- Added automatic reconnect after refreshing Twitch bot token.
- Added reattempt limit to prevent Twitch ratelimiting.kami_dev
parent
095514d95d
commit
a83e27c7ed
|
@ -120,15 +120,23 @@ class TwitchBot(commands.Bot):
|
||||||
"""
|
"""
|
||||||
Run the Twitch bot, refreshing tokens if needed.
|
Run the Twitch bot, refreshing tokens if needed.
|
||||||
"""
|
"""
|
||||||
try:
|
retries = 0
|
||||||
await self.start()
|
while True:
|
||||||
#while True:
|
if retries > 3:
|
||||||
# await self.refresh_access_token()
|
self.log(f"Twitch bot failed to connect after {retries} attempts.", "CIRITCAL")
|
||||||
# await asyncio.sleep(10800) # Refresh every 3 hours
|
break # Break loop if repeatedly failing to connect to Twitch
|
||||||
except Exception as e:
|
try:
|
||||||
self.log(f"Twitch bot failed to start: {e}", "CRITICAL")
|
await self.start()
|
||||||
if "Invalid or unauthorized Access Token passed." in str(e):
|
#while True:
|
||||||
try:
|
# await self.refresh_access_token()
|
||||||
await self.refresh_access_token()
|
# await asyncio.sleep(10800) # Refresh every 3 hours
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log(f"Unable to refresh Twitch token! Twitch bot will be offline!", "CRITICAL")
|
retries += 1
|
||||||
|
self.log(f"Twitch bot failed to start: {e}", "CRITICAL")
|
||||||
|
if "Invalid or unauthorized Access Token passed." in str(e):
|
||||||
|
try:
|
||||||
|
await self.refresh_access_token()
|
||||||
|
except Exception as e:
|
||||||
|
self.log(f"Unable to refresh Twitch token! Twitch bot will be offline!", "CRITICAL")
|
||||||
|
await asyncio.sleep(5) # Wait before retrying to authenticate
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue