Browse Source

qwerty huy

huy
gsd 2 years ago
parent
commit
7a09a93a7e
  1. 14
      bot.py
  2. 4
      other_ext/stats_presence.py

14
bot.py

@ -23,6 +23,7 @@ class DiscordClient(commands.Bot):
stats = {}
show_stats_prev = 0
loaded_extensions = {}
api_down = True
def __init__(self, backend_url, secret_key):
self.backend_url = backend_url
@ -57,6 +58,8 @@ class DiscordClient(commands.Bot):
await self.tree.sync(guild=discord.Object(self.main_server_id))
await self.tree.sync()
await self.core.wait_until_ready()
print(f"[init] check exts for have prepairs")
for ext_name, ext in self.loaded_extensions.items():
if getattr(ext, "prepair", None):
@ -137,9 +140,14 @@ class DiscordClient(commands.Bot):
return player
async def GetStats(self):
async with aiohttp.ClientSession() as session:
async with session.get(f"{os.getenv('BACKEND_URL')}/api/stats", ssl=False) as response:
self.stats = await response.json()
try:
async with aiohttp.ClientSession() as session:
async with session.get(f"{os.getenv('BACKEND_URL')}/api/stats", ssl=False) as response:
self.stats = await response.json()
self.api_down = False
except Exception as e:
self.api_down = True
raise e
return self.stats
def GetServersChoice(self):

4
other_ext/stats_presence.py

@ -17,6 +17,10 @@ class Extension:
async def updater(self):
try:
if self.core.api_down:
act = discord.Activity(type=discord.ActivityType.watching, name = f"API DOWN")
return await self.core.change_presence(activity=act)
if not self.core.stats['servers'].values():
print("Stats not be loaded")
return

Loading…
Cancel
Save