Update (Sep 2026):
I had since improved the scripts by adding another one to also ping me if the AC charger was disconnected (useful to know if it accidentally fell off or lost connection to electricity, and nice confirmation if I deliberately removed it), and this month I upgraded the warning system to combine the two into a single LaunchAgent triggered script, which I have now pushed to a GitHub repo.
The original scripts from this Gist are now a historical reference in the root commit. I don't recommend them. Instead, use the launch agent at the latest commit.