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.
100 lines
3.3 KiB
100 lines
3.3 KiB
import brathuhn, datetime, time
|
|
from StringIO import StringIO
|
|
|
|
from persistent import PersistentContainer
|
|
import config
|
|
user_logs = PersistentContainer(__name__,config.PCACHE)
|
|
|
|
log=open("channel_log_"+brathuhn.NAME,"a+")
|
|
|
|
def get_log(msg,args):
|
|
global log
|
|
if unicode(msg.getFrom()) in user_logs:
|
|
log.seek(user_logs[unicode(msg.getFrom())])
|
|
txtlog = log.read()
|
|
fd = StringIO(txtlog )
|
|
brathuhn.sendFileStream(unicode(msg.getFrom()),len(txtlog),"log.txt",fd)
|
|
else:
|
|
brathuhn.sendMsg(unicode(msg.getFrom()),"I'm currently not logging for you")
|
|
|
|
def show_log(msg,args):
|
|
global log
|
|
if unicode(msg.getFrom()) in user_logs:
|
|
log.seek(user_logs[unicode(msg.getFrom())])
|
|
txtlog = log.read()
|
|
brathuhn.sendMsg(unicode(msg.getFrom()),'\n'+txtlog)
|
|
else:
|
|
brathuhn.sendMsg(unicode(msg.getFrom()),"I'm currently not logging for you")
|
|
|
|
def delete_log(msg,args):
|
|
global log
|
|
if unicode(msg.getFrom()) in user_logs:
|
|
user_logs[unicode(msg.getFrom())]=log.tell()
|
|
brathuhn.sendMsg(unicode(msg.getFrom()),"Done!")
|
|
else:
|
|
brathuhn.sendMsg(unicode(msg.getFrom()),"I'm currently not logging for you")
|
|
|
|
def stop_log(msg,args):
|
|
if unicode(msg.getFrom()) in user_logs:
|
|
brathuhn.sendMsg(brathuhn.ROOM,"/me stopped logging for "+unicode(unicode(msg.getFrom())),'groupchat')
|
|
del user_logs[unicode(msg.getFrom())]
|
|
else:
|
|
brathuhn.sendMsg(unicode(msg.getFrom()),"I'm currently not logging for you")
|
|
|
|
|
|
def start_log(msg,args):
|
|
global log
|
|
if not unicode(msg.getFrom()) in user_logs:
|
|
brathuhn.sendMsg(brathuhn.ROOM,"/me started logging for "+unicode(unicode(msg.getFrom())),'groupchat')
|
|
user_logs[unicode(msg.getFrom())]=log.tell()
|
|
else:
|
|
brathuhn.sendMsg(unicode(msg.getFrom()),"I'm already logging for you")
|
|
|
|
def message_logger(mfrom,msg):
|
|
global log
|
|
body = unicode(msg.getBody())
|
|
|
|
date=datetime.datetime.fromtimestamp(time.time())
|
|
log.write(date.strftime("(%H:%M:%S) "))
|
|
log.write(unicode(mfrom.getResource())+": "+body+"\n")
|
|
log.flush()
|
|
|
|
def status_logger(mfrom,msg,status):
|
|
global log
|
|
date=datetime.datetime.fromtimestamp(time.time())
|
|
log.write(date.strftime("(%H:%M:%S) "))
|
|
if status==brathuhn.STATUS_JOIN:
|
|
log.write(mfrom.getResource()+" joined\n")
|
|
if status==brathuhn.STATUS_ONLINE:
|
|
log.write(mfrom.getResource()+" is now online\n")
|
|
if status==brathuhn.STATUS_OFFLINE:
|
|
log.write(mfrom.getResource()+" left\n")
|
|
if status==brathuhn.STATUS_RENAME:
|
|
log.write(mfrom.getResource()+" is now known as "+msg.getNick()+"\n")
|
|
if status==brathuhn.STATUS_XAWAY:
|
|
log.write(mfrom.getResource()+" is now extended away\n")
|
|
if status==brathuhn.STATUS_AWAY:
|
|
log.write(mfrom.getResource()+" is now away\n")
|
|
if status==brathuhn.STATUS_UNKNOWN:
|
|
log.write(mfrom.getResource()+" is now ???\n")
|
|
|
|
def logger(msg,args):
|
|
if len(args)!=2:
|
|
brathuhn.sendMsg(unicode(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(unicode(msg.getFrom()),"Usage: !log (start|stop|delete|show|get)")
|
|
|
|
brathuhn.addPrivateCommand("log","Usage: !log (start|stop|delete|show|get)",logger)
|
|
brathuhn.addGroupListener(message_logger)
|
|
brathuhn.addStatusListener(status_logger)
|
|
|