]> jfr.im git - erebus.git/blob - modules/exception_hook.py
update comments
[erebus.git] / modules / exception_hook.py
1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
3 # A basic exception hook. Sends exceptions to `[exception_hook] destination` in the config.
4 # This file is released into the public domain; see http://unlicense.org/
5
6 # module info
7 modinfo = {
8 'author': 'Erebus Team',
9 'license': 'public domain',
10 'compatible': [0], # compatible module API versions
11 'depends': [], # other modules required to work properly?
12 'softdeps': [], # modules which are preferred but not required
13 }
14
15 # preamble
16 import modlib
17 lib = modlib.modlib(__name__)
18 modstart = lib.modstart
19 modstop = lib.modstop
20
21 # module code
22 import traceback
23
24 @lib.hookexception(Exception)
25 def got_exception(bot, exc, source, *args, **kwargs):
26 dest = lib.parent.cfg.get('exception_hook', 'destination')
27 if dest is not None:
28 bot.msg(dest, '%s exception: %r %r' % (source, args, kwargs))
29 for line in traceback.format_exc(limit=-lib.parent.cfg.getint('exception_hook', 'limit', 5)).split("\n"):
30 bot.msg(dest, (' '*4) + line)