|
|
|
|
@ -1,11 +1,18 @@ |
|
|
|
|
import brathuhn, tempfile |
|
|
|
|
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 len(args)!=1: |
|
|
|
|
brathuhn.sendMsg(msg.getFrom(),"Usage: !"+args[0]) |
|
|
|
|
return |
|
|
|
|
if msg.getFrom() in user_logs: |
|
|
|
|
user_logs[msg.getFrom()].seek(0) |
|
|
|
|
log = user_logs[msg.getFrom()].read() |
|
|
|
|
@ -13,10 +20,7 @@ def show_log(msg,args): |
|
|
|
|
else: |
|
|
|
|
brathuhn.sendMsg(msg.getFrom(),"I'm currently not logging for you") |
|
|
|
|
|
|
|
|
|
def del_log(msg,args): |
|
|
|
|
if len(args)!=1: |
|
|
|
|
brathuhn.sendMsg(msg.getFrom(),"Usage: !"+args[0]) |
|
|
|
|
return |
|
|
|
|
def delete_log(msg,args): |
|
|
|
|
if msg.getFrom() in user_logs: |
|
|
|
|
user_logs[msg.getFrom()].seek(0) |
|
|
|
|
user_logs[msg.getFrom()].truncate(0) |
|
|
|
|
@ -25,28 +29,31 @@ def del_log(msg,args): |
|
|
|
|
brathuhn.sendMsg(msg.getFrom(),"I'm currently not logging for you") |
|
|
|
|
|
|
|
|
|
def stop_log(msg,args): |
|
|
|
|
if len(args)!=1: |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"Usage: !"+args[0],'groupchat') |
|
|
|
|
return |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"/me stopped logging for "+unicode(msg.getFrom()),'groupchat') |
|
|
|
|
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 len(args)!=1: |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"Usage: !"+args[0],'groupchat') |
|
|
|
|
return |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,"/me started logging for "+unicode(msg.getFrom()),'groupchat') |
|
|
|
|
user_logs[msg.getFrom()]=open(tempfile.mkstemp(brathuhn.NAME)[1],"w+") |
|
|
|
|
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: |
|
|
|
|
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: |
|
|
|
|
@ -62,9 +69,23 @@ def status_logger(mfrom,msg,status): |
|
|
|
|
if status==brathuhn.STATUS_UNKNOWN: |
|
|
|
|
user_logs[key].write(unicode(mfrom)+" is now ???\n") |
|
|
|
|
|
|
|
|
|
brathuhn.addPrivateCommand("show_log","Usage: !show_log",show_log) |
|
|
|
|
brathuhn.addPrivateCommand("start_log","Usage: !start_log",start_log) |
|
|
|
|
brathuhn.addPrivateCommand("stop_log","Usage: !stop_log",stop_log) |
|
|
|
|
brathuhn.addPrivateCommand("delete_log","Usage: !delete_log",del_log) |
|
|
|
|
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) |
|
|
|
|
|