Made !tell persistent

master
Stefan Krulj 14 years ago
parent 6fe177dc05
commit 4d336b3fea
  1. 24
      modules/active/tell.py

@ -12,13 +12,16 @@ import config
# HOLDBACK ... how long will brathuhn wait # HOLDBACK ... how long will brathuhn wait
# to tell someone # to tell someone
DELAY = 60*60*24 DELAY = 60*60*24
HOLDBACK = 60*60*24*7 HOLDBACK = 60*60*24*7 # TODO make brathuhn tell if it deletes messages
############################################## ##############################################
store = [] container = PersistentContainer(__name__+'_data',config.PCACHE)
if not "store" in container:
container["store"] = []
def tell(msg, args): def tell(msg, args):
global store global container
store = container["store"]
if( len(args) <= 2): if( len(args) <= 2):
brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" nick text",'groupchat') brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" nick text",'groupchat')
@ -36,10 +39,12 @@ def tell(msg, args):
nick = spl[1] nick = spl[1]
origin = msg.getFrom().getResource() origin = msg.getFrom().getResource()
store.append( (nick, message, origin, datetime.today()) ) store.append( (nick, message, origin, datetime.today()) )
container["store"] = store
brathuhn.sendMsg(brathuhn.ROOM,origin+": will do!",'groupchat') brathuhn.sendMsg(brathuhn.ROOM,origin+": will do!",'groupchat')
def tellCB(nick, msg, status): def tellCB(nick, msg, status):
global store global container
store = container["store"]
if(status != brathuhn.STATUS_JOIN): if(status != brathuhn.STATUS_JOIN):
return return
@ -55,9 +60,11 @@ def tellCB(nick, msg, status):
for r in rem: for r in rem:
store.remove(r) store.remove(r)
container["store"] = store
def cleartell(): def cleartell():
global store global container
store = container["store"]
now = datetime.today() now = datetime.today()
rem = [] rem = []
for l in store: for l in store:
@ -65,6 +72,7 @@ def cleartell():
rem.append(l) rem.append(l)
for r in rem: for r in rem:
store.remove(r) store.remove(r)
container["store"] = store
brathuhn.callAt(cleartell, time.time()+DELAY, []) brathuhn.callAt(cleartell, time.time()+DELAY, [])
@ -77,13 +85,15 @@ brathuhn.callAt(cleartell, time.time()+DELAY, [])
############################################## ##############################################
#def flushtell(msg, args): #def flushtell(msg, args):
# global store # global container
store = container["store"]
# store = [] # store = []
# #
#brathuhn.addCommand("flush","Usage: !flush ", flushtell) #brathuhn.addCommand("flush","Usage: !flush ", flushtell)
#def showtell(msg, args): #def showtell(msg, args):
# #global store # #global container
store = container["store"]
# #
# for l in store: # for l in store:
# timestamp = "{:02}:{:02}, {}-{:02}-{:02}".format(l[3].hour, l[3].minute, l[3].year, l[3].month, l[3].day) # timestamp = "{:02}:{:02}, {}-{:02}-{:02}".format(l[3].hour, l[3].minute, l[3].year, l[3].month, l[3].day)

Loading…
Cancel
Save