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:
await ctx.send(":x:")
def _log(self, s):
async def _log(self, s):
if await self.config.log():
print(s)
@ -76,16 +76,16 @@ class WynncraftCog(commands.Cog):
await self.bot.wait_until_ready()
last_status = {}
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):
guild_id = guild.id
self._log("Loop id %s" % guild_id)
await self._log("Loop id %s" % guild_id)
try:
channel_id = await self.config.guild(guild).channel()
if channel_id:
self._log("Channel set")
await self._log("Channel set")
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()
for cl in r["data"][0]["classes"]:
if guild_id not in last_status:
@ -101,11 +101,11 @@ class WynncraftCog(commands.Cog):
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"]))
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
else:
self._log("Guild has no channel set")
await self._log("Guild has no channel set")
except:
if await self.config.log():
traceback.print_exc()