This commit is contained in:
Amazed 2020-08-31 20:06:55 +02:00
parent 4549d65116
commit b2f03cb54b

View File

@ -55,12 +55,16 @@ class WynncraftCog(commands.Cog):
await self.bot.wait_until_ready() await self.bot.wait_until_ready()
last_status = {} last_status = {}
while self is self.bot.get_cog("WynncraftCog"): while self is self.bot.get_cog("WynncraftCog"):
print("Looping guilds")
async for guild in self.bot.fetch_guilds(limit=150): async for guild in self.bot.fetch_guilds(limit=150):
guild_id = guild.id guild_id = guild.id
print("Loop id %s" % guild_id)
try: try:
channel_id = await self.config.guild(guild).channel() channel_id = await self.config.guild(guild).channel()
if channel_id: if channel_id:
print("Channel set")
for tracked in await self.config.guild(guild).tracked(): for tracked in await self.config.guild(guild).tracked():
print("calling API for player %s" % tracked)
r = requests.get("https://api.wynncraft.com/v2/player/%s/stats" % tracked).json() r = requests.get("https://api.wynncraft.com/v2/player/%s/stats" % tracked).json()
for cl in r["data"][0]["classes"]: for cl in r["data"][0]["classes"]:
if guild_id not in last_status: if guild_id not in last_status:
@ -75,8 +79,12 @@ class WynncraftCog(commands.Cog):
if cl["professions"]["combat"]["level"] > last_status[guild_id][tracked][cl["name"]]["professions"]["combat"]["level"]: if cl["professions"]["combat"]["level"] > last_status[guild_id][tracked][cl["name"]]["professions"]["combat"]["level"]:
channel = self.bot.get_channel(channel_id) channel = self.bot.get_channel(channel_id)
await channel.send(":high_brightness: %s a level up au niveau %s! GG!" % (tracked, cl["professions"]["combat"]["level"])) await channel.send(":high_brightness: %s a level up au niveau %s! GG!" % (tracked, cl["professions"]["combat"]["level"]))
else:
print("Player %s had last level %s and current %s" % (tracked, last_status[guild_id][tracked][cl["name"]]["professions"]["combat"]["level"], cl["professions"]["combat"]["level"]))
last_status[guild_id][tracked][cl["name"]] = cl last_status[guild_id][tracked][cl["name"]] = cl
else:
print("Guild has no channel set")
except: except:
traceback.print_exc() traceback.print_exc()
await asyncio.sleep(30) await asyncio.sleep(30)