diff --git a/EventManager.py b/EventManager.py index e17258df..0a16a657 100644 --- a/EventManager.py +++ b/EventManager.py @@ -1,7 +1,8 @@ class Event(object): - def __init__(self, bot, **kwargs): + def __init__(self, bot, subevent, **kwargs): self.bot = bot + self.subevent = subevent self.kwargs = kwargs self.eaten = False def __getitem__(self, key): @@ -34,8 +35,9 @@ class MultipleEventHook(object): event_hook.call(max, **kwargs) class EventHook(object): - def __init__(self, bot): + def __init__(self, bot, name=None): self.bot = bot + self.name = name self._children = {} self._hooks = [] self._hook_notify = None @@ -56,7 +58,7 @@ class EventHook(object): return multiple_event_hook return self.get_child(subevent) def call(self, max=None, **kwargs): - event = Event(self.bot, **kwargs) + event = Event(self.bot, self.name, **kwargs) if self._call_notify: self._call_notify(self, event) called = 0 @@ -72,7 +74,8 @@ class EventHook(object): def get_child(self, child_name): child_name_lower = child_name.lower() if not child_name_lower in self._children: - self._children[child_name_lower] = EventHook(self.bot) + self._children[child_name_lower] = EventHook(self.bot, + child_name) if self._child_notify: self._child_notify(self, self._children[ child_name_lower]) diff --git a/modules/logs.py b/modules/logs.py new file mode 100644 index 00000000..5f58cbf3 --- /dev/null +++ b/modules/logs.py @@ -0,0 +1,16 @@ +import datetime + +class Module(object): + def __init__(self, bot): + bot.events.on("log").on("info", "warn", "error").hook(self.log) + + def timestamp(self): + return datetime.datetime.utcnow().isoformat()+"Z" + + def log(self, event): + log_level = event.name + timestamp = self.timestamp() + message = event["message"] + with open("bot.log", "a") as log_file: + log_file.write("%s [%s] %s" % (timestamp, log_level, + message))