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.

47 lines
1.3 KiB

#!/usr/bin/env python
""" - Phenny Logging Module
Copyright 2014, sfan5
Licensed under GNU General Public License v2.0
import time
loglevels = {
'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
actionchannel = "##minetestbot"
actionhighlight = "sfan5"
def log(level, text, phenny=None):
level = level.upper()
f = open("bot.log", "ab")
f.write(bytes(time.strftime("%F %H:%M:%S %z") + "\t" + loglevels[level] + "\t" + text + "\n", 'utf-8', 'ignore'))
if level == 'ACTION' and phenny is not None:
phenny.write(['PRIVMSG', actionchannel], actionhighlight + ": " + text)
def fmt_user(input):
return "%s(%s)" % (input.nick, input.hostmask)
class SomeObject(object):
log_api = SomeObject()
log_api.log = log
log_api.fmt_user = fmt_user
_export = {
'log': log_api,
def log_text(phenny, input, func):
if func.event != "PRIVMSG": return True
log("text", "%s executes command '%s'" % (fmt_user(input),, phenny)
return True
log_text.hook = True