🏡 index : ~doyle/dave.git

author Jordan Doyle <jordan@doyle.wf> 2017-07-22 23:36:43.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2017-07-22 23:36:43.0 +01:00:00
commit
7ed1271e6da2ed7670242068e450147b78d83f53 [patch]
tree
76d17590f4f65bbeb84a08374d26f6a304bd5300
parent
21d113377faf34f4dc776903b6dd4be5764ff5dc
download
7ed1271e6da2ed7670242068e450147b78d83f53.tar.gz

Add tell command to remind someone of something when they're back



Diff

 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()))