Optimized code

This commit is contained in:
gpkvt 2022-08-13 20:05:29 +02:00
parent b281fff743
commit d1c502f38b
1 changed files with 19 additions and 24 deletions

43
tts.py
View File

@ -157,6 +157,7 @@ class IRC:
logging.debug(self.poll) logging.debug(self.poll)
if msg.startswith('!tts'): if msg.startswith('!tts'):
logging.info('!tts command detected')
self.tts_command(message, tags) self.tts_command(message, tags)
def get_tags(self, resp): def get_tags(self, resp):
@ -264,21 +265,19 @@ class IRC:
self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['MODONLY']) self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['MODONLY'])
return True return True
def check_tts_enabled(self, user): def check_tts_disabled(self, user):
""" Check if TTS is enabled """ """ Check if TTS is disabled """
if not self.tts_status: if not self.tts_status:
logging.info('TTS is disabled')
self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['DISABLED']) self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['DISABLED'])
return False return True
logging.debug('TTS is enabled') logging.debug('TTS is enabled')
return True return False
def check_msg_too_long(self, message, user): def check_msg_too_long(self, message, user):
""" Check if message is too long """ """ Check if message is too long """
if message['length'] > conf['IRC_TTS_LEN']: if message['length'] > conf['IRC_TTS_LEN']:
logging.info('TTS message is to long')
self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['TOO_LONG']) self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['TOO_LONG'])
return True return True
@ -300,8 +299,7 @@ class IRC:
if conf['WHITELIST']: if conf['WHITELIST']:
if user not in self.tts_allowed: if user not in self.tts_allowed:
logging.info('User is not on whitelist') logging.debug("tts_allowed: %s", self.tts_allowed)
logging.info(self.tts_allowed)
self.sendmsg( self.sendmsg(
conf['IRC_CHANNEL'], conf['IRC_CHANNEL'],
"@"+str(user), conf['MESSAGE']['WHITELISTONLY'] "@"+str(user), conf['MESSAGE']['WHITELISTONLY']
@ -343,26 +341,24 @@ class IRC:
def tts_command(self, message, tags): def tts_command(self, message, tags):
""" Process !tts command """ """ Process !tts command """
logging.debug('!tts command detected')
logging.debug("tts status: %s", self.tts_status)
user = tags['user'] user = tags['user']
if self.check_tts_enabled(user): if self.check_tts_disabled(user):
return False logging.info('TTS is disabled')
elif self.check_msg_too_long(message, user): elif self.check_msg_too_long(message, user):
return False logging.info('TTS message is too long')
elif self.check_user_denied(user): elif self.check_user_denied(user):
return False logging.info('User is not allowed to use TTS')
elif self.check_subonly(tags): elif self.check_subonly(tags):
return False logging.info('TTS is sub-only')
elif self.check_modonly(tags): elif self.check_modonly(tags):
return False logging.info('TTS is mod-only')
elif self.check_whitelist(user): elif self.check_whitelist(user):
return False logging.info('User is not on whitelist')
else:
self.send_tts_msg(message, tags) logging.info('Sending TTS message to raw_queue')
return True self.send_tts_msg(message, tags)
def get_response(self): def get_response(self):
"""Get and process response from IRC""" """Get and process response from IRC"""
@ -868,10 +864,9 @@ def main():
if not irc.tts_status: if not irc.tts_status:
continue continue
else:
logging.debug('Raw message queue:') logging.debug('msg_queue_raw: %s', msg_queue_raw)
logging.debug(msg_queue_raw) send_tts_queue()
send_tts_queue()
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info('Exiting...') logging.info('Exiting...')