From 2425395575a4905caf77d4c30bf5d746d8fc2c9c Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Sun, 7 Oct 2012 12:04:48 +0200 Subject: [PATCH] forgot last_active.py --- last_active.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 last_active.py diff --git a/last_active.py b/last_active.py new file mode 100644 index 0000000..a74e891 --- /dev/null +++ b/last_active.py @@ -0,0 +1,33 @@ +import brathuhn, datetime, time + +last_active = dict() + +def active(mfrom,msg): + global last_active + body = unicode(msg.getBody()) + res = mfrom.getResource() + date=datetime.datetime.fromtimestamp(time.time()) + last_active[res]=(body,date.strftime("%a, %d-%b-%Y %H:%M:%S")) +brathuhn.addGroupListener(active) + + +def last_active_cmd(msg,args): + if( len(args)==2 ): + res = args[1] + if res in last_active: + if res[-1]!='s': + mymsg=res+"'s" + else: + mymsg=res+"'" + la = last_active[res] + mymsg+= " last message on "+la[1]+' : "'+la[0]+'"' + + brathuhn.sendMsg(brathuhn.ROOM,mymsg,'groupchat') + else: + brathuhn.sendMsg(brathuhn.ROOM,"no message in record",'groupchat') + else: + brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" nick",'groupchat') +brathuhn.addCommand("last_active","Usage: !last_active nick",last_active_cmd) + + +