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

4
other_ext/stats_presence.py

@ -17,6 +17,10 @@ class Extension:
async def updater(self): async def updater(self):
try: 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(): if not self.core.stats['servers'].values():
print("Stats not be loaded") print("Stats not be loaded")
return return

Loading…
Cancel
Save