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
Adapt `config.yml` to your needs. Example:
Adapt `config.yml` to your needs. Please use `UTF-8` as encoding. Example:
``` lang=yaml
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
def tts(self, msg, tags):
""" !tts command
""" !tts command
Check if message is valid and send it to queue
:param str msg: The IRC message triggering the command
@ -813,7 +813,7 @@ def get_url(path=False):
url = "localhost"
else:
url = conf['HTTP_BIND']
url = "http://"+str(url)+":"+str(conf['HTTP_PORT'])+"/"
if path:
@ -821,17 +821,18 @@ def get_url(path=False):
return url
def check_oauth_token(conf):
def check_oauth_token():
""" Check for valid authentication via Twitch API """
global conf # pylint: disable=global-statement,invalid-name
logging.debug('Checking OAuth Token')
try:
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.add_header('Authorization', oauth)
urllib.request.urlopen(request)
except HTTPError:
conf['IRC_OAUTH_TOKEN'] == "Invalid"
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'])
@ -841,13 +842,14 @@ def check_oauth_token(conf):
time.sleep(300)
conf = load_config()
check_oauth_token()
logging.info('OAuth Token is valid \o/')
return
logging.info('OAuth Token is valid.')
return conf
def main():
"""Main loop"""
global conf # pylint: disable=global-statement,invalid-name
conf = load_config()
lastreload = datetime.datetime.now()
@ -862,7 +864,7 @@ def main():
http_thread = Thread(target=http_serve_forever, daemon=True, args=(httpd, ))
http_thread.start()
check_oauth_token(conf)
check_oauth_token()
logging.info("Starting IRC bot")
irc = IRC()
@ -901,15 +903,14 @@ def main():
sys.exit()
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(module)s %(threadName)s %(levelname)s: %(message)s')
sys.tracebacklimit = 3
conf = {}
tts_done = []
msg_queue_raw = []
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] == "--version":
print('Simple TTS Bot')