Minor changes

This commit is contained in:
gpkvt 2022-08-15 20:36:11 +02:00
parent fa4e28a1ff
commit ab9ae82984
3 changed files with 15 additions and 15 deletions

View File

@ -32,7 +32,7 @@ By using Javascript for the actual TTS part it's not only very easy to access th
### Configuration ### Configuration
Adapt `config.yml` to your needs. Example: Adapt `config.yml` to your needs. Please use `UTF-8` as encoding. Example:
``` lang=yaml ``` lang=yaml
irc: irc:

1
bootstrap.min.css vendored

File diff suppressed because one or more lines are too long

27
tts.py
View File

@ -382,8 +382,8 @@ class IRC:
self.pollcount = self.pollcount self.pollcount = self.pollcount
def tts(self, msg, tags): def tts(self, msg, tags):
""" !tts command """ !tts command
Check if message is valid and send it to queue Check if message is valid and send it to queue
:param str msg: The IRC message triggering the command :param str msg: The IRC message triggering the command
@ -813,7 +813,7 @@ def get_url(path=False):
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:
@ -821,17 +821,18 @@ def get_url(path=False):
return url return url
def check_oauth_token(conf): 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
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 %s" % 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:
conf['IRC_OAUTH_TOKEN'] == "Invalid"
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'])
@ -841,13 +842,14 @@ def check_oauth_token(conf):
time.sleep(300) time.sleep(300)
conf = load_config() conf = load_config()
check_oauth_token() check_oauth_token()
logging.info('OAuth Token is valid \o/') logging.info('OAuth Token is valid.')
return return conf
def main(): def main():
"""Main loop""" """Main loop"""
global conf # pylint: disable=global-statement,invalid-name
conf = load_config() conf = load_config()
lastreload = datetime.datetime.now() lastreload = datetime.datetime.now()
@ -862,7 +864,7 @@ def main():
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()
check_oauth_token(conf) check_oauth_token()
logging.info("Starting IRC bot") logging.info("Starting IRC bot")
irc = IRC() irc = IRC()
@ -901,15 +903,14 @@ def main():
sys.exit() sys.exit()
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(module)s %(threadName)s %(levelname)s: %(message)s')
sys.tracebacklimit = 3
conf = {} conf = {}
tts_done = [] tts_done = []
msg_queue_raw = [] msg_queue_raw = []
msg_queue = {} msg_queue = {}
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(module)s %(threadName)s %(levelname)s: %(message)s')
sys.tracebacklimit = 3
if sys.argv[1:]: if sys.argv[1:]:
if sys.argv[1] == "--version": if sys.argv[1] == "--version":
print('Simple TTS Bot') print('Simple TTS Bot')