mirror of
				https://gitlab.com/gpvkt/twitchtts.git
				synced 2025-10-31 00:57:35 +01:00 
			
		
		
		
	Renamed conf variable
This commit is contained in:
		
							parent
							
								
									5d2c03cc0f
								
							
						
					
					
						commit
						c65e3b86b1
					
				
					 1 changed files with 161 additions and 161 deletions
				
			
		
							
								
								
									
										322
									
								
								tts.py
									
										
									
									
									
								
							
							
						
						
									
										322
									
								
								tts.py
									
										
									
									
									
								
							|  | @ -1,6 +1,6 @@ | ||||||
| #!/usr/bin/python3 | #!/usr/bin/python3 | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| # pylint: disable=line-too-long,too-many-lines | # pylint: disable=bare-except | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
|     TwitchTTS |     TwitchTTS | ||||||
|  | @ -53,7 +53,7 @@ class IRC: | ||||||
|         self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |         self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||||||
|         self.tts_denied = [] |         self.tts_denied = [] | ||||||
|         self.tts_allowed = [] |         self.tts_allowed = [] | ||||||
|         self.tts_status = conf['TTS_STARTENABLED'] |         self.tts_status = CONF['TTS_STARTENABLED'] | ||||||
|         self.quickvote_status = False |         self.quickvote_status = False | ||||||
|         self.pick_status = False |         self.pick_status = False | ||||||
|         self.votemsg = False |         self.votemsg = False | ||||||
|  | @ -63,8 +63,8 @@ class IRC: | ||||||
|         self.picknumber = 1 |         self.picknumber = 1 | ||||||
|         self.pickcount = 0 |         self.pickcount = 0 | ||||||
| 
 | 
 | ||||||
|         if 'WHITELIST_USER' in conf: |         if 'WHITELIST_USER' in CONF: | ||||||
|             self.tts_allowed = conf['WHITELIST_USER'] |             self.tts_allowed = CONF['WHITELIST_USER'] | ||||||
| 
 | 
 | ||||||
|     def connect(self, server, port, channel, botnick, botpass): |     def connect(self, server, port, channel, botnick, botpass): | ||||||
|         """ Connect to Twitch IRC servers """ |         """ Connect to Twitch IRC servers """ | ||||||
|  | @ -179,12 +179,12 @@ class IRC: | ||||||
|             self.Commands.tts(self, message, tags) |             self.Commands.tts(self, message, tags) | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         if msg.startswith('!wiki') and conf['FEATURE']['WIKI']: |         if msg.startswith('!wiki') and CONF['FEATURE']['WIKI']: | ||||||
|             logging.debug("!wiki command detected") |             logging.debug("!wiki command detected") | ||||||
|             self.Commands.wiki(self, tags, msg) |             self.Commands.wiki(self, tags, msg) | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         if conf['FEATURE']['QUOTE']: |         if CONF['FEATURE']['QUOTE']: | ||||||
|             if msg.startswith('!addquote'): |             if msg.startswith('!addquote'): | ||||||
|                 logging.debug("!addquote command detected") |                 logging.debug("!addquote command detected") | ||||||
|                 self.Commands.addquote(self, tags, msg) |                 self.Commands.addquote(self, tags, msg) | ||||||
|  | @ -237,23 +237,23 @@ class IRC: | ||||||
|         user = tags['user'] |         user = tags['user'] | ||||||
| 
 | 
 | ||||||
|         if 'broadcaster' in badges or 'moderator' in badges: |         if 'broadcaster' in badges or 'moderator' in badges: | ||||||
|             if msg.startswith('!ping') and conf['FEATURE']['PING']: |             if msg.startswith('!ping') and CONF['FEATURE']['PING']: | ||||||
|                 logging.debug("Ping check received.") |                 logging.debug("Ping check received.") | ||||||
|                 self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), "Pong!") |                 self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), "Pong!") | ||||||
| 
 | 
 | ||||||
|             elif msg.startswith('!version') and conf['FEATURE']['VERSION']: |             elif msg.startswith('!version') and CONF['FEATURE']['VERSION']: | ||||||
|                 logging.debug("!version command detected") |                 logging.debug("!version command detected") | ||||||
|                 self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), VERSION) |                 self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), VERSION) | ||||||
| 
 | 
 | ||||||
|             elif msg.startswith('!pick') and conf['FEATURE']['PICK']: |             elif msg.startswith('!pick') and CONF['FEATURE']['PICK']: | ||||||
|                 logging.debug("!pick command detected") |                 logging.debug("!pick command detected") | ||||||
|                 self.Commands.pick(self, msg) |                 self.Commands.pick(self, msg) | ||||||
| 
 | 
 | ||||||
|             elif msg.startswith('!random') and conf['FEATURE']['RANDOM']: |             elif msg.startswith('!random') and CONF['FEATURE']['RANDOM']: | ||||||
|                 logging.info('!random command detected') |                 logging.info('!random command detected') | ||||||
|                 self.Commands.random(self, msg) |                 self.Commands.random(self, msg) | ||||||
| 
 | 
 | ||||||
|             elif msg.startswith('!quickvote') and conf['FEATURE']['QUOTE']: |             elif msg.startswith('!quickvote') and CONF['FEATURE']['QUOTE']: | ||||||
|                 logging.info("!quickvote command detected") |                 logging.info("!quickvote command detected") | ||||||
|                 self.Commands.quickvote(self, msg) |                 self.Commands.quickvote(self, msg) | ||||||
| 
 | 
 | ||||||
|  | @ -278,19 +278,19 @@ class IRC: | ||||||
|                 msg_queue.clear() |                 msg_queue.clear() | ||||||
|                 msg_queue_raw.clear() |                 msg_queue_raw.clear() | ||||||
|                 self.tts_status = False |                 self.tts_status = False | ||||||
|                 self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['TOFF']) |                 self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['TOFF']) | ||||||
| 
 | 
 | ||||||
|             elif msg.startswith('!ton'): |             elif msg.startswith('!ton'): | ||||||
|                 logging.info('TTS is now turned on') |                 logging.info('TTS is now turned on') | ||||||
|                 msg_queue.clear() |                 msg_queue.clear() | ||||||
|                 msg_queue_raw.clear() |                 msg_queue_raw.clear() | ||||||
|                 self.tts_status = True |                 self.tts_status = True | ||||||
|                 self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['TON']) |                 self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['TON']) | ||||||
| 
 | 
 | ||||||
|     def check_subonly(self, tags): |     def check_subonly(self, tags): | ||||||
|         """ subonly """ |         """ subonly """ | ||||||
| 
 | 
 | ||||||
|         if not conf['IRC_SUBONLY']: |         if not CONF['IRC_SUBONLY']: | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|         subscriber = tags['subscriber'] |         subscriber = tags['subscriber'] | ||||||
|  | @ -302,13 +302,13 @@ class IRC: | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|         logging.debug('TTS is sub-only') |         logging.debug('TTS is sub-only') | ||||||
|         self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['SUBONLY']) |         self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['SUBONLY']) | ||||||
|         return True |         return True | ||||||
| 
 | 
 | ||||||
|     def check_modonly(self, tags): |     def check_modonly(self, tags): | ||||||
|         """ modonly """ |         """ modonly """ | ||||||
| 
 | 
 | ||||||
|         if not conf['IRC_MODONLY']: |         if not CONF['IRC_MODONLY']: | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|         badges = tags['badges'] |         badges = tags['badges'] | ||||||
|  | @ -319,13 +319,13 @@ class IRC: | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|         logging.debug('TTS is mod-only') |         logging.debug('TTS is mod-only') | ||||||
|         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_disabled(self, user): |     def check_tts_disabled(self, user): | ||||||
|         """ Check if TTS is disabled """ |         """ Check if TTS is disabled """ | ||||||
|         if not self.tts_status: |         if not self.tts_status: | ||||||
|             self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['DISABLED']) |             self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['DISABLED']) | ||||||
|             return True |             return True | ||||||
| 
 | 
 | ||||||
|         logging.debug('TTS is enabled') |         logging.debug('TTS is enabled') | ||||||
|  | @ -334,8 +334,8 @@ class IRC: | ||||||
|     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']: | ||||||
|             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 | ||||||
| 
 | 
 | ||||||
|         logging.debug('Check length: Message is ok') |         logging.debug('Check length: Message is ok') | ||||||
|  | @ -345,7 +345,7 @@ class IRC: | ||||||
|         """ Check if user is on denied list """ |         """ Check if user is on denied list """ | ||||||
|         if user in self.tts_denied: |         if user in self.tts_denied: | ||||||
|             logging.info("%s is not allowed to use TTS", user) |             logging.info("%s is not allowed to use TTS", user) | ||||||
|             self.sendmsg(conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['DENIED']) |             self.sendmsg(CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['DENIED']) | ||||||
|             return True |             return True | ||||||
| 
 | 
 | ||||||
|         logging.debug("%s is allowed to use TTS", user) |         logging.debug("%s is allowed to use TTS", user) | ||||||
|  | @ -354,12 +354,12 @@ class IRC: | ||||||
|     def check_whitelist(self, user): |     def check_whitelist(self, user): | ||||||
|         """ Check Whitelist """ |         """ Check Whitelist """ | ||||||
| 
 | 
 | ||||||
|         if conf['WHITELIST']: |         if CONF['WHITELIST']: | ||||||
|             if user not in self.tts_allowed: |             if user not in self.tts_allowed: | ||||||
|                 logging.debug("tts_allowed: %s", self.tts_allowed) |                 logging.debug("tts_allowed: %s", self.tts_allowed) | ||||||
|                 self.sendmsg( |                 self.sendmsg( | ||||||
|                     conf['IRC_CHANNEL'], |                     CONF['IRC_CHANNEL'], | ||||||
|                     "@"+str(user), conf['MESSAGE']['WHITELISTONLY'] |                     "@"+str(user), CONF['MESSAGE']['WHITELISTONLY'] | ||||||
|                 ) |                 ) | ||||||
|                 return False |                 return False | ||||||
|             return True |             return True | ||||||
|  | @ -491,8 +491,8 @@ class IRC: | ||||||
|                 date = time.strftime("%d.%m.%Y") |                 date = time.strftime("%d.%m.%Y") | ||||||
| 
 | 
 | ||||||
|                 try: |                 try: | ||||||
|                     token = conf['IRC_OAUTH_TOKEN'].replace('oauth:','') |                     token = CONF['IRC_OAUTH_TOKEN'].replace('oauth:','') | ||||||
|                     login = conf['IRC_CHANNEL'].replace('#','') |                     login = CONF['IRC_CHANNEL'].replace('#','') | ||||||
|                     api_endpoint = "https://api.twitch.tv/helix/users?login="+str(login) |                     api_endpoint = "https://api.twitch.tv/helix/users?login="+str(login) | ||||||
|                     headers = { |                     headers = { | ||||||
|                         'Content-type': 'application/x-form-urlencoded', |                         'Content-type': 'application/x-form-urlencoded', | ||||||
|  | @ -514,7 +514,7 @@ class IRC: | ||||||
|                     game = data['data'][0]['game_name'] |                     game = data['data'][0]['game_name'] | ||||||
| 
 | 
 | ||||||
|                     quote = f"#{nol}: \"{quote[1]}\" -{username}/{game} ({date})\n" |                     quote = f"#{nol}: \"{quote[1]}\" -{username}/{game} ({date})\n" | ||||||
|                 except: # pylint: disable=bare-except |                 except: | ||||||
|                     logging.warning('Could not get metadata for quote') |                     logging.warning('Could not get metadata for quote') | ||||||
|                     quote = f"#{nol}: \"{quote[1]}\" -{username} ({date})\n" |                     quote = f"#{nol}: \"{quote[1]}\" -{username} ({date})\n" | ||||||
| 
 | 
 | ||||||
|  | @ -522,7 +522,7 @@ class IRC: | ||||||
|                 with open("quotes.txt", "ab") as file: |                 with open("quotes.txt", "ab") as file: | ||||||
|                     file.write(quote.encode('utf-8')) |                     file.write(quote.encode('utf-8')) | ||||||
| 
 | 
 | ||||||
|                 msg = f"{conf['MESSAGE']['QUOTE_ADDED_PREFIX']} #{nol} {conf['MESSAGE']['QUOTE_ADDED_SUFFIX']}" |                 msg = f"{CONF['MESSAGE']['QUOTE_ADDED_PREFIX']} #{nol} {CONF['MESSAGE']['QUOTE_ADDED_SUFFIX']}" | ||||||
| 
 | 
 | ||||||
|                 raw_msg = { |                 raw_msg = { | ||||||
|                     "TTS": True, |                     "TTS": True, | ||||||
|  | @ -530,25 +530,25 @@ class IRC: | ||||||
|                     "badges": True, |                     "badges": True, | ||||||
|                     "subscriber": True, |                     "subscriber": True, | ||||||
|                     "msgid": True, |                     "msgid": True, | ||||||
|                     "user": conf['IRC_USERNAME'], |                     "user": CONF['IRC_USERNAME'], | ||||||
|                     "length": conf['IRC_TTS_LEN'], |                     "length": CONF['IRC_TTS_LEN'], | ||||||
|                     "queuetime": datetime.datetime.now(), |                     "queuetime": datetime.datetime.now(), | ||||||
|                     "timestamp": str(time.time_ns()) |                     "timestamp": str(time.time_ns()) | ||||||
|                 } |                 } | ||||||
|                 msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] |                 msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] | ||||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), msg) |                 IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@"+str(user), msg) | ||||||
| 
 | 
 | ||||||
|         def wiki(self, tags, msg): |         def wiki(self, tags, msg): | ||||||
|             """ !wiki command """ |             """ !wiki command """ | ||||||
| 
 | 
 | ||||||
|             try: |             try: | ||||||
|                 user = tags['user'] |                 user = tags['user'] | ||||||
|                 wikipedia.set_lang(conf['WIKI_LANG']) |                 wikipedia.set_lang(CONF['WIKI_LANG']) | ||||||
|                 msg = msg.replace('!wiki', '').strip() |                 msg = msg.replace('!wiki', '').strip() | ||||||
|                 wikiresult = wikipedia.summary(msg, sentences=3) |                 wikiresult = wikipedia.summary(msg, sentences=3) | ||||||
| 
 | 
 | ||||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), wikiresult) |                 IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@"+str(user), wikiresult) | ||||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), wikipedia.page(msg).url) |                 IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@"+str(user), wikipedia.page(msg).url) | ||||||
| 
 | 
 | ||||||
|                 wikiresult = wikiresult.replace('==', '') |                 wikiresult = wikiresult.replace('==', '') | ||||||
| 
 | 
 | ||||||
|  | @ -559,16 +559,16 @@ class IRC: | ||||||
|                     "subscriber": True, |                     "subscriber": True, | ||||||
|                     "msgid": True, |                     "msgid": True, | ||||||
|                     "user": 'wikipedia', |                     "user": 'wikipedia', | ||||||
|                     "length": conf['IRC_TTS_LEN'], |                     "length": CONF['IRC_TTS_LEN'], | ||||||
|                     "queuetime": datetime.datetime.now(), |                     "queuetime": datetime.datetime.now(), | ||||||
|                     "timestamp": str(time.time_ns()) |                     "timestamp": str(time.time_ns()) | ||||||
|                 } |                 } | ||||||
|                 msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] |                 msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] | ||||||
| 
 | 
 | ||||||
|             except wikipedia.exceptions.DisambiguationError: |             except wikipedia.exceptions.DisambiguationError: | ||||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['WIKI_TOO_MANY']) |                 IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['WIKI_TOO_MANY']) | ||||||
|             except: # pylint: disable=bare-except |             except: | ||||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@"+str(user), conf['MESSAGE']['WIKI_NO_RESULT']) |                 IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@"+str(user), CONF['MESSAGE']['WIKI_NO_RESULT']) | ||||||
| 
 | 
 | ||||||
|         def quote(self, tags, msg = False): |         def quote(self, tags, msg = False): | ||||||
|             """ !smartquote command |             """ !smartquote command | ||||||
|  | @ -627,8 +627,8 @@ class IRC: | ||||||
| 
 | 
 | ||||||
|             if not 'quote' in vars(): |             if not 'quote' in vars(): | ||||||
|                 logging.info('No quote found.') |                 logging.info('No quote found.') | ||||||
|                 quote = conf['MESSAGE']['QUOTE_NOT_FOUND'] |                 quote = CONF['MESSAGE']['QUOTE_NOT_FOUND'] | ||||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "", quote) |                 IRC.sendmsg(self, CONF['IRC_CHANNEL'], "", quote) | ||||||
|                 return False |                 return False | ||||||
| 
 | 
 | ||||||
|             if not isinstance(quote, str): |             if not isinstance(quote, str): | ||||||
|  | @ -647,7 +647,7 @@ class IRC: | ||||||
|             else: |             else: | ||||||
|                 logging.info('Sending quote to TTS') |                 logging.info('Sending quote to TTS') | ||||||
|                 logging.debug("Quote: %s", quote) |                 logging.debug("Quote: %s", quote) | ||||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "", quote) |                 IRC.sendmsg(self, CONF['IRC_CHANNEL'], "", quote) | ||||||
| 
 | 
 | ||||||
|                 quote = quote.rsplit('(', 1)[0] |                 quote = quote.rsplit('(', 1)[0] | ||||||
| 
 | 
 | ||||||
|  | @ -657,8 +657,8 @@ class IRC: | ||||||
|                     "badges": True, |                     "badges": True, | ||||||
|                     "subscriber": True, |                     "subscriber": True, | ||||||
|                     "msgid": True, |                     "msgid": True, | ||||||
|                     "user": conf['IRC_USERNAME'], |                     "user": CONF['IRC_USERNAME'], | ||||||
|                     "length": conf['IRC_TTS_LEN'], |                     "length": CONF['IRC_TTS_LEN'], | ||||||
|                     "queuetime": datetime.datetime.now(), |                     "queuetime": datetime.datetime.now(), | ||||||
|                     "timestamp": str(time.time_ns()) |                     "timestamp": str(time.time_ns()) | ||||||
|                 } |                 } | ||||||
|  | @ -676,7 +676,7 @@ class IRC: | ||||||
| 
 | 
 | ||||||
|             try: |             try: | ||||||
|                 delay = msg.split(' ')[1] |                 delay = msg.split(' ')[1] | ||||||
|             except: # pylint: disable=bare-except |             except: | ||||||
|                 delay = False |                 delay = False | ||||||
| 
 | 
 | ||||||
|             if delay: |             if delay: | ||||||
|  | @ -703,7 +703,7 @@ class IRC: | ||||||
|                 splitmsg = msg.split(" ") |                 splitmsg = msg.split(" ") | ||||||
|                 username, *mappingname = splitmsg |                 username, *mappingname = splitmsg | ||||||
|                 mappingname = ' '.join(mappingname) |                 mappingname = ' '.join(mappingname) | ||||||
|             except: # pylint: disable=bare-except |             except: | ||||||
|                 username = False |                 username = False | ||||||
|                 mappingname = False |                 mappingname = False | ||||||
| 
 | 
 | ||||||
|  | @ -734,36 +734,36 @@ class IRC: | ||||||
| 
 | 
 | ||||||
|                     converted_picks = [str(element) for element in picks] |                     converted_picks = [str(element) for element in picks] | ||||||
|                     joined_picks = " ".join(converted_picks) |                     joined_picks = " ".join(converted_picks) | ||||||
|                 except: # pylint: disable=bare-except |                 except: | ||||||
|                     logging.error("There was an error during picking.") |                     logging.error("There was an error during picking.") | ||||||
|                     joined_picks = False |                     joined_picks = False | ||||||
| 
 | 
 | ||||||
|                 if joined_picks: |                 if joined_picks: | ||||||
|                     raw_msg = { |                     raw_msg = { | ||||||
|                         "TTS": True, |                         "TTS": True, | ||||||
|                         "msg": conf['MESSAGE']['PICKRESULT'] +" "+ str(joined_picks), |                         "msg": CONF['MESSAGE']['PICKRESULT'] +" "+ str(joined_picks), | ||||||
|                         "badges": True, |                         "badges": True, | ||||||
|                         "subscriber": True, |                         "subscriber": True, | ||||||
|                         "msgid": True, |                         "msgid": True, | ||||||
|                         "user": conf['IRC_USERNAME'], |                         "user": CONF['IRC_USERNAME'], | ||||||
|                         "length": conf['IRC_TTS_LEN'], |                         "length": CONF['IRC_TTS_LEN'], | ||||||
|                         "queuetime": datetime.datetime.now(), |                         "queuetime": datetime.datetime.now(), | ||||||
|                         "timestamp": str(time.time_ns()) |                         "timestamp": str(time.time_ns()) | ||||||
|                     } |                     } | ||||||
|                     msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] |                     msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] | ||||||
| 
 | 
 | ||||||
|                     IRC.sendmsg(self, |                     IRC.sendmsg(self, | ||||||
|                         conf['IRC_CHANNEL'], "", |                         CONF['IRC_CHANNEL'], "", | ||||||
|                         conf['MESSAGE']['PICKRESULT'] |                         CONF['MESSAGE']['PICKRESULT'] | ||||||
|                     ) |                     ) | ||||||
|                     IRC.sendmsg(self, |                     IRC.sendmsg(self, | ||||||
|                         conf['IRC_CHANNEL'], "*", |                         CONF['IRC_CHANNEL'], "*", | ||||||
|                         joined_picks |                         joined_picks | ||||||
|                     ) |                     ) | ||||||
|                 else: |                 else: | ||||||
|                     IRC.sendmsg(self, |                     IRC.sendmsg(self, | ||||||
|                         conf['IRC_CHANNEL'], "*", |                         CONF['IRC_CHANNEL'], "*", | ||||||
|                         conf['MESSAGE']['PICKNONE'] |                         CONF['MESSAGE']['PICKNONE'] | ||||||
|                     ) |                     ) | ||||||
| 
 | 
 | ||||||
|                 self.pick_status = False |                 self.pick_status = False | ||||||
|  | @ -783,8 +783,8 @@ class IRC: | ||||||
|             logging.info("Will pick %s participants", self.picknumber) |             logging.info("Will pick %s participants", self.picknumber) | ||||||
| 
 | 
 | ||||||
|             IRC.sendmsg(self, |             IRC.sendmsg(self, | ||||||
|                 conf['IRC_CHANNEL'], "@chat", |                 CONF['IRC_CHANNEL'], "@chat", | ||||||
|                 conf['MESSAGE']['PICKSTART'] |                 CONF['MESSAGE']['PICKSTART'] | ||||||
|             ) |             ) | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|  | @ -802,23 +802,23 @@ class IRC: | ||||||
| 
 | 
 | ||||||
|                 if self.pollcount == 0: |                 if self.pollcount == 0: | ||||||
|                     logging.info("Nobody voted") |                     logging.info("Nobody voted") | ||||||
|                     IRC.sendmsg(self, conf['IRC_CHANNEL'], "@chat", conf['MESSAGE']['VOTEEND']) |                     IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@chat", CONF['MESSAGE']['VOTEEND']) | ||||||
|                     IRC.sendmsg(self, conf['IRC_CHANNEL'], "*", conf['MESSAGE']['VOTENOBODY']) |                     IRC.sendmsg(self, CONF['IRC_CHANNEL'], "*", CONF['MESSAGE']['VOTENOBODY']) | ||||||
| 
 | 
 | ||||||
|                     raw_msg = { |                     raw_msg = { | ||||||
|                         "TTS": True, |                         "TTS": True, | ||||||
|                         "msg": conf['MESSAGE']['VOTENOBODY'], |                         "msg": CONF['MESSAGE']['VOTENOBODY'], | ||||||
|                         "badges": True, |                         "badges": True, | ||||||
|                         "subscriber": True, |                         "subscriber": True, | ||||||
|                         "msgid": True, |                         "msgid": True, | ||||||
|                         "user": conf['IRC_USERNAME'], |                         "user": CONF['IRC_USERNAME'], | ||||||
|                         "length": conf['IRC_TTS_LEN'], |                         "length": CONF['IRC_TTS_LEN'], | ||||||
|                         "queuetime": datetime.datetime.now(), |                         "queuetime": datetime.datetime.now(), | ||||||
|                         "timestamp": str(time.time_ns()) |                         "timestamp": str(time.time_ns()) | ||||||
|                     } |                     } | ||||||
|                     msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] |                     msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] | ||||||
| 
 | 
 | ||||||
|                     logging.info('The result is: %s', conf['MESSAGE']['VOTENOBODY']) |                     logging.info('The result is: %s', CONF['MESSAGE']['VOTENOBODY']) | ||||||
|                     logging.debug('Votemsg: %s', msg) |                     logging.debug('Votemsg: %s', msg) | ||||||
| 
 | 
 | ||||||
|                     self.quickvote_status = False |                     self.quickvote_status = False | ||||||
|  | @ -828,31 +828,31 @@ class IRC: | ||||||
|                 logging.info("Counting votes") |                 logging.info("Counting votes") | ||||||
|                 count = 0 |                 count = 0 | ||||||
|                 count = Counter(self.poll.values()).most_common(5) |                 count = Counter(self.poll.values()).most_common(5) | ||||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@chat", conf['MESSAGE']['VOTEEND']) |                 IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@chat", CONF['MESSAGE']['VOTEEND']) | ||||||
| 
 | 
 | ||||||
|                 logging.debug(count) |                 logging.debug(count) | ||||||
| 
 | 
 | ||||||
|                 raw_msg = { |                 raw_msg = { | ||||||
|                     "TTS": True, |                     "TTS": True, | ||||||
|                     "msg": conf['MESSAGE']['VOTERESULT'] +" "+ str(count[0][0].replace('#','')), |                     "msg": CONF['MESSAGE']['VOTERESULT'] +" "+ str(count[0][0].replace('#','')), | ||||||
|                     "badges": True, |                     "badges": True, | ||||||
|                     "subscriber": True, |                     "subscriber": True, | ||||||
|                     "msgid": True, |                     "msgid": True, | ||||||
|                     "user": conf['IRC_USERNAME'], |                     "user": CONF['IRC_USERNAME'], | ||||||
|                     "length": conf['IRC_TTS_LEN'], |                     "length": CONF['IRC_TTS_LEN'], | ||||||
|                     "queuetime": datetime.datetime.now(), |                     "queuetime": datetime.datetime.now(), | ||||||
|                     "timestamp": str(time.time_ns()) |                     "timestamp": str(time.time_ns()) | ||||||
|                 } |                 } | ||||||
|                 msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] |                 msg_queue[raw_msg['timestamp']] = [raw_msg['user'], raw_msg['msg']] | ||||||
| 
 | 
 | ||||||
|                 logging.info('The result is: %s', conf['MESSAGE']['VOTERESULT'] +" "+ str(count[0])) |                 logging.info('The result is: %s', CONF['MESSAGE']['VOTERESULT'] +" "+ str(count[0])) | ||||||
|                 logging.debug('Votemsg: %s', msg) |                 logging.debug('Votemsg: %s', msg) | ||||||
| 
 | 
 | ||||||
|                 for key, value in count: |                 for key, value in count: | ||||||
|                     IRC.sendmsg( |                     IRC.sendmsg( | ||||||
|                         self, |                         self, | ||||||
|                         conf['IRC_CHANNEL'], "*", |                         CONF['IRC_CHANNEL'], "*", | ||||||
|                         str(key)+" ("+str(value)+ " "+ conf['MESSAGE']['VOTES'] + ")" |                         str(key)+" ("+str(value)+ " "+ CONF['MESSAGE']['VOTES'] + ")" | ||||||
|                     ) |                     ) | ||||||
| 
 | 
 | ||||||
|                 self.quickvote_status = False |                 self.quickvote_status = False | ||||||
|  | @ -865,11 +865,11 @@ class IRC: | ||||||
|             self.votemsg = msg.split('!quickvote', 1)[1].strip() |             self.votemsg = msg.split('!quickvote', 1)[1].strip() | ||||||
|             if self.votemsg: |             if self.votemsg: | ||||||
|                 IRC.sendmsg(self, |                 IRC.sendmsg(self, | ||||||
|                     conf['IRC_CHANNEL'], "@chat", |                     CONF['IRC_CHANNEL'], "@chat", | ||||||
|                     conf['MESSAGE']['VOTESTART'] + " (" + str(self.votemsg) + ")" |                     CONF['MESSAGE']['VOTESTART'] + " (" + str(self.votemsg) + ")" | ||||||
|                 ) |                 ) | ||||||
|             else: |             else: | ||||||
|                 IRC.sendmsg(self, conf['IRC_CHANNEL'], "@chat", conf['MESSAGE']['VOTESTART']) |                 IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@chat", CONF['MESSAGE']['VOTESTART']) | ||||||
| 
 | 
 | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|  | @ -906,8 +906,8 @@ class IRC: | ||||||
|                 "badges": True, |                 "badges": True, | ||||||
|                 "subscriber": True, |                 "subscriber": True, | ||||||
|                 "msgid": True, |                 "msgid": True, | ||||||
|                 "user": conf['IRC_USERNAME'], |                 "user": CONF['IRC_USERNAME'], | ||||||
|                 "length": conf['IRC_TTS_LEN'], |                 "length": CONF['IRC_TTS_LEN'], | ||||||
|                 "queuetime": datetime.datetime.now(), |                 "queuetime": datetime.datetime.now(), | ||||||
|                 "timestamp": str(time.time_ns()) |                 "timestamp": str(time.time_ns()) | ||||||
|             } |             } | ||||||
|  | @ -1021,7 +1021,7 @@ class HTTPserv(BaseHTTPRequestHandler): | ||||||
|             self.send_header('Content-type', 'text/json') |             self.send_header('Content-type', 'text/json') | ||||||
|             self.end_headers() |             self.end_headers() | ||||||
| 
 | 
 | ||||||
|             usermap = conf['USERMAP'] |             usermap = CONF['USERMAP'] | ||||||
|             sorted_tts = {k: msg_queue[k] for k in sorted(msg_queue, reverse=True)} |             sorted_tts = {k: msg_queue[k] for k in sorted(msg_queue, reverse=True)} | ||||||
|             logging.debug(usermap) |             logging.debug(usermap) | ||||||
| 
 | 
 | ||||||
|  | @ -1029,10 +1029,10 @@ class HTTPserv(BaseHTTPRequestHandler): | ||||||
|                 if key not in tts_done: |                 if key not in tts_done: | ||||||
|                     if msg_queue[key][0].lower() in usermap: |                     if msg_queue[key][0].lower() in usermap: | ||||||
|                         logging.debug('Using usermap for user: %s (%s)', msg_queue[key][0], usermap[msg_queue[key][0].lower()]) |                         logging.debug('Using usermap for user: %s (%s)', msg_queue[key][0], usermap[msg_queue[key][0].lower()]) | ||||||
|                         tts = {str(key): str(usermap[msg_queue[key][0].lower()]) + " " + str(conf['MESSAGE']['SAYS']) + ":" + str(msg_queue[key][1])} |                         tts = {str(key): str(usermap[msg_queue[key][0].lower()]) + " " + str(CONF['MESSAGE']['SAYS']) + ":" + str(msg_queue[key][1])} | ||||||
|                     else: |                     else: | ||||||
|                         logging.debug('No usermap entry found for user: %s', msg_queue[key][0]) |                         logging.debug('No usermap entry found for user: %s', msg_queue[key][0]) | ||||||
|                         tts = {str(key): str(msg_queue[key][0]) + " " + str(conf['MESSAGE']['SAYS']) + ":" + str(msg_queue[key][1])} |                         tts = {str(key): str(msg_queue[key][0]) + " " + str(CONF['MESSAGE']['SAYS']) + ":" + str(msg_queue[key][1])} | ||||||
| 
 | 
 | ||||||
|             tts_json = json.dumps(tts) |             tts_json = json.dumps(tts) | ||||||
|             self.wfile.write(bytes(str(tts_json)+"\n", "utf-8")) |             self.wfile.write(bytes(str(tts_json)+"\n", "utf-8")) | ||||||
|  | @ -1057,11 +1057,11 @@ class HTTPserv(BaseHTTPRequestHandler): | ||||||
|             data['client_id'] = "ebo548vs6tq54c9zlrgin2yfzzlrrs" |             data['client_id'] = "ebo548vs6tq54c9zlrgin2yfzzlrrs" | ||||||
|             data['response_type'] = "token" |             data['response_type'] = "token" | ||||||
|             data['scope'] = "chat:edit chat:read" |             data['scope'] = "chat:edit chat:read" | ||||||
|             if conf['HTTP_PORT'] == 80: |             if CONF['HTTP_PORT'] == 80: | ||||||
|                 data['redirect_uri'] = "http://localhost/token" |                 data['redirect_uri'] = "http://localhost/token" | ||||||
|             elif conf['HTTP_PORT'] == 8080: |             elif CONF['HTTP_PORT'] == 8080: | ||||||
|                 data['redirect_uri'] = "http://localhost:8080/token" |                 data['redirect_uri'] = "http://localhost:8080/token" | ||||||
|             elif conf['HTTP_PORT'] == 3000: |             elif CONF['HTTP_PORT'] == 3000: | ||||||
|                 data['redirect_uri'] = "http://localhost:3000/token" |                 data['redirect_uri'] = "http://localhost:3000/token" | ||||||
|             else: |             else: | ||||||
|                 self.send_response(500) |                 self.send_response(500) | ||||||
|  | @ -1115,87 +1115,87 @@ def load_config(): | ||||||
|     for section in cfg: |     for section in cfg: | ||||||
|         try: |         try: | ||||||
|             logging.debug('Fetching config: %s', section) |             logging.debug('Fetching config: %s', section) | ||||||
|             conf['IRC_CHANNEL'] = cfg.get('irc', {}).get('channel', False) |             CONF['IRC_CHANNEL'] = cfg.get('irc', {}).get('channel', False) | ||||||
|             conf['IRC_USERNAME'] = cfg.get('irc', {}).get('username', False) |             CONF['IRC_USERNAME'] = cfg.get('irc', {}).get('username', False) | ||||||
|             conf['IRC_OAUTH_TOKEN'] = cfg.get('irc', {}).get('oauth_token', False) |             CONF['IRC_OAUTH_TOKEN'] = cfg.get('irc', {}).get('oauth_token', False) | ||||||
|             conf['IRC_SERVER'] = cfg.get('irc', {}).get('server', "irc.chat.twitch.tv") |             CONF['IRC_SERVER'] = cfg.get('irc', {}).get('server', "irc.chat.twitch.tv") | ||||||
|             conf['IRC_CLEARMSG_TIMEOUT'] = cfg.get('irc', {}).get('clearmsg_timeout', 60) |             CONF['IRC_CLEARMSG_TIMEOUT'] = cfg.get('irc', {}).get('clearmsg_timeout', 60) | ||||||
| 
 | 
 | ||||||
|             conf['IRC_SUBONLY'] = cfg.get('bot', {}).get('subonly', False) |             CONF['IRC_SUBONLY'] = cfg.get('bot', {}).get('subonly', False) | ||||||
|             conf['IRC_MODONLY'] = cfg.get('bot', {}).get('modonly', False) |             CONF['IRC_MODONLY'] = cfg.get('bot', {}).get('modonly', False) | ||||||
|             conf['IRC_TTS_LEN'] = cfg.get('bot', {}).get('message_length', 200) |             CONF['IRC_TTS_LEN'] = cfg.get('bot', {}).get('message_length', 200) | ||||||
|             conf['TTS_STARTENABLED'] = cfg.get('bot', {}).get('start_enabled', True) |             CONF['TTS_STARTENABLED'] = cfg.get('bot', {}).get('start_enabled', True) | ||||||
|             conf['WIKI_LANG'] = cfg.get('bot', {}).get('language', 'en') |             CONF['WIKI_LANG'] = cfg.get('bot', {}).get('language', 'en') | ||||||
| 
 | 
 | ||||||
|             conf['LOG_LEVEL'] = cfg.get('log', {}).get('level', "INFO") |             CONF['LOG_LEVEL'] = cfg.get('log', {}).get('level', "INFO") | ||||||
|             conf['HTTP_PORT'] = cfg.get('http', {}).get('port', 80) |             CONF['HTTP_PORT'] = cfg.get('http', {}).get('port', 80) | ||||||
|             conf['HTTP_BIND'] = cfg.get('http', {}).get('bind', "localhost") |             CONF['HTTP_BIND'] = cfg.get('http', {}).get('bind', "localhost") | ||||||
| 
 | 
 | ||||||
|             conf['MESSAGE'] = {} |             CONF['MESSAGE'] = {} | ||||||
|             conf['MESSAGE']['TOFF'] = cfg.get('messages', {}).get('toff', "TTS is now disabled.") |             CONF['MESSAGE']['TOFF'] = cfg.get('messages', {}).get('toff', "TTS is now disabled.") | ||||||
|             conf['MESSAGE']['TON'] = cfg.get('messages', {}).get('ton', "TTS is now active.") |             CONF['MESSAGE']['TON'] = cfg.get('messages', {}).get('ton', "TTS is now active.") | ||||||
|             conf['MESSAGE']['TOO_LONG'] = cfg.get('messages', {}).get('too_long', "Sorry, your message is too long.") |             CONF['MESSAGE']['TOO_LONG'] = cfg.get('messages', {}).get('too_long', "Sorry, your message is too long.") | ||||||
|             conf['MESSAGE']['DISABLED'] = cfg.get('messages', {}).get('disabled', "Sorry, TTS is disabled.") |             CONF['MESSAGE']['DISABLED'] = cfg.get('messages', {}).get('disabled', "Sorry, TTS is disabled.") | ||||||
|             conf['MESSAGE']['DENIED'] = cfg.get('messages', {}).get('denied', "Sorry, you're not allowed to use TTS.") |             CONF['MESSAGE']['DENIED'] = cfg.get('messages', {}).get('denied', "Sorry, you're not allowed to use TTS.") | ||||||
|             conf['MESSAGE']['SUBONLY'] = cfg.get('messages', {}).get('subonly', "Sorry, TTS is sub-only.") |             CONF['MESSAGE']['SUBONLY'] = cfg.get('messages', {}).get('subonly', "Sorry, TTS is sub-only.") | ||||||
|             conf['MESSAGE']['MODONLY'] = cfg.get('messages', {}).get('modonly', "Sorry, TTS is mod-only.") |             CONF['MESSAGE']['MODONLY'] = cfg.get('messages', {}).get('modonly', "Sorry, TTS is mod-only.") | ||||||
|             conf['MESSAGE']['READY'] = cfg.get('messages', {}).get('ready', "TTS bot is ready.") |             CONF['MESSAGE']['READY'] = cfg.get('messages', {}).get('ready', "TTS bot is ready.") | ||||||
|             conf['MESSAGE']['WHITELISTONLY'] = cfg.get('messages', {}).get('whitelist', False) |             CONF['MESSAGE']['WHITELISTONLY'] = cfg.get('messages', {}).get('whitelist', False) | ||||||
|             conf['MESSAGE']['SAYS'] = cfg.get('messages', {}).get('says', "says") |             CONF['MESSAGE']['SAYS'] = cfg.get('messages', {}).get('says', "says") | ||||||
| 
 | 
 | ||||||
|             conf['MESSAGE']['VOTESTART'] = cfg.get('messages', {}).get('votestart', "Quickvote started. Send #yourchoice to participate.") |             CONF['MESSAGE']['VOTESTART'] = cfg.get('messages', {}).get('votestart', "Quickvote started. Send #yourchoice to participate.") | ||||||
|             conf['MESSAGE']['VOTEEND'] = cfg.get('messages', {}).get('voteend', "Quickvote ended. The results are:") |             CONF['MESSAGE']['VOTEEND'] = cfg.get('messages', {}).get('voteend', "Quickvote ended. The results are:") | ||||||
|             conf['MESSAGE']['VOTENOBODY']  = cfg.get('messages', {}).get('votenobody', "Nobody casted a vote. :(") |             CONF['MESSAGE']['VOTENOBODY']  = cfg.get('messages', {}).get('votenobody', "Nobody casted a vote. :(") | ||||||
|             conf['MESSAGE']['VOTERESULT']  = cfg.get('messages', {}).get('voteresult', "Voting has ended. The result is:") |             CONF['MESSAGE']['VOTERESULT']  = cfg.get('messages', {}).get('voteresult', "Voting has ended. The result is:") | ||||||
|             conf['MESSAGE']['VOTES']  = cfg.get('messages', {}).get('votes', "Votes") |             CONF['MESSAGE']['VOTES']  = cfg.get('messages', {}).get('votes', "Votes") | ||||||
| 
 | 
 | ||||||
|             conf['MESSAGE']['PICKSTART'] = cfg.get('messages', {}).get('pickstart', "Pick started. Send #pickme to participate.") |             CONF['MESSAGE']['PICKSTART'] = cfg.get('messages', {}).get('pickstart', "Pick started. Send #pickme to participate.") | ||||||
|             conf['MESSAGE']['PICKRESULT'] = cfg.get('messages', {}).get('pickresult', "Pick ended. The results are:") |             CONF['MESSAGE']['PICKRESULT'] = cfg.get('messages', {}).get('pickresult', "Pick ended. The results are:") | ||||||
|             conf['MESSAGE']['PICKNONE'] = cfg.get('messages', {}).get('picknone', "Pick ended. Nobody was picked.") |             CONF['MESSAGE']['PICKNONE'] = cfg.get('messages', {}).get('picknone', "Pick ended. Nobody was picked.") | ||||||
| 
 | 
 | ||||||
|             conf['MESSAGE']['QUOTE_NOT_FOUND'] = cfg.get('messages', {}).get('quotenotfound', "Sorry, no quote found.") |             CONF['MESSAGE']['QUOTE_NOT_FOUND'] = cfg.get('messages', {}).get('quotenotfound', "Sorry, no quote found.") | ||||||
|             conf['MESSAGE']['QUOTE_ADDED_PREFIX'] = cfg.get('messages', {}).get('quoteaddedprefix', "Quote:") |             CONF['MESSAGE']['QUOTE_ADDED_PREFIX'] = cfg.get('messages', {}).get('quoteaddedprefix', "Quote:") | ||||||
|             conf['MESSAGE']['QUOTE_ADDED_SUFFIX'] = cfg.get('messages', {}).get('quoteaddedsuffix', "added.") |             CONF['MESSAGE']['QUOTE_ADDED_SUFFIX'] = cfg.get('messages', {}).get('quoteaddedsuffix', "added.") | ||||||
| 
 | 
 | ||||||
|             conf['MESSAGE']['WIKI_TOO_MANY'] = cfg.get('messages', {}).get('wiki_too_many', "Sorry, there are too many possible results. Try a more narrow search.") |             CONF['MESSAGE']['WIKI_TOO_MANY'] = cfg.get('messages', {}).get('wiki_too_many', "Sorry, there are too many possible results. Try a more narrow search.") | ||||||
|             conf['MESSAGE']['WIKI_NO_RESULT'] = cfg.get('messages', {}).get('wiki_no_result', "Sorry, there was an error fetching the wikipedia answer.") |             CONF['MESSAGE']['WIKI_NO_RESULT'] = cfg.get('messages', {}).get('wiki_no_result', "Sorry, there was an error fetching the wikipedia answer.") | ||||||
| 
 | 
 | ||||||
|             conf['FEATURE'] = {} |             CONF['FEATURE'] = {} | ||||||
|             conf['FEATURE']['WIKI'] = cfg.get('features', {}).get('wiki', True) |             CONF['FEATURE']['WIKI'] = cfg.get('features', {}).get('wiki', True) | ||||||
|             conf['FEATURE']['PICK'] = cfg.get('features', {}).get('pick', True) |             CONF['FEATURE']['PICK'] = cfg.get('features', {}).get('pick', True) | ||||||
|             conf['FEATURE']['VOTE'] = cfg.get('features', {}).get('vote', True) |             CONF['FEATURE']['VOTE'] = cfg.get('features', {}).get('vote', True) | ||||||
|             conf['FEATURE']['QUOTE'] = cfg.get('features', {}).get('quote', True) |             CONF['FEATURE']['QUOTE'] = cfg.get('features', {}).get('quote', True) | ||||||
|             conf['FEATURE']['RANDOM'] = cfg.get('features', {}).get('random', True) |             CONF['FEATURE']['RANDOM'] = cfg.get('features', {}).get('random', True) | ||||||
|             conf['FEATURE']['VERSION'] = cfg.get('features', {}).get('version', True) |             CONF['FEATURE']['VERSION'] = cfg.get('features', {}).get('version', True) | ||||||
|             conf['FEATURE']['PING'] = cfg.get('features', {}).get('ping', True) |             CONF['FEATURE']['PING'] = cfg.get('features', {}).get('ping', True) | ||||||
| 
 | 
 | ||||||
|             conf['USERMAP'] = cfg.get('usermapping', []) |             CONF['USERMAP'] = cfg.get('usermapping', []) | ||||||
| 
 | 
 | ||||||
|             if 'whitelist' in cfg: |             if 'whitelist' in cfg: | ||||||
|                 conf['WHITELIST'] = True |                 CONF['WHITELIST'] = True | ||||||
|                 conf['WHITELIST_USER'] = cfg['whitelist'] |                 CONF['WHITELIST_USER'] = cfg['whitelist'] | ||||||
|             else: |             else: | ||||||
|                 conf['WHITELIST'] = False |                 CONF['WHITELIST'] = False | ||||||
| 
 | 
 | ||||||
|         except KeyError: |         except KeyError: | ||||||
|             logging.exception('Your config file is invalid, please check and try again.') |             logging.exception('Your config file is invalid, please check and try again.') | ||||||
|             sys.exit(254) |             sys.exit(254) | ||||||
| 
 | 
 | ||||||
|     if conf['WHITELIST']: |     if CONF['WHITELIST']: | ||||||
|         logging.info('Whitelist mode enabled') |         logging.info('Whitelist mode enabled') | ||||||
|         logging.debug('Whitelist: %s', conf['WHITELIST_USER']) |         logging.debug('Whitelist: %s', CONF['WHITELIST_USER']) | ||||||
| 
 | 
 | ||||||
|     if not conf['IRC_CHANNEL']: |     if not CONF['IRC_CHANNEL']: | ||||||
|         raise ValueError('Please add your twitch channel to config.yml.') |         raise ValueError('Please add your twitch channel to config.yml.') | ||||||
|     if not conf['IRC_USERNAME']: |     if not CONF['IRC_USERNAME']: | ||||||
|         raise ValueError('Please add the bots username to config.yml.') |         raise ValueError('Please add the bots username to config.yml.') | ||||||
|     if not conf['IRC_OAUTH_TOKEN']: |     if not CONF['IRC_OAUTH_TOKEN']: | ||||||
|         conf['IRC_OAUTH_TOKEN'] = "Invalid" |         CONF['IRC_OAUTH_TOKEN'] = "Invalid" | ||||||
|         return conf |         return CONF | ||||||
|     if not conf['IRC_OAUTH_TOKEN'].startswith('oauth:'): |     if not CONF['IRC_OAUTH_TOKEN'].startswith('oauth:'): | ||||||
|         raise ValueError('Your oauth-token is invalid, it has to start with: "oauth:"') |         raise ValueError('Your oauth-token is invalid, it has to start with: "oauth:"') | ||||||
| 
 | 
 | ||||||
|     return conf |     return CONF | ||||||
| 
 | 
 | ||||||
| def send_tts_queue(): | def send_tts_queue(): | ||||||
|     """ Send messages to TTS """ |     """ Send messages to TTS """ | ||||||
|  | @ -1204,7 +1204,7 @@ def send_tts_queue(): | ||||||
|         logging.debug('Raw msg: %s', msg_queue_raw) |         logging.debug('Raw msg: %s', msg_queue_raw) | ||||||
| 
 | 
 | ||||||
|         now = datetime.datetime.now() |         now = datetime.datetime.now() | ||||||
|         if now - raw_msg['queuetime'] > datetime.timedelta(seconds=conf['IRC_CLEARMSG_TIMEOUT']): |         if now - raw_msg['queuetime'] > datetime.timedelta(seconds=CONF['IRC_CLEARMSG_TIMEOUT']): | ||||||
|             logging.debug('clearmsg_timeout reached') |             logging.debug('clearmsg_timeout reached') | ||||||
|             if raw_msg['timestamp'] not in msg_queue: |             if raw_msg['timestamp'] not in msg_queue: | ||||||
|                 logging.info('Sending TTS message') |                 logging.info('Sending TTS message') | ||||||
|  | @ -1215,12 +1215,12 @@ def send_tts_queue(): | ||||||
| 
 | 
 | ||||||
| def get_url(path=False): | def get_url(path=False): | ||||||
|     """ Generate a valid URL from config values """ |     """ Generate a valid URL from config values """ | ||||||
|     if conf['HTTP_BIND'] == "0.0.0.0": |     if CONF['HTTP_BIND'] == "0.0.0.0": | ||||||
|         url = "localhost" |         url = "localhost" | ||||||
|     else: |     else: | ||||||
|         url = conf['HTTP_BIND'] |         url = CONF['HTTP_BIND'] | ||||||
| 
 | 
 | ||||||
|     url = "http://"+str(url)+":"+str(conf['HTTP_PORT'])+"/" |     url = "http://"+str(url)+":"+str(CONF['HTTP_PORT'])+"/" | ||||||
| 
 | 
 | ||||||
|     if path: |     if path: | ||||||
|         url = url+str(path) |         url = url+str(path) | ||||||
|  | @ -1229,42 +1229,42 @@ def get_url(path=False): | ||||||
| 
 | 
 | ||||||
| def check_oauth_token(): | def check_oauth_token(): | ||||||
|     """ Check for valid authentication via Twitch API """ |     """ Check for valid authentication via Twitch API """ | ||||||
|     global conf # pylint: disable=global-statement,invalid-name |     global CONF # pylint: disable=global-statement | ||||||
|     logging.debug('Checking OAuth Token') |     logging.debug('Checking OAuth Token') | ||||||
| 
 | 
 | ||||||
|     try: |     try: | ||||||
|         url = 'https://id.twitch.tv/oauth2/validate' |         url = 'https://id.twitch.tv/oauth2/validate' | ||||||
|         oauth = "OAuth "+str(conf['IRC_OAUTH_TOKEN'].replace('oauth:','')) |         oauth = "OAuth "+str(CONF['IRC_OAUTH_TOKEN'].replace('oauth:','')) | ||||||
|         request = urllib.request.Request(url) |         request = urllib.request.Request(url) | ||||||
|         request.add_header('Authorization', oauth) |         request.add_header('Authorization', oauth) | ||||||
|         urllib.request.urlopen(request) |         urllib.request.urlopen(request) | ||||||
|     except HTTPError: |     except HTTPError: | ||||||
|         logging.fatal('Twitch rejected your OAuth Token. Please check and generate a new one.') |         logging.fatal('Twitch rejected your OAuth Token. Please check and generate a new one.') | ||||||
|         logging.info('Please open http://%s:%s/token to generate your OAuth-Token.', conf['HTTP_BIND'], conf['HTTP_PORT']) |         logging.info('Please open http://%s:%s/token to generate your OAuth-Token.', CONF['HTTP_BIND'], CONF['HTTP_PORT']) | ||||||
| 
 | 
 | ||||||
|         url = get_url("token") |         url = get_url("token") | ||||||
|         webbrowser.open_new_tab(url) |         webbrowser.open_new_tab(url) | ||||||
|         logging.info('Please complete the OAuth process and add the token into your "config.yml" within the next 5 minutes.') |         logging.info('Please complete the OAuth process and add the token into your "config.yml" within the next 5 minutes.') | ||||||
|         time.sleep(300) |         time.sleep(300) | ||||||
|         conf = load_config() |         CONF = load_config() | ||||||
|         check_oauth_token() |         check_oauth_token() | ||||||
| 
 | 
 | ||||||
|     logging.info('OAuth Token is valid') |     logging.info('OAuth Token is valid') | ||||||
|     return conf |     return CONF | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
|     """Main loop""" |     """Main loop""" | ||||||
| 
 | 
 | ||||||
|     global conf # pylint: disable=global-statement,invalid-name |     global CONF # pylint: disable=global-statement | ||||||
|     conf = load_config() |     CONF = load_config() | ||||||
| 
 | 
 | ||||||
|     lastreload = datetime.datetime.now() |     lastreload = datetime.datetime.now() | ||||||
|     logging.getLogger().setLevel(conf['LOG_LEVEL']) |     logging.getLogger().setLevel(CONF['LOG_LEVEL']) | ||||||
|     if conf['LOG_LEVEL'] == 'DEBUG': |     if CONF['LOG_LEVEL'] == 'DEBUG': | ||||||
|         sys.tracebacklimit = 5 |         sys.tracebacklimit = 5 | ||||||
| 
 | 
 | ||||||
|     logging.info("Starting Webserver") |     logging.info("Starting Webserver") | ||||||
|     httpd = ThreadingSimpleServer((conf['HTTP_BIND'], conf['HTTP_PORT']), HTTPserv) |     httpd = ThreadingSimpleServer((CONF['HTTP_BIND'], CONF['HTTP_PORT']), HTTPserv) | ||||||
| 
 | 
 | ||||||
|     http_thread = Thread(target=http_serve_forever, daemon=True, args=(httpd, )) |     http_thread = Thread(target=http_serve_forever, daemon=True, args=(httpd, )) | ||||||
|     http_thread.start() |     http_thread.start() | ||||||
|  | @ -1273,8 +1273,8 @@ def main(): | ||||||
|     logging.info("Starting IRC bot") |     logging.info("Starting IRC bot") | ||||||
|     irc = IRC() |     irc = IRC() | ||||||
| 
 | 
 | ||||||
|     irc.connect(conf['IRC_SERVER'], 6667, conf['IRC_CHANNEL'], conf['IRC_USERNAME'], conf['IRC_OAUTH_TOKEN']) |     irc.connect(CONF['IRC_SERVER'], 6667, CONF['IRC_CHANNEL'], CONF['IRC_USERNAME'], CONF['IRC_OAUTH_TOKEN']) | ||||||
|     irc.sendmsg(conf['IRC_CHANNEL'], 'MrDestructoid', conf['MESSAGE']['READY']) |     irc.sendmsg(CONF['IRC_CHANNEL'], 'MrDestructoid', CONF['MESSAGE']['READY']) | ||||||
| 
 | 
 | ||||||
|     logging.info('Connected and joined') |     logging.info('Connected and joined') | ||||||
|     url = get_url() |     url = get_url() | ||||||
|  | @ -1282,7 +1282,7 @@ def main(): | ||||||
|     webbrowser.open_new_tab(url) |     webbrowser.open_new_tab(url) | ||||||
| 
 | 
 | ||||||
|     while True: |     while True: | ||||||
|         if conf['LOG_LEVEL'] == "DEBUG": |         if CONF['LOG_LEVEL'] == "DEBUG": | ||||||
|             time.sleep(1) |             time.sleep(1) | ||||||
| 
 | 
 | ||||||
|         try: |         try: | ||||||
|  | @ -1290,12 +1290,12 @@ def main(): | ||||||
| 
 | 
 | ||||||
|             confreload = datetime.datetime.now() |             confreload = datetime.datetime.now() | ||||||
|             if confreload - lastreload > datetime.timedelta(seconds=60): |             if confreload - lastreload > datetime.timedelta(seconds=60): | ||||||
|                 conf = load_config() |                 CONF = load_config() | ||||||
|                 lastreload = datetime.datetime.now() |                 lastreload = datetime.datetime.now() | ||||||
| 
 | 
 | ||||||
|                 if irc.quickvote_status and irc.votemsg: |                 if irc.quickvote_status and irc.votemsg: | ||||||
|                     logging.info('Quickvote is active') |                     logging.info('Quickvote is active') | ||||||
|                     irc.sendmsg(conf['IRC_CHANNEL'], "@chat", conf['MESSAGE']['VOTESTART'] + " (" + str(irc.votemsg) + ")") |                     irc.sendmsg(CONF['IRC_CHANNEL'], "@chat", CONF['MESSAGE']['VOTESTART'] + " (" + str(irc.votemsg) + ")") | ||||||
| 
 | 
 | ||||||
|             if not irc.tts_status: |             if not irc.tts_status: | ||||||
|                 continue |                 continue | ||||||
|  | @ -1312,8 +1312,8 @@ if __name__ == "__main__": | ||||||
|     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 = 3 |     sys.tracebacklimit = 3 | ||||||
| 
 | 
 | ||||||
|     VERSION = "1.7.0" |     VERSION = "1.7.1" | ||||||
|     conf = {} |     CONF = {} | ||||||
|     tts_done = [] |     tts_done = [] | ||||||
|     msg_queue_raw = [] |     msg_queue_raw = [] | ||||||
|     msg_queue = {} |     msg_queue = {} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue