From 88b95dd1b81ea6aa06f212303a221655150ba5a9 Mon Sep 17 00:00:00 2001 From: fbr Date: Sat, 6 Oct 2012 16:34:35 +0200 Subject: [PATCH] added module tell.py --- main.py | 1 + tell.py | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tell.py diff --git a/main.py b/main.py index 01ceb84..9c05129 100755 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ import logger import cowsay import choose import tantrum +import tell brathuhn.connect_and_join() brathuhn.loop() diff --git a/tell.py b/tell.py new file mode 100644 index 0000000..9735559 --- /dev/null +++ b/tell.py @@ -0,0 +1,93 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import brathuhn +import time +from datetime import datetime +import config + +############################################## +# change values to your need +# DELAY ... time between checks for outdated +# HOLDBACK ... how long will brathuhn wait +# to tell someone +DELAY = 60*60*24 +HOLDBACK = 60*60*24*7 +############################################## + +store = [] + +def tell(msg, args): + global store + + if( len(args) <= 2): + brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" nick text",'groupchat') + return + + userJID = brathuhn.getUsers().items() + for a in userJID: + if( args[1] == a[0].getResource()): + brathuhn.sendMsg(brathuhn.ROOM,"User "+args[1]+" is already here, tell them yourself!",'groupchat') + return + + body = unicode(msg.getBody()) + spl = body.split(' ', 2) + message = spl[2] + nick = spl[1] + origin = msg.getFrom().getResource() + store.append( (nick, message, origin, datetime.today()) ) + brathuhn.sendMsg(brathuhn.ROOM,origin+": will do!",'groupchat') + +def tellCB(nick, msg, status): + global store + + if(status != brathuhn.STATUS_JOIN): + return + + + user = nick.getResource() + rem = [] + for l in store: + if(l[0] == unicode(user)): + timestamp = "{:02}:{:02}, {}-{:02}-{:02}".format(l[3].hour, l[3].minute, l[3].year, l[3].month, l[3].day) + brathuhn.sendMsg(brathuhn.ROOM,(l[0]+": User "+l[2]+" told me at "+timestamp+" to tell you: \""+l[1]+"\""),'groupchat') + rem.append(l) + + for r in rem: + store.remove(r) + +def cleartell(): + global store + now = datetime.today() + rem = [] + for l in store: + if(now - l[3] < HOLDBACK): + rem.append(l) + for r in rem: + store.remove(r) + + brathuhn.callAt(cleartell, time.time()+DELAY, []) + +############################################## + +brathuhn.addCommand("tell","Usage: !tell nick text", tell) +brathuhn.addStatusListener(tellCB) +brathuhn.callAt(cleartell, time.time()+DELAY, []) + +############################################## + +#def flushtell(msg, args): +# global store +# store = [] +# +#brathuhn.addCommand("flush","Usage: !flush ", flushtell) + +#def showtell(msg, args): +# #global 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) +# brathuhn.sendMsg(brathuhn.ROOM,(l[2]+" -> "+ l[0]+"; "+l[1]+"; "+timestamp),'groupchat') +# +#brathuhn.addCommand("show","Usage: !show ", showtell) +