11import asyncio
2- from datetime import datetime , timezone
2+ from datetime import datetime
33from typing import Literal
44import discord
55from discord .enums import InteractionType
@@ -20,15 +20,13 @@ class ErrorCodes:
2020 INVALID_API_TOKEN = "Invalid API token, please get one at " + ApiEndpoints .BASE_URL .split ("/api" )[0 ] + " and try again."
2121 DATA_NOT_SENT = "Data cannot be sent to the API, I will try again in a minute."
2222 SUSPENDED_BOT = "Your bot has been suspended, please check your mailbox for more information."
23- INSTANCE_NOT_INITIALIZED = "It seem that you didn't initialize your instance. Please check the docs for more informations."
2423 INVALID_EVENTS_COUNT = "invalid events count"
2524
2625class DiscordAnalytics ():
2726 def __init__ (self , client : discord .Client , api_key : str , debug : bool = False , chunk_guilds_at_startup : bool = True ):
2827 self .client = client
2928 self .api_key = api_key
3029 self .debug = debug
31- self .is_ready = False
3230 self .chunk_guilds = chunk_guilds_at_startup
3331 self .headers = {
3432 "Content-Type" : "application/json" ,
@@ -85,6 +83,7 @@ async def init(self):
8583 if not self .client .is_ready ():
8684 raise ValueError (ErrorCodes .CLIENT_NOT_READY )
8785
86+ # Proceed with initialization, API calls, etc.
8887 async with aiohttp .ClientSession () as session :
8988 async with session .patch (
9089 ApiEndpoints .BOT_URL .replace (":id" , str (self .client .user .id )),
@@ -105,7 +104,6 @@ async def init(self):
105104
106105 if self .debug :
107106 print ("[DISCORDANALYTICS] Instance successfully initialized" )
108- self .is_ready = True
109107
110108 if self .debug :
111109 if "--dev" in sys .argv :
@@ -187,7 +185,8 @@ async def send_stats(self):
187185 }
188186 }
189187
190- await asyncio .sleep (10 if "--dev" in sys .argv else 300 )
188+ # await asyncio.sleep(10 if "--dev" in sys.argv else 300)
189+ await asyncio .sleep (10 )
191190
192191 def calculate_guild_members_repartition (self ):
193192 result = {
@@ -212,8 +211,9 @@ def calculate_guild_members_repartition(self):
212211 def track_interactions (self , interaction : discord .Interaction ):
213212 if self .debug :
214213 print ("[DISCORDANALYTICS] Track interactions triggered" )
215- if not self .is_ready :
216- raise ValueError (ErrorCodes .INSTANCE_NOT_INITIALIZED )
214+
215+ if not self .client .is_ready ():
216+ raise ValueError (ErrorCodes .CLIENT_NOT_READY )
217217
218218 locale = next ((x for x in self .stats ["locales" ] if x ["locale" ] == interaction .locale .value ), None )
219219 if locale is not None :
0 commit comments