configure verbose
This commit is contained in:
parent
b2f03cb54b
commit
0b05407ea0
@ -14,7 +14,11 @@ class WynncraftCog(commands.Cog):
|
||||
"tracked": [],
|
||||
"channel": None
|
||||
}
|
||||
default_global = {
|
||||
"log": True
|
||||
}
|
||||
self.config.register_guild(**default_guild)
|
||||
self.config.register_global(**default_global)
|
||||
|
||||
@commands.command()
|
||||
@checks.admin_or_permissions(manage_guild=True)
|
||||
@ -51,20 +55,37 @@ class WynncraftCog(commands.Cog):
|
||||
await self.config.guild(ctx.guild).channel.set(i)
|
||||
await ctx.send("Les messages seront désormais envoyés dans %s" % channel.mention)
|
||||
|
||||
@commands.command()
|
||||
@checks.is_owner()
|
||||
async def log(self, ctx, state):
|
||||
state = state.lower()
|
||||
if state == "true" or state == "on":
|
||||
await self.config.log.set(True)
|
||||
await ctx.send(":white_check_mark:")
|
||||
elif state == "false" or state == "off":
|
||||
await self.config.log.set(False)
|
||||
await ctx.send(":white_check_mark:")
|
||||
else:
|
||||
await ctx.send(":x:")
|
||||
|
||||
def _log(self, s):
|
||||
if await self.config.log():
|
||||
print(s)
|
||||
|
||||
async def loop(self):
|
||||
await self.bot.wait_until_ready()
|
||||
last_status = {}
|
||||
while self is self.bot.get_cog("WynncraftCog"):
|
||||
print("Looping guilds")
|
||||
self._log("Looping guilds")
|
||||
async for guild in self.bot.fetch_guilds(limit=150):
|
||||
guild_id = guild.id
|
||||
print("Loop id %s" % guild_id)
|
||||
self._log("Loop id %s" % guild_id)
|
||||
try:
|
||||
channel_id = await self.config.guild(guild).channel()
|
||||
if channel_id:
|
||||
print("Channel set")
|
||||
self._log("Channel set")
|
||||
for tracked in await self.config.guild(guild).tracked():
|
||||
print("calling API for player %s" % tracked)
|
||||
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:
|
||||
@ -80,11 +101,12 @@ 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:
|
||||
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"]))
|
||||
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:
|
||||
print("Guild has no channel set")
|
||||
self._log("Guild has no channel set")
|
||||
except:
|
||||
traceback.print_exc()
|
||||
if await self.config.log():
|
||||
traceback.print_exc()
|
||||
await asyncio.sleep(30)
|
||||
|
Loading…
Reference in New Issue
Block a user