configure verbose (fix)

This commit is contained in:
Amazed 2020-08-31 20:26:35 +02:00
parent 0b05407ea0
commit 3082061cae

View File

@ -68,7 +68,7 @@ class WynncraftCog(commands.Cog):
else: else:
await ctx.send(":x:") await ctx.send(":x:")
def _log(self, s): async def _log(self, s):
if await self.config.log(): if await self.config.log():
print(s) print(s)
@ -76,16 +76,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"):
self._log("Looping guilds") await self._log("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
self._log("Loop id %s" % guild_id) await self._log("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:
self._log("Channel set") await self._log("Channel set")
for tracked in await self.config.guild(guild).tracked(): for tracked in await self.config.guild(guild).tracked():
self._log("calling API for player %s" % tracked) await self._log("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:
@ -101,11 +101,11 @@ class WynncraftCog(commands.Cog):
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: else:
self._log("Player %s had last level %s and current %s" % (tracked, last_status[guild_id][tracked][cl["name"]]["professions"]["combat"]["level"], cl["professions"]["combat"]["level"])) await self._log("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: else:
self._log("Guild has no channel set") await self._log("Guild has no channel set")
except: except:
if await self.config.log(): if await self.config.log():
traceback.print_exc() traceback.print_exc()