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.
91 lines
3.1 KiB
91 lines
3.1 KiB
import brathuhn, tempfile, datetime, time
|
|
from StringIO import StringIO
|
|
|
|
user_logs = dict()
|
|
|
|
def get_log(msg,args):
|
|
if msg.getFrom() in user_logs:
|
|
user_logs[msg.getFrom()].seek(0)
|
|
log = user_logs[msg.getFrom()].read()
|
|
fd = StringIO(log)
|
|
brathuhn.sendFileStream(msg.getFrom(),len(log),"log.txt",fd)
|
|
else:
|
|
brathuhn.sendMsg(msg.getFrom(),"I'm currently not logging for you")
|
|
|
|
def show_log(msg,args):
|
|
if msg.getFrom() in user_logs:
|
|
user_logs[msg.getFrom()].seek(0)
|
|
log = user_logs[msg.getFrom()].read()
|
|
brathuhn.sendMsg(msg.getFrom(),'\n'+log)
|
|
else:
|
|
brathuhn.sendMsg(msg.getFrom(),"I'm currently not logging for you")
|
|
|
|
def delete_log(msg,args):
|
|
if msg.getFrom() in user_logs:
|
|
user_logs[msg.getFrom()].seek(0)
|
|
user_logs[msg.getFrom()].truncate(0)
|
|
brathuhn.sendMsg(msg.getFrom(),"Done!")
|
|
else:
|
|
brathuhn.sendMsg(msg.getFrom(),"I'm currently not logging for you")
|
|
|
|
def stop_log(msg,args):
|
|
if msg.getFrom() in user_logs:
|
|
brathuhn.sendMsg(brathuhn.ROOM,"/me stopped logging for "+unicode(msg.getFrom()),'groupchat')
|
|
del user_logs[msg.getFrom()]
|
|
else:
|
|
brathuhn.sendMsg(msg.getFrom(),"I'm currently not logging for you")
|
|
|
|
|
|
def start_log(msg,args):
|
|
if not msg.getFrom() in user_logs:
|
|
brathuhn.sendMsg(brathuhn.ROOM,"/me started logging for "+unicode(msg.getFrom()),'groupchat')
|
|
user_logs[msg.getFrom()]=open(tempfile.mkstemp(brathuhn.NAME)[1],"w+")
|
|
else:
|
|
brathuhn.sendMsg(msg.getFrom(),"I'm already logging for you")
|
|
|
|
def message_logger(mfrom,msg):
|
|
body = unicode(msg.getBody())
|
|
for key in user_logs:
|
|
date=datetime.datetime.fromtimestamp(time.time())
|
|
user_logs[key].write(date.strftime("(%H:%M:%S) "))
|
|
user_logs[key].write(unicode(mfrom)+": "+body+"\n")
|
|
|
|
def status_logger(mfrom,msg,status):
|
|
for key in user_logs:
|
|
date=datetime.datetime.fromtimestamp(time.time())
|
|
user_logs[key].write(date.strftime("(%H:%M:%S) "))
|
|
if status==brathuhn.STATUS_JOIN:
|
|
user_logs[key].write(unicode(mfrom)+" joined\n")
|
|
if status==brathuhn.STATUS_ONLINE:
|
|
user_logs[key].write(unicode(mfrom)+" is now online\n")
|
|
if status==brathuhn.STATUS_OFFLINE:
|
|
user_logs[key].write(unicode(mfrom)+" left\n")
|
|
if status==brathuhn.STATUS_RENAME:
|
|
user_logs[key].write(unicode(mfrom)+" is now known as "+msg.getName()+"\n")
|
|
if status==brathuhn.STATUS_XAWAY:
|
|
user_logs[key].write(unicode(mfrom)+" is now extended away\n")
|
|
if status==brathuhn.STATUS_AWAY:
|
|
user_logs[key].write(unicode(mfrom)+" is now away\n")
|
|
if status==brathuhn.STATUS_UNKNOWN:
|
|
user_logs[key].write(unicode(mfrom)+" is now ???\n")
|
|
|
|
def log(msg,args):
|
|
if len(args)!=2:
|
|
brathuhn.sendMsg(msg.getFrom(),"Usage: !log (start|stop|delete|show|get)")
|
|
return
|
|
if args[1]=='start':
|
|
start_log(msg,args)
|
|
elif args[1]=='stop':
|
|
stop_log(msg,args)
|
|
elif args[1]=='delete':
|
|
delete_log(msg,args)
|
|
elif args[1]=='show':
|
|
show_log(msg,args)
|
|
elif args[1]=='get':
|
|
get_log(msg,args)
|
|
else:
|
|
brathuhn.sendMsg(msg.getFrom(),"Usage: !log (start|stop|delete|show|get)")
|
|
|
|
brathuhn.addPrivateCommand("log","Usage: !log (start|stop|delete|show|get)",log)
|
|
brathuhn.addGroupListener(message_logger)
|
|
brathuhn.addStatusListener(status_logger)
|
|
|