diff --git a/tts.py b/tts.py index c479726..b421466 100644 --- a/tts.py +++ b/tts.py @@ -131,7 +131,10 @@ class IRC: sys.exit(251) def resp_clearmsg(self, resp): - """ Respond to CLEARMSG """ + """ Respond to CLEARMSG + + :param str resp: IRC Server message + """ logging.info('CLEARMSG received') msgid = False @@ -154,7 +157,10 @@ class IRC: MSG_QUEUE_RAW = filtered_msg_queue def resp_privmsg(self, resp): - """ Respond to PRIVMSG """ + """ Respond to PRIVMSG + + :param str resp: IRC Server message + """ logging.debug('PRIVMSG received') tags = self.get_tags(resp) @@ -207,7 +213,12 @@ class IRC: return def get_tags(self, resp): - """ Strip tags from response """ + """ Strip tags from response + + :param str resp: IRC Server message + + :return dict tags: Message metadata (tags) + """ tags = resp.split(';') for tag in tags: @@ -232,7 +243,12 @@ class IRC: return tags def get_message(self, resp): - """ Process message """ + """ Transform IRC server message and determine length + + :param str resp: IRC Server message + + :return dict msg: Processed message + """ msg = {} msg['message'] = resp.rsplit('PRIVMSG #',1)[1].split(':',1)[1].replace('\r\n','') @@ -241,7 +257,11 @@ class IRC: return msg def priviledged_commands(self, message, tags): - """ Process priviledged commands """ + """ Process priviledged commands + + :param dict message: Message + :param dict tags: Message metadata (tags) + """ msg = message['message'] badges = tags['badges'] @@ -299,7 +319,12 @@ class IRC: self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['TON']) def check_subonly(self, tags): - """ subonly """ + """ Check if subonly mode is enabled and sender is sub + + :param dict tags: Message metadata (tags) + + :return bool: + """ if not CONF['IRC_SUBONLY']: return False @@ -317,7 +342,12 @@ class IRC: return True def check_modonly(self, tags): - """ modonly """ + """ Check if modonly mode is enabled and sender is mod + + :param dict tags: Message metadata (tags) + + :return bool: + """ if not CONF['IRC_MODONLY']: return False @@ -334,7 +364,12 @@ class IRC: return True def check_tts_disabled(self, user): - """ Check if TTS is disabled """ + """ Check if TTS is disabled + + :param str user: Username + + :return bool: + """ if not self.tts_status: self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['DISABLED']) return True @@ -343,7 +378,13 @@ class IRC: return False def check_msg_too_long(self, message, user): - """ Check if message is too long """ + """ Check if message is too long + + :param dict message: Message + :param str user: Username + + :return bool: + """ if message['length'] > CONF['IRC_TTS_LEN']: self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['TOO_LONG']) @@ -358,6 +399,8 @@ class IRC: Check if the given user is on the TTS blacklist :param str user: Username + + :return bool: """ if user in self.tts_denied: @@ -374,6 +417,8 @@ class IRC: Checks if the given user is on the TTS whitelist :param str user: Username + + :return bool: """ if CONF['WHITELIST']: @@ -423,11 +468,10 @@ class IRC: MSG_QUEUE_RAW.append(msg) def get_response(self): - """Get and process response from IRC""" + """ Get and process response from IRC """ try: resp = self.irc.recv(2048).decode("UTF-8") - logging.debug('resp:') - logging.debug(resp) + logging.debug('resp: %s', resp) except socket.timeout: return except Exception: @@ -731,7 +775,7 @@ class IRC: def usermap(self, msg): """ !usermap command - Adds new entries to usermapping in config.yml + Adds a new entry to usermapping in config.yml :param str msg: The IRC message triggering the command """ @@ -756,7 +800,13 @@ class IRC: load_config() def pick(self, msg): - """ !pick command """ + """ !pick command + + Pick a number of users who typed #pickme in the chat + after the pick command was started. + + :param str msg: Number of users to pick + """ if self.pick_status: logging.info('Pick stopped') @@ -918,9 +968,8 @@ class IRC: If no file is given in msg a standard file will be used :param str msg: The IRC message triggering the command - :raise: FileNotFoundError if randomfile does not exists - :return: True if line was successfully read and added to msg_queue - :rtype: bool + + :return bool: """ randomfile = msg.replace('!random', '').strip().lower() @@ -974,8 +1023,6 @@ class IRC: logging.info("Removing %s from deny list", user) self.tts_denied.remove(user) - return - def dtts(self, msg): """ !dtts command @@ -998,20 +1045,18 @@ class IRC: logging.info("Removing %s from allowed list", user) self.tts_allowed.remove(user) - return - class ThreadingSimpleServer(ThreadingMixIn, HTTPServer): """ Threaded HTTP Server """ class HTTPserv(BaseHTTPRequestHandler): - """Simple HTTP Server""" + """ Simple HTTP Server """ def log_message(self, format, *args): # pylint: disable=redefined-builtin - """Suppress HTTP log messages""" + """ Suppress HTTP log messages """ return def do_GET(self): # pylint: disable=invalid-name - """Process GET requests""" + """ Process GET requests """ if self.path == '/': self.send_response(200) self.send_header('Content-type', 'text/html') @@ -1132,14 +1177,14 @@ class HTTPserv(BaseHTTPRequestHandler): self.end_headers() self.wfile.write(bytes("File not found.\n", "utf-8")) - return + return True def http_serve_forever(httpd): - """httpd loop""" + """ httpd loop """ httpd.serve_forever() def load_config(): - """Loading config variables""" + """ Loading config variables """ logging.info("Loading configfile") @@ -1253,6 +1298,7 @@ def send_tts_queue(): def get_url(path=False): """ Generate a valid URL from config values """ + if CONF['HTTP_BIND'] == "0.0.0.0": url = "localhost" else: @@ -1267,6 +1313,7 @@ def get_url(path=False): def check_oauth_token(): """ Check for valid authentication via Twitch API """ + global CONF logging.debug('Checking OAuth Token') @@ -1291,7 +1338,7 @@ def check_oauth_token(): return CONF def main(): - """Main loop""" + """ Main loop """ global CONF CONF = load_config()