add force command

This commit is contained in:
Amazed 2020-10-30 18:36:51 +01:00
parent b8eb2f600e
commit 5573bb2bed

View File

@ -20,6 +20,7 @@ class WynncraftCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.config = Config.get_conf(self, identifier=48775419874)
self.last_status = {}
default_guild = {
"role_guild_member": 758458266195198003,
"role_guild": {
@ -464,10 +465,13 @@ class WynncraftCog(commands.Cog):
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"):
@commands.command()
@checks.admin_or_permissions(manage_guild=True)
async def force(self, ctx):
await self.do_loop()
await ctx.send("OK!")
async def do_loop(self):
await self._log("Looping guilds")
for guild in self.bot.guilds:
roles_combat_level = await self.config.guild(guild).role_levels()
@ -498,25 +502,25 @@ class WynncraftCog(commands.Cog):
await self._log("%s had empty data %s" % (member_name, r["data"]))
continue
for cl in r["data"][0]["classes"]:
if guild_id not in last_status:
last_status[guild_id] = {}
if guild_id not in self.last_status:
self.last_status[guild_id] = {}
if member_name not in last_status[guild_id]:
last_status[guild_id][member_name] = {}
if member_name not in self.last_status[guild_id]:
self.last_status[guild_id][member_name] = {}
if cl["name"] not in last_status[guild_id][member_name]:
last_status[guild_id][member_name][cl["name"]] = cl
if cl["name"] not in self.last_status[guild_id][member_name]:
self.last_status[guild_id][member_name][cl["name"]] = cl
# ping level up
ping_channel_id = await self.config.guild(guild).ping_channel()
if await self.config.guild(guild).ping_levels() and ping_channel_id:
await self._log("Checking for level up")
if cl["professions"]["combat"]["level"] > last_status[guild_id][member_name][cl["name"]]["professions"]["combat"]["level"]:
if cl["professions"]["combat"]["level"] > self.last_status[guild_id][member_name][cl["name"]]["professions"]["combat"]["level"]:
ping_channel = self.bot.get_channel(ping_channel_id)
await ping_channel.send(":high_brightness: %s a level up au niveau %s! GG!" % (member_name, cl["professions"]["combat"]["level"]))
else:
await self._log("Player %s had last level %s and current %s" % (member_name, last_status[guild_id][member_name][cl["name"]]["professions"]["combat"]["level"], cl["professions"]["combat"]["level"]))
last_status[guild_id][member_name][cl["name"]] = cl
await self._log("Player %s had last level %s and current %s" % (member_name, self.last_status[guild_id][member_name][cl["name"]]["professions"]["combat"]["level"], cl["professions"]["combat"]["level"]))
self.last_status[guild_id][member_name][cl["name"]] = cl
# get max_combat_lvl_class
if not max_combat_lvl_class or cl["professions"]["combat"]["level"] > max_combat_lvl_class["professions"]["combat"]["level"]:
@ -664,4 +668,9 @@ class WynncraftCog(commands.Cog):
except:
if await self.config.log():
traceback.print_exc()
async def loop(self):
await self.bot.wait_until_ready()
while self is self.bot.get_cog("WynncraftCog"):
await self.do_loop()
await asyncio.sleep(3600)