Sentry support
This commit is contained in:
parent
bd208a13df
commit
a986639588
|
@ -3,7 +3,7 @@ import sys
|
||||||
import logging
|
import logging
|
||||||
import signal
|
import signal
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from pyircbot.common import load
|
from pyircbot.common import load, sentry_sdk
|
||||||
from pyircbot import PyIRCBot
|
from pyircbot import PyIRCBot
|
||||||
from json import loads
|
from json import loads
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@ def main():
|
||||||
|
|
||||||
botconfig = loads(sys.stdin.read()) if args.config == "-" else load(args.config)
|
botconfig = loads(sys.stdin.read()) if args.config == "-" else load(args.config)
|
||||||
|
|
||||||
|
if sentry_sdk and "dsn" in botconfig["bot"]:
|
||||||
|
sentry_sdk.init(botconfig["bot"]["dsn"])
|
||||||
|
|
||||||
log.debug(botconfig)
|
log.debug(botconfig)
|
||||||
|
|
||||||
bot = PyIRCBot(botconfig)
|
bot = PyIRCBot(botconfig)
|
||||||
|
|
|
@ -5,11 +5,20 @@ from collections import namedtuple
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import os
|
import os
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
try:
|
||||||
|
import sentry_sdk
|
||||||
|
except ImportError:
|
||||||
|
sentry_sdk = None
|
||||||
|
|
||||||
|
|
||||||
ParsedCommand = namedtuple("ParsedCommand", "command args args_str message")
|
ParsedCommand = namedtuple("ParsedCommand", "command args args_str message")
|
||||||
|
|
||||||
|
|
||||||
|
def report(exception):
|
||||||
|
if sentry_sdk:
|
||||||
|
sentry_sdk.capture_exception(exception)
|
||||||
|
|
||||||
|
|
||||||
class burstbucket(object):
|
class burstbucket(object):
|
||||||
def __init__(self, maximum, interval):
|
def __init__(self, maximum, interval):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -12,7 +12,7 @@ import logging
|
||||||
import traceback
|
import traceback
|
||||||
import sys
|
import sys
|
||||||
from inspect import getargspec
|
from inspect import getargspec
|
||||||
from pyircbot.common import burstbucket, parse_irc_line
|
from pyircbot.common import burstbucket, parse_irc_line, report
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from time import time
|
from time import time
|
||||||
|
@ -80,9 +80,10 @@ class IRCCore(object):
|
||||||
family=self.connection_family,
|
family=self.connection_family,
|
||||||
local_addr=self.bind_addr)
|
local_addr=self.bind_addr)
|
||||||
self.fire_hook("_CONNECT")
|
self.fire_hook("_CONNECT")
|
||||||
except (socket.gaierror, ConnectionRefusedError, OSError):
|
except (socket.gaierror, ConnectionRefusedError, OSError) as e:
|
||||||
traceback.print_exc()
|
|
||||||
logging.warning("Non-fatal connect error, trying next server...")
|
logging.warning("Non-fatal connect error, trying next server...")
|
||||||
|
self.trace()
|
||||||
|
report(e)
|
||||||
self.server = (self.server + 1) % len(self.servers)
|
self.server = (self.server + 1) % len(self.servers)
|
||||||
await asyncio.sleep(1, loop=loop)
|
await asyncio.sleep(1, loop=loop)
|
||||||
continue
|
continue
|
||||||
|
@ -97,11 +98,13 @@ class IRCCore(object):
|
||||||
.format(command, prefix, args, trailing))
|
.format(command, prefix, args, trailing))
|
||||||
else:
|
else:
|
||||||
self.fire_hook(command, args=args, prefix=prefix, trailing=trailing)
|
self.fire_hook(command, args=args, prefix=prefix, trailing=trailing)
|
||||||
except (ConnectionResetError, asyncio.streams.IncompleteReadError):
|
except (ConnectionResetError, asyncio.streams.IncompleteReadError) as e:
|
||||||
traceback.print_exc()
|
self.trace()
|
||||||
|
report(e)
|
||||||
break
|
break
|
||||||
except (UnicodeDecodeError, ):
|
except (UnicodeDecodeError, ) as e:
|
||||||
traceback.print_exc()
|
self.trace()
|
||||||
|
report(e)
|
||||||
self.fire_hook("_DISCONNECT")
|
self.fire_hook("_DISCONNECT")
|
||||||
self.writer.close()
|
self.writer.close()
|
||||||
if self.alive:
|
if self.alive:
|
||||||
|
@ -128,8 +131,8 @@ class IRCCore(object):
|
||||||
try:
|
try:
|
||||||
self.writer.write((line + "\r\n").encode("UTF-8"))
|
self.writer.write((line + "\r\n").encode("UTF-8"))
|
||||||
except Exception as e: # Probably fine if we drop messages while offline
|
except Exception as e: # Probably fine if we drop messages while offline
|
||||||
print(e)
|
self.trace()
|
||||||
print(self.trace())
|
report(e)
|
||||||
|
|
||||||
async def kill(self, message="Help! Another thread is killing me :(", forever=True):
|
async def kill(self, message="Help! Another thread is killing me :(", forever=True):
|
||||||
"""Send quit message, flush queue, and close the socket
|
"""Send quit message, flush queue, and close the socket
|
||||||
|
@ -221,8 +224,9 @@ class IRCCore(object):
|
||||||
else:
|
else:
|
||||||
hook(args, prefix, trailing)
|
hook(args, prefix, trailing)
|
||||||
|
|
||||||
except:
|
except Exception as e:
|
||||||
self.log.warning("Error processing hook: \n%s" % self.trace())
|
self.log.warning("Error processing hook: \n%s" % self.trace())
|
||||||
|
report(e)
|
||||||
|
|
||||||
def addHook(self, command, method):
|
def addHook(self, command, method):
|
||||||
"""**Internal.** Enable (connect) a single hook of a module
|
"""**Internal.** Enable (connect) a single hook of a module
|
||||||
|
|
|
@ -7,23 +7,16 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pyircbot.modulebase import ModuleBase, ModuleHook
|
from pyircbot.modulebase import ModuleBase, hook
|
||||||
|
|
||||||
|
|
||||||
class Error(ModuleBase):
|
class Error(ModuleBase):
|
||||||
def __init__(self, bot, moduleName):
|
|
||||||
ModuleBase.__init__(self, bot, moduleName)
|
|
||||||
self.hooks = [ModuleHook("PRIVMSG", self.error)]
|
|
||||||
|
|
||||||
def error(self, args, prefix, trailing):
|
@hook("PRIVMSG")
|
||||||
"""If the message recieved from IRC has the string "error" in it, cause a ZeroDivisionError
|
def error(self, message, command):
|
||||||
|
"""
|
||||||
:param args: IRC args received
|
If the message recieved from IRC has the string "error" in it, cause a ZeroDivisionError
|
||||||
:type args: list
|
"""
|
||||||
:param prefix: IRC prefix of sender
|
if "error" in message.trailing:
|
||||||
:type prefix: str
|
|
||||||
:param trailing: IRC message body
|
|
||||||
:type trailing: str"""
|
|
||||||
if "error" in trailing:
|
|
||||||
print(10 / 0)
|
print(10 / 0)
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import logging
|
||||||
import sys
|
import sys
|
||||||
from pyircbot.rpc import BotRPC
|
from pyircbot.rpc import BotRPC
|
||||||
from pyircbot.irccore import IRCCore
|
from pyircbot.irccore import IRCCore
|
||||||
|
from pyircbot.common import report
|
||||||
from socket import AF_INET, AF_INET6
|
from socket import AF_INET, AF_INET6
|
||||||
import os.path
|
import os.path
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -44,6 +45,7 @@ class ModuleLoader(object):
|
||||||
self.log.error("Module %s failed to load: " % name)
|
self.log.error("Module %s failed to load: " % name)
|
||||||
self.log.error("Module load failure reason: " + str(e))
|
self.log.error("Module load failure reason: " + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
report(e)
|
||||||
return (False, str(e))
|
return (False, str(e))
|
||||||
else:
|
else:
|
||||||
self.log.warning("Module %s already imported" % name)
|
self.log.warning("Module %s already imported" % name)
|
||||||
|
|
Loading…
Reference in New Issue