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.

48 lines
1.3 KiB

8 years ago
#!/usr/bin/env python
"""
log.py - Phenny Logging Module
Copyright 2014, sfan5
Licensed under GNU General Public License v2.0
8 years ago
"""
import time
loglevels = {
8 years ago
'TEXT': 'TXT', # TEXT: purely informal message that appears in masses e.g. a command being executed
'EVENT': 'EVT', # EVENT: like TEXT events but more likely someone wants to see those
'ACTION': 'ACT', # ACTION: something the bot decided on doing automatically, requires attention
'WARNING': 'WRN', # WARNING: a warning
8 years ago
}
actionchannel = "##minetestbot"
actionhighlight = "sfan5"
def log(level, text, phenny=None):
8 years ago
level = level.upper()
8 years ago
f = open("bot.log", "ab")
f.write(bytes(time.strftime("%F %H:%M:%S %z") + "\t" + loglevels[level] + "\t" + text + "\n", 'utf-8', 'ignore'))
8 years ago
f.close()
if level == 'ACTION' and phenny is not None:
8 years ago
phenny.write(['PRIVMSG', actionchannel], actionhighlight + ": " + text)
8 years ago
def fmt_user(input):
8 years ago
return "%s(%s)" % (input.nick, input.hostmask)
8 years ago
class SomeObject(object):
8 years ago
pass
8 years ago
log_api = SomeObject()
log_api.log = log
log_api.fmt_user = fmt_user
_export = {
8 years ago
'log': log_api,
8 years ago
}
def log_text(phenny, input, func):
if func.event != "PRIVMSG": return True
log("text", "%s executes command '%s'" % (fmt_user(input), input.group(0)), phenny)
return True
log_text.hook = True