Improved error handling

This commit is contained in:
gpkvt 2022-08-12 10:06:42 +02:00
parent b7c74849fd
commit d37363be45
1 changed files with 19 additions and 9 deletions

28
tts.py
View File

@ -65,6 +65,7 @@ class IRC:
except ConnectionResetError: except ConnectionResetError:
logging.warn('JOIN was refused, will try again in 5 seconds.') logging.warn('JOIN was refused, will try again in 5 seconds.')
time.sleep(5) time.sleep(5)
logging.warn('Please check your credentials, if this error persists.')
self.irc.send(bytes("JOIN " + channel + "\r\n", "UTF-8")) self.irc.send(bytes("JOIN " + channel + "\r\n", "UTF-8"))
def sendpriv(self, channel, user, msg): def sendpriv(self, channel, user, msg):
@ -78,6 +79,7 @@ class IRC:
except socket.timeout: except socket.timeout:
return False return False
except: except:
logging.exception('An unknown error occured while getting a IRC response.')
sys.exit(255) sys.exit(255)
if resp.find('PING') != -1: if resp.find('PING') != -1:
@ -108,6 +110,14 @@ class IRC:
return True return True
if resp.find('NOTICE') != -1:
if 'Login authentication failed' in resp:
try:
raise RuntimeError()
except RuntimeError:
logging.exception('Login failed, please check your credentials and try again.')
sys.exit(251)
if resp.find('PRIVMSG') != -1: if resp.find('PRIVMSG') != -1:
logging.debug('PRIVMSG received') logging.debug('PRIVMSG received')
badges = False badges = False
@ -347,16 +357,16 @@ def load_config():
conf['IRC_CHANNEL'] = cfg['irc']['channel'] conf['IRC_CHANNEL'] = cfg['irc']['channel']
conf['IRC_USERNAME'] = cfg['irc']['username'] conf['IRC_USERNAME'] = cfg['irc']['username']
conf['IRC_OAUTH_TOKEN'] = cfg['irc']['oauth_token'] conf['IRC_OAUTH_TOKEN'] = cfg['irc']['oauth_token']
conf['IRC_SERVER'] = cfg['irc']['server'] conf['IRC_SERVER'] = cfg['irc']['server'] or "irc.chat.twitch.tv"
conf['IRC_CLEARMSG_TIMEOUT'] = cfg['irc']['clearmsg_timeout'] conf['IRC_CLEARMSG_TIMEOUT'] = cfg['irc']['clearmsg_timeout'] or 60
conf['IRC_SUBONLY'] = cfg['bot']['subonly'] conf['IRC_SUBONLY'] = cfg['bot']['subonly'] or False
conf['IRC_MODONLY'] = cfg['bot']['modonly'] conf['IRC_MODONLY'] = cfg['bot']['modonly'] or False
conf['IRC_TTS_LEN'] = cfg['bot']['message_length'] conf['IRC_TTS_LEN'] = cfg['bot']['message_length'] or 200
conf['LOG_LEVEL'] = cfg['log']['level'] conf['LOG_LEVEL'] = cfg['log']['level'] or "INFO"
conf['HTTP_PORT'] = cfg['http']['port'] conf['HTTP_PORT'] = cfg['http']['port'] or 80
conf['HTTP_BIND'] = cfg['http']['bind'] conf['HTTP_BIND'] = cfg['http']['bind'] or "localhost"
conf['MESSAGE'] = {} conf['MESSAGE'] = {}
conf['MESSAGE']['TOO_LONG'] = cfg['messages']['too_long'] or "Sorry, your message is too long" conf['MESSAGE']['TOO_LONG'] = cfg['messages']['too_long'] or "Sorry, your message is too long"
@ -402,7 +412,7 @@ msg_queue_raw = []
msg_queue = {} msg_queue = {}
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(module)s %(threadName)s %(levelname)s: %(message)s') logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(module)s %(threadName)s %(levelname)s: %(message)s')
sys.tracebacklimit = 1 sys.tracebacklimit = 0
def main(): def main():
conf = load_config() conf = load_config()