aboutsummaryrefslogtreecommitdiff
path: root/modules/channel_log.py
diff options
context:
space:
mode:
authorGravatar jesopo2020-01-27 23:26:54 +0000
committerGravatar jesopo2020-01-27 23:26:54 +0000
commit3b55e00dd060e13f6f8bc09bd16977bf06483345 (patch)
tree25c0c2decb699d133cca4aeb08cfeab04bfaf0fb /modules/channel_log.py
parentmove logs to new data_directory(), log all channels by default (diff)
move channel_log/__init__.py to channel_log.py
Diffstat (limited to 'modules/channel_log.py')
-rw-r--r--modules/channel_log.py39
1 files changed, 39 insertions, 0 deletions
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)