From 3b55e00dd060e13f6f8bc09bd16977bf06483345 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 27 Jan 2020 23:26:54 +0000 Subject: move channel_log/__init__.py to channel_log.py --- modules/channel_log.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 modules/channel_log.py (limited to 'modules/channel_log.py') diff --git a/modules/channel_log.py b/modules/channel_log.py new file mode 100644 index 00000000..51ad7c04 --- /dev/null +++ b/modules/channel_log.py @@ -0,0 +1,39 @@ +#--depends-on config +#--depends-on format_activity + +import datetime, os.path +from src import ModuleManager, utils + +ROOT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) +LOGS_DIRECTORY = os.path.join(ROOT_DIRECTORY, "logs") + +@utils.export("channelset", utils.BoolSetting("log", + "Enable/disable channel logging")) +class Module(ModuleManager.BaseModule): + def _file(self, server_name, channel_name): + return self.data_directory("%s/%s.log" % (server_name, channel_name)) + def _log(self, event, channel): + if channel.get_setting("log", True): + with open(self._file(str(event["server"]), str(channel)), "a") as log: + timestamp = datetime.datetime.now().strftime("%x %X") + log.write("%s %s\n" % (timestamp, event["line"])) + + @utils.hook("formatted.message.channel") + @utils.hook("formatted.notice.channel") + @utils.hook("formatted.join") + @utils.hook("formatted.part") + @utils.hook("formatted.nick") + @utils.hook("formatted.invite") + @utils.hook("formatted.mode.channel") + @utils.hook("formatted.topic") + @utils.hook("formatted.topic-timestamp") + @utils.hook("formatted.kick") + @utils.hook("formatted.quit") + @utils.hook("formatted.rename") + @utils.hook("formatted.chghost") + def on_formatted(self, event): + if event["channel"]: + self._log(event, event["channel"]) + elif event["user"]: + for channel in event["user"].channels: + self._log(event, channel) -- cgit v1.3.1-10-gc9f91