From 80ceef98f780c35cb49f690568929d57be29e1da Mon Sep 17 00:00:00 2001 From: khuxkm Date: Thu, 15 Nov 2018 17:16:12 -0500 Subject: [PATCH] Use datastore library for persisting SOTD data --- bot.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 6e88978..785bf5e 100644 --- a/bot.py +++ b/bot.py @@ -1,9 +1,9 @@ -import teambot, sys +import teambot, sys, time, datatore -USAGE = dict(admin="Stop trying to use this command!",sotd="{}sotd ") -PUBLIC_COMMANDS = ["sotd"] +USAGE = dict(admin="Stop trying to use this command!",sotd="{}sotd ",listsotd="{}listsotd") +PUBLIC_COMMANDS = ["sotd","listsotd"] -SOTDS = dict() +SOTDS = datastore.DataStore("sotd.json") def get_title(link): return link # TODO: actually make this get the title of a link. @@ -40,7 +40,7 @@ class SOTDBot(teambot.Handler,teambot.CommandHandlerMixin): self.prefix = args[0] def do_botlist(self): - self.say(self.target,"Maintainer: khuxkm | commands: {}".format(", ".join("{}{}".format(self.prefix,cmd) for cmd in PUBLIC_COMMANDS))) + self.say(self.target,"Maintainer: khuxkm | Song-of-the-day bot | commands: {}".format(", ".join("{}{}".format(self.prefix,cmd) for cmd in PUBLIC_COMMANDS))) def do_sotd(self,link,*name): if name: @@ -50,6 +50,12 @@ class SOTDBot(teambot.Handler,teambot.CommandHandlerMixin): SOTDS[self.sourcenick] = (name,link) self.say(self.target,self.sourcenick+": Your SOTD has been set to {}.".format(name)) + def do_listsotd(self): + for k in SOTDS.data: + sotd = SOTDS[k] + t = time.strftime("%B %d, %Y",time.localtime(SOTDS.getSetTime(k))) + self.say(self.target,self.sourcenick+": {} - {} ({}, set {})".format(k,sotd[1],sotd[0],t)) + if __name__=="__main__": channels = "#bots".split() bot = teambot.TeamBot(channels,"sotdbot","localhost",chandler=SOTDBot)