bot: capture exceptions, try to report on them
it beats crashing, probably
This commit is contained in:
parent
9c4e0fe782
commit
1bbb64618d
@ -144,51 +144,56 @@ class DrReactor(irc.client.Reactor):
|
||||
Also supports regex handlers.
|
||||
"""
|
||||
|
||||
log.debug("EVENT: e[%s] s[%s] t[%s] a[%s]", event.type, event.source,
|
||||
event.target, event.arguments)
|
||||
try:
|
||||
log.debug("EVENT: e[%s] s[%s] t[%s] a[%s]", event.type, event.source,
|
||||
event.target, event.arguments)
|
||||
|
||||
self.try_recursion(connection, event)
|
||||
self.try_recursion(connection, event)
|
||||
|
||||
# only do aliasing for pubmsg/privmsg
|
||||
if event.type in ['pubmsg', 'privmsg']:
|
||||
what = event.arguments[0]
|
||||
log.debug("checking for alias for %s", what)
|
||||
# only do aliasing for pubmsg/privmsg
|
||||
if event.type in ['pubmsg', 'privmsg']:
|
||||
what = event.arguments[0]
|
||||
log.debug("checking for alias for %s", what)
|
||||
|
||||
for alias in Alias.objects.all():
|
||||
repl = alias.replace(what)
|
||||
if repl:
|
||||
# we found an alias for our given string, doing a replace
|
||||
event.arguments[0] = repl
|
||||
# recurse, in case there's another alias in this one
|
||||
return self._handle_event(connection, event)
|
||||
for alias in Alias.objects.all():
|
||||
repl = alias.replace(what)
|
||||
if repl:
|
||||
# we found an alias for our given string, doing a replace
|
||||
event.arguments[0] = repl
|
||||
# recurse, in case there's another alias in this one
|
||||
return self._handle_event(connection, event)
|
||||
|
||||
with self.mutex:
|
||||
# doing regex version first as it has the potential to be more specific
|
||||
log.debug("checking regex handlers for %s", event.type)
|
||||
matching_handlers = sorted(
|
||||
self.regex_handlers.get("all_events", []) +
|
||||
self.regex_handlers.get(event.type, [])
|
||||
)
|
||||
log.debug("got %d", len(matching_handlers))
|
||||
for handler in matching_handlers:
|
||||
log.debug("checking %s vs. %s", handler, event.arguments)
|
||||
for line in event.arguments:
|
||||
match = re.search(handler.regex, line)
|
||||
if match:
|
||||
log.debug("match!")
|
||||
result = handler.callback(connection, event, match)
|
||||
if result == "NO MORE":
|
||||
return
|
||||
with self.mutex:
|
||||
# doing regex version first as it has the potential to be more specific
|
||||
log.debug("checking regex handlers for %s", event.type)
|
||||
matching_handlers = sorted(
|
||||
self.regex_handlers.get("all_events", []) +
|
||||
self.regex_handlers.get(event.type, [])
|
||||
)
|
||||
log.debug("got %d", len(matching_handlers))
|
||||
for handler in matching_handlers:
|
||||
log.debug("checking %s vs. %s", handler, event.arguments)
|
||||
for line in event.arguments:
|
||||
match = re.search(handler.regex, line)
|
||||
if match:
|
||||
log.debug("match!")
|
||||
result = handler.callback(connection, event, match)
|
||||
if result == "NO MORE":
|
||||
return
|
||||
|
||||
matching_handlers = sorted(
|
||||
self.handlers.get("all_events", []) +
|
||||
self.handlers.get(event.type, [])
|
||||
)
|
||||
for handler in matching_handlers:
|
||||
log.debug("not-match")
|
||||
result = handler.callback(connection, event)
|
||||
if result == "NO MORE":
|
||||
return
|
||||
matching_handlers = sorted(
|
||||
self.handlers.get("all_events", []) +
|
||||
self.handlers.get(event.type, [])
|
||||
)
|
||||
for handler in matching_handlers:
|
||||
log.debug("not-match")
|
||||
result = handler.callback(connection, event)
|
||||
if result == "NO MORE":
|
||||
return
|
||||
except Exception as ex:
|
||||
log.error("caught exception!")
|
||||
log.exception(ex)
|
||||
connection.privmsg(event.target, str(ex))
|
||||
|
||||
def try_recursion(self, connection, event):
|
||||
"""Scan message for subcommands to execute and use as part of this command.
|
||||
|
Loading…
Reference in New Issue
Block a user