You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
import brathuhn, datetime, time, config
|
|
from persistent import PersistentContainer
|
|
|
|
pc_msg = PersistentContainer(__name__+'_msg',config.PCACHE)
|
|
pc_stat = PersistentContainer(__name__+'_stat',config.PCACHE)
|
|
|
|
def active(mfrom,msg):
|
|
global pc_msg
|
|
body = unicode(msg.getBody())
|
|
res = mfrom.getResource()
|
|
date=datetime.datetime.fromtimestamp(time.time())
|
|
pc_msg[res]=(body,date.strftime("%a, %d-%b-%Y %H:%M:%S"))
|
|
brathuhn.addGroupListener(active)
|
|
|
|
def sactive(mfrom,msg,status):
|
|
global pc_stat
|
|
res = mfrom.getResource()
|
|
date=datetime.datetime.fromtimestamp(time.time())
|
|
stat = brathuhn.statusString(status)
|
|
pc_stat[res]=(stat,date.strftime("%a, %d-%b-%Y %H:%M:%S"))
|
|
brathuhn.addStatusListener(sactive)
|
|
|
|
def last_active_cmd(msg,args):
|
|
global pc_msg
|
|
global pc_stat
|
|
if( len(args)==2 ):
|
|
res = args[1]
|
|
if res in pc_msg:
|
|
if res[-1]!='s':
|
|
mymsg=res+"'s"
|
|
else:
|
|
mymsg=res+"'"
|
|
la = pc_msg[res]
|
|
mymsg+= " last message on "+la[1]+' : "'+la[0]+'"'
|
|
if res in pc_stat:
|
|
ls = pc_stat[res]
|
|
mymsg+= "\nlast status change on "+ls[1]+' to "'+ls[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)
|
|
|
|
|
|
|