diff options
| author | 2019-03-06 13:36:46 +0000 | |
|---|---|---|
| committer | 2019-03-06 13:36:46 +0000 | |
| commit | 77dd36cbf621e853dfdfeb158648332af2d39b16 (patch) | |
| tree | dbe7e12b52a9ace72f6d95390730c292be7a2cc3 /modules/channel_log | |
| parent | Pass IRCChannel and IRCUser objects on formatted events where applicable (diff) | |
| signature | ||
Add channel_log module for per-channel logging
Diffstat (limited to 'modules/channel_log')
| -rw-r--r-- | modules/channel_log/__init__.py | 34 | ||||
| -rw-r--r-- | modules/channel_log/logs/.keep | 0 |
2 files changed, 34 insertions, 0 deletions
diff --git a/modules/channel_log/__init__.py b/modules/channel_log/__init__.py new file mode 100644 index 00000000..7f4d54be --- /dev/null +++ b/modules/channel_log/__init__.py @@ -0,0 +1,34 @@ +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") + +class Module(ModuleManager.BaseModule): + def _log_file(self, server_name, channel_name): + return open(os.path.join(LOGS_DIRECTORY, + "%s%s.log" % (server_name, channel_name)), "a") + def _log(self, event, channel): + if channel.get_setting("log", False): + with self._log_file(str(event["server"]), str(channel)) as log: + timestamp = datetime.datetime.now().strftime("%x %X") + log.write("%s %s\n" % (timestamp, event["raw_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") + 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) diff --git a/modules/channel_log/logs/.keep b/modules/channel_log/logs/.keep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/modules/channel_log/logs/.keep |
