From 969de00cbceaa30f0a580829e87a799fcc3cc7f3 Mon Sep 17 00:00:00 2001 From: Hipstercat Date: Thu, 19 Nov 2020 19:58:18 +0100 Subject: [PATCH] added !perso command --- cogs/wynncraft/wynncraftcog.py | 51 +++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/cogs/wynncraft/wynncraftcog.py b/cogs/wynncraft/wynncraftcog.py index 44206b5..3ee9597 100644 --- a/cogs/wynncraft/wynncraftcog.py +++ b/cogs/wynncraft/wynncraftcog.py @@ -22,6 +22,7 @@ class WynncraftCog(commands.Cog): self.config = Config.get_conf(self, identifier=48775419874) self.last_status = {} default_guild = { + "persos": {}, "role_guild_member": 758458266195198003, "role_guild": { "RECRUIT": 743544640052920332, @@ -307,10 +308,22 @@ class WynncraftCog(commands.Cog): if not req["data"]: await ctx.send(":x: impossible de t'aider, je ne te trouve pas sur Wynncraft :(") return + + persos = await self.config.guild(ctx.guild).persos() max_class = None - for cl in req["data"][0]["classes"]: - if not max_class or max_class["professions"]["combat"]["level"] < cl["professions"]["combat"]["level"]: - max_class = cl + if ctx.author.id in persos: + wanted_class = persos[ctx.author.id] + for cl in req["data"][0]["classes"]: + if cl["name"] == wanted_class: + max_class = cl + break + if not max_class: + await ctx.send(":x: impossible de t'aider, je ne trouve plus ton perso sur Wynncraft :(\nUtilise la commande `!perso` pour changer ton perso !") + return + else: + for cl in req["data"][0]["classes"]: + if not max_class or max_class["professions"]["combat"]["level"] < cl["professions"]["combat"]["level"]: + max_class = cl if not max_class: await ctx.send(":x: impossible de t'aider, je ne te trouve pas ta classe sur Wynncraft :(") @@ -357,7 +370,7 @@ class WynncraftCog(commands.Cog): break if hints: - await ctx.send(":dizzy: Woosh! Voici comment tu peux continuer ton aventure :\n\n\t%s" % "\n\t".join(hints)) + await ctx.send(":dizzy: Woosh! Voici comment tu peux continuer ton aventure :\n\n\t%s\n\n*Tu peux changer de perso avec la commande `!perso` !*" % "\n\t".join(hints)) else: await ctx.send(":x: Si tu lis ce message c'est que quelque chose s'est mal passé car il est normalement impossible que je ne puisse pas te donner de conseils ! Contacte <@158370947097821185> pour l'informer de ce bug.") @@ -420,6 +433,36 @@ class WynncraftCog(commands.Cog): else: await ctx.send(":x:") + @commands.command() + async def perso(self, ctx, class_str: str = None): + persos = await self.config.guild(ctx.guild).persos() + if not class_str: + if ctx.author.id in persos: + await ctx.send(":white_check_mark: Ton perso défini est : %s" % persos[ctx.author.id]) + return + else: + await ctx.send(":x: Tu n'as pas de perso défini, ton perso sera donc ton plus haut level !") + return + player_name = ctx.author.display_name + req = requests.get("https://api.wynncraft.com/v2/player/%s/stats" % player_name).json() + if not req["data"]: + await ctx.send(":x: impossible de t'aider, je ne te trouve pas sur Wynncraft :(") + return + + valid = False + for cl in req["data"][0]["classes"]: + if cl["name"] == class_str: + valid = True + break + + if not valid: + await ctx.send(":x: ce perso n'existe pas :(") + return + + persos[ctx.author.id] = class_str + await self.config.guild(ctx.guild).persos.set(persos) + await ctx.send(":white_check_mark: Ton perso est désormais %s !" % class_str) + @commands.command() @checks.admin_or_permissions(manage_guild=True) async def set_guild(self, ctx, guild_name):