aboutsummaryrefslogtreecommitdiff
path: root/modules/channel_log.py
diff options
context:
space:
mode:
authorGravatar jesopo2020-01-27 23:51:30 +0000
committerGravatar jesopo2020-01-27 23:51:30 +0000
commitb5c068a0ce217a9bf394393a1b525f8c8ed7c34f (patch)
tree492ac4c4975f9dec46938e0763778062d2902dda /modules/channel_log.py
parentmove channel_log/__init__.py to channel_log.py (diff)
signature
disable logging by default but allow enabling bot/server-wide
Diffstat (limited to 'modules/channel_log.py')
-rw-r--r--modules/channel_log.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/modules/channel_log.py b/modules/channel_log.py
index 51ad7c04..3e4291a1 100644
--- a/modules/channel_log.py
+++ b/modules/channel_log.py
@@ -7,16 +7,25 @@ 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",
+SETTING = utils.BoolSetting("channel-log",
+ "Enable/disable channel logging")
+
+@utils.export("channelset",utils.BoolSetting("log",
"Enable/disable channel logging"))
+@utils.export("serverset", SETTING)
+@utils.export("botset", SETTING)
class Module(ModuleManager.BaseModule):
+ def _enabled(self, server, channel):
+ return channel.get_setting("log",
+ server.get_setting("channel-log",
+ self.bot.get_setting("channel-log", False)))
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:
+ def _log(self, server, channel, line):
+ if self._enabled(server, channel):
+ with open(self._file(str(server), str(channel)), "a") as log:
timestamp = datetime.datetime.now().strftime("%x %X")
- log.write("%s %s\n" % (timestamp, event["line"]))
+ log.write("%s %s\n" % (timestamp, line))
@utils.hook("formatted.message.channel")
@utils.hook("formatted.notice.channel")
@@ -33,7 +42,8 @@ class Module(ModuleManager.BaseModule):
@utils.hook("formatted.chghost")
def on_formatted(self, event):
if event["channel"]:
- self._log(event, event["channel"])
+ self._log(event["server"], event["channel"], event["line"])
elif event["user"]:
for channel in event["user"].channels:
- self._log(event, channel)
+ self._log(event["server"], channel, event["line"])
+