added !perso command

This commit is contained in:
Amazed 2020-11-19 19:58:18 +01:00
parent 669167b402
commit 969de00cbc
1 changed files with 47 additions and 4 deletions

View File

@ -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):