5 json_load("var/remind.json", remind);
8 # Parse an at style time
9 function atp(now, time, cmd, iso, arr, month) {
10 # Remove quotes if needed
11 gsub(/["']/, "", time);
14 cmd = "atp " now " " time " 2>/dev/null";
19 gsub(/^\w+ |:/, " ", iso);
20 if (!match(iso, /(\w+) +([0-9]+ [0-9]+ [0-9]+ [0-9]+) +([0-9]+)/, arr))
22 month = (index("JanFebMarAprMayJunJulAugSepOctNovDec", arr[1])-1)/3+1;
23 return mktime(arr[3] " " month " " arr[2])
27 function at(from, text, prefix, now, arr, desc, time, mesg, cmd) {
31 if (!match(text, /^.(at|in) +([a-zA-Z0-9:+-]+|"[ a-zA-Z0-9:+-]+") +(.*)/, arr))
32 return reply("invalid time");
34 return reply("no message");
39 time = atp(now, prefix desc);
41 return reply("unparsable time: " desc);
43 return reply("time is in the past");
45 return reply("date is right now");
49 remind[id]["time"] = time;
50 remind[id]["from"] = from;
51 remind[id]["mesg"] = mesg;
52 remind[id]["done"] = "pending";
53 json_save("var/remind.json", remind);
55 say("queued job " id ": " \
56 strftime("%Y-%m-%d %H:%M", time));
60 function atq(all, i, from, time, done, desc, line) {
61 for (i = 0; i < length(remind); i++) {
62 from = remind[i]["from"];
63 time = remind[i]["time"];
64 done = remind[i]["done"];
65 if (!all && done != "pending")
67 desc = strftime("%Y-%m-%d %H:%M", time);
68 line = sprintf("%-3d %s %s (%s)", i, desc, from, done);
75 if (id >= length(remind))
76 return reply("invalid job id");
77 say("job " id ": " remind[id]["mesg"]);
80 # Remove job from the queue
82 if (id >= length(remind))
83 return reply("invalid job id");
84 if (remind[id]["done"] != "pending")
85 return reply("job is not pending");
86 remind[id]["done"] = "canceled";
87 json_save("var/remind.json", remind);
88 say("canceled job " id);
94 for (i = 0; i < length(remind); i++) {
95 if (remind[i]["done"] != "pending")
97 if (remind[i]["time"] > now)
99 remind[i]["done"] = "finished";
100 say(CHANNEL, remind[i]["from"] ": " remind[i]["mesg"]);
102 json_save("var/remind.json", remind);
112 at(FROM, $0, "now+");
128 say(".help at -- queue reminders for later")
132 say(".at [time] [msg] -- record a message for the given time")
133 say(".in [len] [msg] -- same as .at \"now + len\"")
134 say(".atq -- list any pending job")
135 say(".atq! -- list all jobs in the queue")
136 say(".atc [n] -- print the given job")
137 say(".atrm [n] -- delete the given job")