]> jfr.im git - erebus.git/commitdiff
exception_hook module
authorJohn Runyon <redacted>
Mon, 23 Oct 2023 13:55:00 +0000 (07:55 -0600)
committerJohn Runyon <redacted>
Mon, 23 Oct 2023 13:55:00 +0000 (07:55 -0600)
modules/exception_hook.py [new file with mode: 0644]

diff --git a/modules/exception_hook.py b/modules/exception_hook.py
new file mode 100644 (file)
index 0000000..5c089ea
--- /dev/null
@@ -0,0 +1,29 @@
+# Erebus IRC bot - Author: Erebus Team
+# vim: fileencoding=utf-8
+# This file is released into the public domain; see http://unlicense.org/
+
+# module info
+modinfo = {
+       'author': 'Erebus Team',
+       'license': 'public domain',
+       'compatible': [0], # compatible module API versions
+       'depends': [], # other modules required to work properly?
+       'softdeps': [], # modules which are preferred but not required
+}
+
+# preamble
+import modlib
+lib = modlib.modlib(__name__)
+modstart = lib.modstart
+modstop = lib.modstop
+
+# module code
+import traceback
+
+@lib.hookexception(Exception)
+def got_exception(bot, exc, source, *args, **kwargs):
+       dest = lib.parent.cfg.get('exception_hook', 'destination')
+       if dest is not None:
+               bot.msg(dest, '%s exception: %r %r' % (source, args, kwargs))
+               for line in traceback.format_exc(limit=lib.parent.cfg.getint('exception_hook', 'limit', 5)).split("\n"):
+                       bot.msg(dest, (' '*4) + line)