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