From 7ed1271e6da2ed7670242068e450147b78d83f53 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 22 Jul 2017 23:36:43 +0100 Subject: [PATCH] Add tell command to remind someone of something when they're back --- dave/modules/speedtest.py | 1 + dave/modules/tell.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/dave/modules/speedtest.py b/dave/modules/speedtest.py index 977c107..77123d9 100644 --- a/dave/modules/speedtest.py +++ a/dave/modules/speedtest.py @@ -1,3 +1,4 @@ +"""Read details from a speedtest test and print them to the channel.""" from requests import get from bs4 import BeautifulSoup import dave.module diff --git a/dave/modules/tell.py b/dave/modules/tell.py new file mode 100644 index 0000000..6849904 100644 --- /dev/null +++ a/dave/modules/tell.py @@ -1,0 +1,31 @@ +"""Tell a user something next time we see them.""" +import dave.module +import dave.config +import pickle + + +@dave.module.help("Syntax: tell [user] [message]. Tell a user something when we next " + "see them") +@dave.module.command(["tell"], "([A-Za-z_\-\[\]\\^{}|`][A-Za-z0-9_\-\[\]\\^{}|`]*) (.*)") +def tell(bot, args, sender, source): + dave.config.redis.lpush("tell:{}".format(args[0].lower()), pickle.dumps({ + "sender": sender, + "msg": args[1] + })) + bot.reply(source, sender, "I'll let {} know when they're back.".format(args[0])) + + +@dave.module.match(r"(.*)") +@dave.module.priority(dave.module.Priority.HIGHEST) +@dave.module.always_run() +def check_msgs(bot, args, sender, source): + msgs = dave.config.redis.lrange("tell:{}".format(sender.lower()), 0, -1) + + if msgs and len(msgs): + bot.msg(sender, "You have messages waiting for you:") + + for msg in msgs: + msg = pickle.loads(msg) + bot.msg(sender, "<{}> {}".format(msg["sender"], msg["msg"])) + + dave.config.redis.delete("tell:{}".format(sender.lower()))-- rgit 0.1.3