You can use IRC to remind you to do anything. Now that you have a directory that your IRC bot reads, you can use one of Linux’s best kept secrets: the at command. The at command allows you to schedule one-time jobs to be run in the future — a non-reoccurring cronjob. The real win with using at is its time syntax. Here’s a few examples from the man page:
- to run a job at 4pm three days from now, you would do at 4pm + 3 day
- to run a job at 10:00am on July 31, you would do at 10am Jul 31
- to run a job at 1am tomorrow, you would do at 1am tomorrow.
You can use this to run any command or script at a given time. This makes the at command perfect for usage over IRC — we just need to drop a file with the reminder in the /say directory at the given time. It’s easy to wrap some of this syntax to give the reminder command a human-like syntax.
Syntax
I went with the following syntax, best expressed with a summarized version of the regular expression used to parse it:
^(remind|pm) (me|us|everyone) (at|in|on) (.*?) to (.*)$
You might say the following things in the IRC channel to the bot:
- remind me in 5 minutes to check the dryer
- pm me at 10pm to remember to charge my cell phone
- remind everyone on august 1s to enjoy the weather
These commands all get sent to at. Behind the scenes, the bot does the following:
- creates a file under /var/tmp with the contents of the reminder. The filename follows the format mentioned in the Mixing the Command-Line and IRC post, and sets the unique identifier to a hash of the submitter’s nick and current timestamp.
- the at command is instructed to move the file from /var/tmp/ to the ~/say directory at the requested time
- at the requested time, at moves the file and the bot picks it up and prints it to the channel.
There’s only a small amount of additional wrapping needed to make the interaction fluid. The biggest abstraction is in the difference between the “remind me at/on” and “remind me in” commands. “remind me at/on” passes the date straight through to the at command, where “in” prepends “now +” to the request. That’s it!
The channel has been using the reminder feature more and more. It’s nice to set a reminder with a long article you’d like to read, or set a reminder in 2 weeks to write a blog post for the DeadCoderSociety. Socializing reminders is a great way to increase community interaction and raise awareness for interesting information that might otherwise end up on a sticky note in a pocket somewhere.
Bonus:
The other Friday I was talking about payday and one guy had added a reminder to “GET PAID” for the next set of pairs of weeks. We ended up adding this on the command-line:
for i in `seq 12 2 50`; do
echo 'echo "GET PAID" > /srv/git/neilforobot/say/#dcs@paid' |
at now + $i weeks ;
done
At makes setting these types of reminders up easy!