- 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.
|
||||
"""
|
||||
retries = 0
|
||||
while True:
|
||||
if retries > 3:
|
||||
self.log(f"Twitch bot failed to connect after {retries} attempts.", "CIRITCAL")
|
||||
break # Break loop if repeatedly failing to connect to Twitch
|
||||
try:
|
||||
await self.start()
|
||||
#while True:
|
||||
# await self.refresh_access_token()
|
||||
# await asyncio.sleep(10800) # Refresh every 3 hours
|
||||
except Exception as e:
|
||||
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