Use datastore library for persisting SOTD data

This commit is contained in:
Robert Miles 2018-11-15 17:16:12 -05:00
parent 60afe1c484
commit 80ceef98f7
1 changed files with 11 additions and 5 deletions

16
bot.py
View File

@ -1,9 +1,9 @@
import teambot, sys
import teambot, sys, time, datatore
USAGE = dict(admin="Stop trying to use this command!",sotd="{}sotd <link> <name>")
PUBLIC_COMMANDS = ["sotd"]
USAGE = dict(admin="Stop trying to use this command!",sotd="{}sotd <link> <name>",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)