From b1f2e3ad39269c02a0f840ba80b5f4f4c7743857 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 28 May 2021 14:03:34 +0200 Subject: [PATCH 01/17] adding test cog for new slash commands --- requirements.txt | 1 + src/cogs/slash.py | 17 +++++++++++++++++ src/main.py | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 src/cogs/slash.py diff --git a/requirements.txt b/requirements.txt index 920fa85..2b3444a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ asyncpraw==7.2.0 # reddit youtube-dl==2021.4.26 # music lyricsgenius==3.0.1 # lyrics feedparser==6.0.2 # rss feed (news) +discord-py-slash-command==1.2.0 # slash commands diff --git a/src/cogs/slash.py b/src/cogs/slash.py new file mode 100644 index 0000000..ec5c133 --- /dev/null +++ b/src/cogs/slash.py @@ -0,0 +1,17 @@ +import discord +from discord.ext import commands +from discord_slash import cog_ext, SlashContext + +def setup(client): + client.add_cog(Slash(client)) + +class Slash(commands.Cog): + """Slash commands test.""" + + def __init__(self, client): + self.client = client + + @cog_ext.cog_slash(name="test") + async def _test(self, ctx: SlashContext): + embed = discord.Embed(title="embed test") + await ctx.send(content="test", embeds=[embed]) diff --git a/src/main.py b/src/main.py index 4db72ee..fdf7a32 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ print("Chargement des extensions & librairie...", end = " ") import discord, re, pytz, os +from discord_slash import SlashCommand from discord.ext import commands from random import choice from datetime import datetime @@ -9,6 +10,7 @@ customPrefix = os.environ['PREFIX'] customTimezone = os.environ['TIMEZONE'] client = commands.Bot(command_prefix = customPrefix, case_insensitive = True, intents = discord.Intents.all()) +slash = SlashCommand(client, sync_commands = True, sync_on_cog_reload = True) client.load_extension("cogs.help") client.load_extension("cogs.utils") @@ -18,6 +20,7 @@ client.load_extension("cogs.games") client.load_extension("cogs.fun") client.load_extension("cogs.autopublish") client.load_extension("cogs.school") +client.load_extension("cogs.slash") print("Terminé !") @client.event From 80963051210fd8995e9d1b6e5c0deb829b041165 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 28 May 2021 14:10:05 +0200 Subject: [PATCH 02/17] adding ping command for the slash test --- src/cogs/slash.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cogs/slash.py b/src/cogs/slash.py index ec5c133..7bee9a4 100644 --- a/src/cogs/slash.py +++ b/src/cogs/slash.py @@ -1,4 +1,5 @@ import discord +import time from discord.ext import commands from discord_slash import cog_ext, SlashContext @@ -11,7 +12,12 @@ class Slash(commands.Cog): def __init__(self, client): self.client = client - @cog_ext.cog_slash(name="test") - async def _test(self, ctx: SlashContext): - embed = discord.Embed(title="embed test") - await ctx.send(content="test", embeds=[embed]) + @cog_ext.cog_slash(name="pingSlash", description = "Affiche mon ping.") + async def _pingSlash(self, ctx: SlashContext): + now = int(round(time.time() * 1000)) + ping = now - int(round(ctx.message.created_at.timestamp() * 1000)) + embed = discord.Embed(description = 'Pinging...') + message = await ctx.send(embed = embed) + ping2 = int(round(time.time() * 1000)) - now + await message.edit(embed = discord.Embed(color = discord.Colour.random(), description = f':hourglass: {round(self.client.latency * 1000)} ms\n\n:stopwatch: {ping2} ms\n\n:heartbeat: {ping} ms')) + await ctx.message.add_reaction(emoji = '✅') From 414c4352f10c299a3566f56da26daf58d75e06fa Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 28 May 2021 17:52:23 +0200 Subject: [PATCH 03/17] update how to add the bot with the right perms --- README.md | 6 +++--- src/cogs/slash.py | 15 ++++----------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 02f9149..ac54f5a 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ To find reddit tokens, go to [this site](https://www.reddit.com/prefs/apps) and ## __Add the bot to your server__ -- [This site](https://discordapi.com/permissions.html) allows you to choose which permissions to add by default to the bot. - - Choose *Administrator* so you don't get in over your head. - - Copy and paste the ID of your bot in *Client ID* found [here](https://discord.com/developers/applications) and go to the link at the bottom of the page. +- In the [Discord Dev Portal](https://discord.com/developers/applications) create an application, and make sure it's a `Bot` (third tab). +- To invite it, go to the `OAuth2` (second tab) tab, select the scopes `bot` (required) and `applications.commands` (for the slashs commands) and in the bot permissions select `Administrator` (You can select manually at your own risk). +- You have the link above between the two blocks scope and permissions ## __Features__ diff --git a/src/cogs/slash.py b/src/cogs/slash.py index 7bee9a4..ad0795a 100644 --- a/src/cogs/slash.py +++ b/src/cogs/slash.py @@ -1,5 +1,4 @@ -import discord -import time + from discord.ext import commands from discord_slash import cog_ext, SlashContext @@ -12,12 +11,6 @@ class Slash(commands.Cog): def __init__(self, client): self.client = client - @cog_ext.cog_slash(name="pingSlash", description = "Affiche mon ping.") - async def _pingSlash(self, ctx: SlashContext): - now = int(round(time.time() * 1000)) - ping = now - int(round(ctx.message.created_at.timestamp() * 1000)) - embed = discord.Embed(description = 'Pinging...') - message = await ctx.send(embed = embed) - ping2 = int(round(time.time() * 1000)) - now - await message.edit(embed = discord.Embed(color = discord.Colour.random(), description = f':hourglass: {round(self.client.latency * 1000)} ms\n\n:stopwatch: {ping2} ms\n\n:heartbeat: {ping} ms')) - await ctx.message.add_reaction(emoji = '✅') + @cog_ext.cog_slash(name="pingg") + async def pingg(self, ctx: SlashContext): + await ctx.send(content="Pong!") From ed2d7b9a2e9bc97fd927ecebffae2a643c4e7ed2 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 28 May 2021 19:59:31 +0200 Subject: [PATCH 04/17] adding first true command who support the slash --- src/cogs/fun.py | 13 +++++++++---- src/cogs/slash.py | 16 ---------------- src/main.py | 1 - 3 files changed, 9 insertions(+), 21 deletions(-) delete mode 100644 src/cogs/slash.py diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 37f5b59..85b143b 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -2,6 +2,7 @@ import discord, re from discord.ext import commands from random import randint, choice from datetime import timedelta +from discord_slash import cog_ext, SlashContext def setup(client): client.add_cog(Fun(client)) @@ -92,8 +93,8 @@ class Fun(commands.Cog): await ctx.send(str(error).replace('Member "', "Le membre **").replace('" not found', "** n'as pas été trouvé.")) @commands.command(name='8ball', aliases=['8b', '8balls']) - async def _8ball(self, ctx, *, question): - """Répond à ta question 🔮.\n ➡ Syntaxe: {PREFIX}8ball/8b ⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" + async def _8ball(self, ctx): + """Répond à ta question 🔮.\n ➡ Syntaxe: {PREFIX}8ball/8b⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" reponses=["c'est sûr.","il en est décidément ainsi.","incontestablement.","oui sans aucun doute.","tu peux t'y fier.","tel que je le vois, oui.","c'est le plus probable.", "cela montre de bonnes perspectives.","certes.","les signes indiquent que oui.","ma réponse est oui.","ta question est trop floue, réessaie.","redemandes plus tard stp.", "je ferais mieux de pas te le dire maintenant...","je ne peux pas le prédire actuellement :/","concentre-toi et redemande.","n'y comptes pas trop.","ma réponse est non.", @@ -105,10 +106,14 @@ class Fun(commands.Cog): await ctx.send(f"Mauvaise syntaxe : `{ctx.prefix}8ball/8b/8balls `.") @commands.command(name='pileouface', aliases=['pf']) - async def _pileouface(self, ctx): + async def _pileouface(self, ctx, fromSlash = False): """Pile ou face.\n ➡ Syntaxe: {PREFIX}pileouface/pf""" - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') return await ctx.send(f"{'Pile' if randint(0,1) == 1 else 'Face'} !") + @cog_ext.cog_slash(name="pileouface", description = "Pile ou face.") + async def __pileouface(self, ctx: SlashContext): + await self._pileouface(ctx, True) @commands.command(name='mock') async def _mock(self, ctx): diff --git a/src/cogs/slash.py b/src/cogs/slash.py deleted file mode 100644 index ad0795a..0000000 --- a/src/cogs/slash.py +++ /dev/null @@ -1,16 +0,0 @@ - -from discord.ext import commands -from discord_slash import cog_ext, SlashContext - -def setup(client): - client.add_cog(Slash(client)) - -class Slash(commands.Cog): - """Slash commands test.""" - - def __init__(self, client): - self.client = client - - @cog_ext.cog_slash(name="pingg") - async def pingg(self, ctx: SlashContext): - await ctx.send(content="Pong!") diff --git a/src/main.py b/src/main.py index fdf7a32..8a71588 100644 --- a/src/main.py +++ b/src/main.py @@ -20,7 +20,6 @@ client.load_extension("cogs.games") client.load_extension("cogs.fun") client.load_extension("cogs.autopublish") client.load_extension("cogs.school") -client.load_extension("cogs.slash") print("Terminé !") @client.event From 4226c1758e3869ea4110b63eb984380aa0f5c470 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 28 May 2021 21:22:43 +0200 Subject: [PATCH 05/17] adding the iq function in the slashs commands --- src/cogs/fun.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 85b143b..75bd2b4 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -14,31 +14,42 @@ class Fun(commands.Cog): self.client = client @commands.command(name='iq') - async def _iq(self, ctx, *, user = '0'): - """Calcule ton IQ.\n ➡ Syntaxe: {PREFIX}iq [user]⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" - if user == '0': + async def _iq(self, ctx, *user): + """Calcule ton QI.\n ➡ Syntaxe: {PREFIX}iq [user]⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" + fromSlash = False + if user[-1] == True: + fromSlash = user[-1] + user = user[:-1] + if len(user) == 0: user = ctx.author - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') return await ctx.send(f"T'as {randint(randint(-100,0),220)} IQ {user.mention} !") else: + user = user[0] try: user2 = user user2 = user2[2:-1] user2 = user2.replace("!","") user2 = int(user2) user2 = self.client.get_user(user2) - KassouBot = self.client.get_user(740140888373854269) - if user2.id == KassouBot.id: - await ctx.message.add_reaction(emoji = '✅') - return await ctx.send(f"Bah... pas ouf... j'ai juste 100000 IQ :/") + if user2.id == self.client.user.id: + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + return await ctx.send(f"Bah... pas ouf... j'ai juste 100000 de QI :/") else: - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') message = await ctx.send("...") - return await message.edit(content = f"{user2.mention} a {randint(randint(-100,0),220)} IQ !") + return await message.edit(content = f"{user2.mention} a {randint(randint(-100,0),220)} de QI !") except: - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') message = await ctx.send("...") - return await message.edit(content = f"{user} a {randint(randint(-100,0),220)} IQ !") + return await message.edit(content = f"{user} a {randint(randint(-100,0),220)} de QI !") + @cog_ext.cog_slash(name="iq", description = "Calcule ton QI.") + async def __iq(self, ctx, user = ()): + await self._iq(ctx, user, True) @commands.command(name='love') async def _love(self, ctx, *users: discord.Member): @@ -112,7 +123,7 @@ class Fun(commands.Cog): await ctx.message.add_reaction(emoji = '✅') return await ctx.send(f"{'Pile' if randint(0,1) == 1 else 'Face'} !") @cog_ext.cog_slash(name="pileouface", description = "Pile ou face.") - async def __pileouface(self, ctx: SlashContext): + async def __pileouface(self, ctx): await self._pileouface(ctx, True) @commands.command(name='mock') From 2a2fd806744e99d2ae174d443fa368c1e4b0b2bd Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 28 May 2021 21:30:55 +0200 Subject: [PATCH 06/17] fix slash command for the iq --- src/cogs/fun.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 75bd2b4..ef2bf41 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -17,9 +17,13 @@ class Fun(commands.Cog): async def _iq(self, ctx, *user): """Calcule ton QI.\n ➡ Syntaxe: {PREFIX}iq [user]⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" fromSlash = False - if user[-1] == True: - fromSlash = user[-1] - user = user[:-1] + if len(user) > 0: + if user[-1] == True: + fromSlash = user[-1] + user = user[:-1] + if len(user) > 0: + if user[0] == None: + user = user[1:] if len(user) == 0: user = ctx.author if fromSlash != True: @@ -48,7 +52,7 @@ class Fun(commands.Cog): message = await ctx.send("...") return await message.edit(content = f"{user} a {randint(randint(-100,0),220)} de QI !") @cog_ext.cog_slash(name="iq", description = "Calcule ton QI.") - async def __iq(self, ctx, user = ()): + async def __iq(self, ctx, user = None): await self._iq(ctx, user, True) @commands.command(name='love') From 5ce54afa6e247216001908ab7a497608eadf20d5 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 28 May 2021 23:11:07 +0200 Subject: [PATCH 07/17] all available commands in fun cogs added to slash commands --- src/cogs/fun.py | 57 +++++++++++++++++++++++++++++------------------ src/cogs/games.py | 12 ++++++++++ 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/cogs/fun.py b/src/cogs/fun.py index ef2bf41..e4d3be5 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -2,7 +2,7 @@ import discord, re from discord.ext import commands from random import randint, choice from datetime import timedelta -from discord_slash import cog_ext, SlashContext +from discord_slash import cog_ext def setup(client): client.add_cog(Fun(client)) @@ -21,9 +21,6 @@ class Fun(commands.Cog): if user[-1] == True: fromSlash = user[-1] user = user[:-1] - if len(user) > 0: - if user[0] == None: - user = user[1:] if len(user) == 0: user = ctx.author if fromSlash != True: @@ -53,11 +50,19 @@ class Fun(commands.Cog): return await message.edit(content = f"{user} a {randint(randint(-100,0),220)} de QI !") @cog_ext.cog_slash(name="iq", description = "Calcule ton QI.") async def __iq(self, ctx, user = None): - await self._iq(ctx, user, True) + if user == None: + return await self._iq(ctx, True) + else: + return await self._iq(ctx, user, True) @commands.command(name='love') async def _love(self, ctx, *users: discord.Member): """Découvre la probabilité que ces deux personnes se mettent en couple.\n ➡ Syntaxe: {PREFIX}love """ + fromSlash = False + if len(users) > 0: + if users[-1] == True: + fromSlash = users[-1] + users = users[:-1] if len(users) == 2 or len(users) == 1: UneDemande = False if len(users) == 1: @@ -67,7 +72,8 @@ class Fun(commands.Cog): users.append(ctx.author) UneDemande = True if users[0] == users[1]: - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') return await ctx.send("Je suis sûr que cette personne s'aime ! :angry:") if users[0].nick: user1 = list(users[0].nick) @@ -86,16 +92,19 @@ class Fun(commands.Cog): else: taille_du_pls_grand = len(user2_CALC) taille_du_ms_grand = len(user1_CALC) - coef_amour = round(float(len(list(set(user1_CALC).intersection(user2_CALC))) / taille_du_pls_grand),1) * 100 + ((taille_du_pls_grand-taille_du_ms_grand) * 1.5) * 1.7 + coef_amour = round(float(len(list(set(user1_CALC).intersection(user2_CALC))) / taille_du_pls_grand), 1) * 100 + ((taille_du_pls_grand-taille_du_ms_grand) * 1.5) * 1.7 if coef_amour > 100: coef_amour = 100 if UneDemande == True: - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') return await ctx.send(f"Tu as {coef_amour}% de chance de te mettre en couple avec {''.join(user1)}") - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') await ctx.send(f"{''.join(user1)} et {''.join(user2)} ont {coef_amour}% de chance de se mettre en couple !") else: - await ctx.message.add_reaction(emoji = '❌') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '❌') await ctx.send(f"Erreur! Syntaxe : `{ctx.prefix}love [User2]`\n") def _retirerDoublons(self, liste): Newliste = [] @@ -106,29 +115,33 @@ class Fun(commands.Cog): @_love.error async def _love_error(self, ctx, error): await ctx.send(str(error).replace('Member "', "Le membre **").replace('" not found', "** n'as pas été trouvé.")) + @cog_ext.cog_slash(name="love", description = "Découvre la probabilité que ces deux personnes se mettent en couple.") + async def __love(self, ctx, user1 = None, user2 = None): + if user1 != None: + if user2 != None: + return await self._love(ctx, user1, user2, True) + else: + return await self._love(ctx, user1, True) + else: + return await self._love(ctx, True) @commands.command(name='8ball', aliases=['8b', '8balls']) - async def _8ball(self, ctx): + async def _8ball(self, ctx, fromSlash = False): """Répond à ta question 🔮.\n ➡ Syntaxe: {PREFIX}8ball/8b⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" reponses=["c'est sûr.","il en est décidément ainsi.","incontestablement.","oui sans aucun doute.","tu peux t'y fier.","tel que je le vois, oui.","c'est le plus probable.", "cela montre de bonnes perspectives.","certes.","les signes indiquent que oui.","ma réponse est oui.","ta question est trop floue, réessaie.","redemandes plus tard stp.", "je ferais mieux de pas te le dire maintenant...","je ne peux pas le prédire actuellement :/","concentre-toi et redemande.","n'y comptes pas trop.","ma réponse est non.", "mes sources disent que non.", "les perspectives ne sont pas si bonnes...","c'est très douteux."] - await ctx.send(f"{ctx.author.mention}, {choice(reponses)}") + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + return await ctx.send(f"{ctx.author.mention}, {choice(reponses)}") @_8ball.error async def _8ball_error(self, ctx, error): if str(error) == "question is a required argument that is missing.": await ctx.send(f"Mauvaise syntaxe : `{ctx.prefix}8ball/8b/8balls `.") - - @commands.command(name='pileouface', aliases=['pf']) - async def _pileouface(self, ctx, fromSlash = False): - """Pile ou face.\n ➡ Syntaxe: {PREFIX}pileouface/pf""" - if fromSlash != True: - await ctx.message.add_reaction(emoji = '✅') - return await ctx.send(f"{'Pile' if randint(0,1) == 1 else 'Face'} !") - @cog_ext.cog_slash(name="pileouface", description = "Pile ou face.") - async def __pileouface(self, ctx): - await self._pileouface(ctx, True) + @cog_ext.cog_slash(name="8ball", description = "Répond à ta question 🔮.") + async def __8ball(self, ctx): + await self._8ball(ctx, True) @commands.command(name='mock') async def _mock(self, ctx): diff --git a/src/cogs/games.py b/src/cogs/games.py index e7f49f6..6f7cda8 100644 --- a/src/cogs/games.py +++ b/src/cogs/games.py @@ -2,6 +2,7 @@ import discord from discord.ext import commands from random import randint, choice import asyncio +from discord_slash import cog_ext def setup(client): client.add_cog(Games(client)) @@ -91,3 +92,14 @@ class Games(commands.Cog): await ctx.send(f"Erreur dans la réponse {ctx.author.mention}, merci de n'écrire qu'un nombre. Tapez `stop` pour arrêter le jeu.") del self.guessing_game[str(ctx.author.id)] await ctx.send(f"T'as pas trouvé {ctx.author.mention}... dommage, c'était {number}.") + + + @commands.command(name='pileouface', aliases=['pf']) + async def _pileouface(self, ctx, fromSlash = False): + """Pile ou face.\n ➡ Syntaxe: {PREFIX}pileouface/pf""" + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + return await ctx.send(f"{'Pile' if randint(0,1) == 1 else 'Face'} !") + @cog_ext.cog_slash(name="pileouface", description = "Pile ou face.") + async def __pileouface(self, ctx): + await self._pileouface(ctx, True) From 4b25f756f7733cd3e1ba6a0984f309c302927be0 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 28 May 2021 23:44:52 +0200 Subject: [PATCH 08/17] fixing errors in slash commands --- src/cogs/fun.py | 13 +++++-------- src/cogs/games.py | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/cogs/fun.py b/src/cogs/fun.py index e4d3be5..8b52dc9 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -116,14 +116,11 @@ class Fun(commands.Cog): async def _love_error(self, ctx, error): await ctx.send(str(error).replace('Member "', "Le membre **").replace('" not found', "** n'as pas été trouvé.")) @cog_ext.cog_slash(name="love", description = "Découvre la probabilité que ces deux personnes se mettent en couple.") - async def __love(self, ctx, user1 = None, user2 = None): - if user1 != None: - if user2 != None: - return await self._love(ctx, user1, user2, True) - else: - return await self._love(ctx, user1, True) + async def __love(self, ctx, user1: discord.Member, user2: discord.Member = None): + if user2 != None: + return await self._love(ctx, user1, user2, True) else: - return await self._love(ctx, True) + return await self._love(ctx, user1, True) @commands.command(name='8ball', aliases=['8b', '8balls']) async def _8ball(self, ctx, fromSlash = False): @@ -140,7 +137,7 @@ class Fun(commands.Cog): if str(error) == "question is a required argument that is missing.": await ctx.send(f"Mauvaise syntaxe : `{ctx.prefix}8ball/8b/8balls `.") @cog_ext.cog_slash(name="8ball", description = "Répond à ta question 🔮.") - async def __8ball(self, ctx): + async def __8ball(self, ctx, question): await self._8ball(ctx, True) @commands.command(name='mock') diff --git a/src/cogs/games.py b/src/cogs/games.py index 6f7cda8..8897886 100644 --- a/src/cogs/games.py +++ b/src/cogs/games.py @@ -15,8 +15,14 @@ class Games(commands.Cog): self.guessing_game = {} @commands.command(name='chifumi', aliases = ["shifumi", "ppc"]) - async def _chifumi(self, ctx, *, choix): + async def _chifumi(self, ctx, *choix): """Un simple Chifumi contre le bot.\n ➡ Syntaxe: {PREFIX}chifumi/shifumi/ppc """ + fromSlash = False + if len(choix) < 1: + raise ModuleNotFoundError + if choix[-1] == True: + fromSlash = choix[-1] + choix = choix[0] choix_jeu = ["Pierre ✊", "Papier 🧻", "Ciseaux ✂"] orditxt = choice(choix_jeu) @@ -39,12 +45,15 @@ class Games(commands.Cog): embed = discord.Embed(title = f"{choix_jeu[choix][-1:]}VS {choix_jeu[ordi][-1:]}", description = description) embed.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url) - await ctx.send(embed = embed) - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + return await ctx.send(embed = embed) @_chifumi.error async def _chifumi_error(self, ctx, error): await ctx.send(f"Mauvaise syntaxe : `{ctx.prefix}chifumi/shifumi/ppc `.") - + @cog_ext.cog_slash(name="chifumi", description = "Un simple Chifumi contre le bot.") + async def __chifumi(self, ctx, choix): + return await self._chifumi(ctx, choix, True) @commands.command(name='plusoumoins', aliases = ['+ou-', '+-']) async def _plusoumoins(self, ctx): @@ -93,7 +102,6 @@ class Games(commands.Cog): del self.guessing_game[str(ctx.author.id)] await ctx.send(f"T'as pas trouvé {ctx.author.mention}... dommage, c'était {number}.") - @commands.command(name='pileouface', aliases=['pf']) async def _pileouface(self, ctx, fromSlash = False): """Pile ou face.\n ➡ Syntaxe: {PREFIX}pileouface/pf""" From c9737bb115c206358f28e1ab046c0ae6aca2b157 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 29 May 2021 00:04:58 +0200 Subject: [PATCH 09/17] =?UTF-8?q?ajout=20pr=C3=A9cision=20dans=20le=20slas?= =?UTF-8?q?h=20du=20chifumi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cogs/games.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/games.py b/src/cogs/games.py index 8897886..95d7bdf 100644 --- a/src/cogs/games.py +++ b/src/cogs/games.py @@ -51,7 +51,7 @@ class Games(commands.Cog): @_chifumi.error async def _chifumi_error(self, ctx, error): await ctx.send(f"Mauvaise syntaxe : `{ctx.prefix}chifumi/shifumi/ppc `.") - @cog_ext.cog_slash(name="chifumi", description = "Un simple Chifumi contre le bot.") + @cog_ext.cog_slash(name="chifumi", description = "Un simple Chifumi contre le bot. ") async def __chifumi(self, ctx, choix): return await self._chifumi(ctx, choix, True) From 463b0080d48919e0b872c56b2703e4ece121b061 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 29 May 2021 00:20:12 +0200 Subject: [PATCH 10/17] adding available commands in internet cogs to slash commands --- src/cogs/internet.py | 59 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/src/cogs/internet.py b/src/cogs/internet.py index 6bf9dd0..af7c2e7 100644 --- a/src/cogs/internet.py +++ b/src/cogs/internet.py @@ -2,6 +2,7 @@ import discord, json, requests, time, feedparser, os from discord.ext import commands from random import choice from asyncpraw import Reddit +from discord_slash import cog_ext def setup(client): client.add_cog(Internet(client)) @@ -9,7 +10,6 @@ def setup(client): class Internet(commands.Cog): """Commandes relatives à ce qui provient d'internet.""" - def __init__(self, client): self.client = client @@ -31,8 +31,17 @@ class Internet(commands.Cog): await self._cat(await self.client.get_context(message)) @commands.command(name='memes', aliases = ['meme']) - async def _memes(self, ctx, *, args = None): + async def _memes(self, ctx, *args): """Envois un meme de reddit.\n ➡ Syntaxe: {PREFIX}memes/meme [subreddit]⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" + fromSlash = False + if len(args) > 0: + if args[-1] == True: + fromSlash = args[-1] + args = args[:-1] + if len(args) > 0: + args = args[0] + else: + args = None if args: # s'il y a un subreddit de défini subredditchoix = args @@ -58,7 +67,8 @@ class Internet(commands.Cog): else: await ctx.send(f"```r/{subredditchoix} pour {ctx.author.name}```\n{submission.url}") message = await ctx.send("```Meme de Reddit```") - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') await message.add_reaction('👍') return await message.add_reaction('👎') @@ -66,6 +76,13 @@ class Internet(commands.Cog): print(f"Error in _memes command = args: {args}, subreddit: {subredditchoix}, error: {error}") await ctx.message.add_reaction(emoji = '❌') return await ctx.send(f"Ce subreddit est interdit, mis en quarantaine ou n'existe pas. ({subredditchoix})") + @cog_ext.cog_slash(name="meme", description = "Envois un meme de reddit.") + async def __memes(self, ctx, subreddit = None): + if subreddit == None: + return await self._memes(ctx, True) + else: + return await self._memes(ctx, subreddit, True) + def _random_image(self, link): temps_requete = int(round(time.time() * 1000)) @@ -86,7 +103,7 @@ class Internet(commands.Cog): return (json_data, temps_requete) @commands.command(name='cat', aliases = ['chat']) - async def _cat(self, ctx): + async def _cat(self, ctx, fromSlash = False): """Te montre un magnifique chat\n ➡ Syntaxe: {PREFIX}cat/chat""" if ctx.author.nick: @@ -97,12 +114,16 @@ class Internet(commands.Cog): cat = self._random_image("http://aws.random.cat/meow") embed.set_image(url = cat[0]['file']) embed.set_footer(text = f"random.cat a pris {cat[1]} ms.") - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') message = await ctx.send(embed=embed) return await message.add_reaction('❤️') + @cog_ext.cog_slash(name="cat", description = "Te montre un magnifique chat") + async def __cat(self, ctx): + return await self._cat(ctx, True) @commands.command(name='dog', aliases = ['chien']) - async def _dog(self, ctx): + async def _dog(self, ctx, fromSlash = False): """Te montre un magnifique chien\n ➡ Syntaxe: {PREFIX}dog/chien""" if ctx.author.nick: @@ -113,9 +134,13 @@ class Internet(commands.Cog): dog = self._random_image("https://dog.ceo/api/breeds/image/random") embed.set_image(url = dog[0]['message']) embed.set_footer(text = f"dog.ceo a pris {dog[1]} ms.") - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') message = await ctx.send(embed=embed) return await message.add_reaction('❤️') + @cog_ext.cog_slash(name="dog", description = "Te montre un magnifique chien") + async def __dog(self, ctx): + return await self._dog(ctx, True) @commands.command(name='sexe', aliases=['sexes', 'nude', 'nudes', 'nsfw']) async def _sexe(self, ctx, *, choice_of_nsfw = None): @@ -137,8 +162,17 @@ class Internet(commands.Cog): await ctx.send(f"Désolé mais je n'envois ce genre de message seulement dans les salons NSFW !") @commands.command(name='news', aliases=['rss']) - async def _news(self, ctx, *, arg = ""): + async def _news(self, ctx, *arg): """Info random dans le domaine de l'informatique\n ➡ Syntaxe: {PREFIX}news/rss [site/liste]""" + fromSlash = False + if len(arg) > 0: + if arg[-1] == True: + fromSlash = arg[-1] + arg = arg[:-1] + if len(arg) > 0: + arg = arg[0] + else: + arg = "" rss_website = { "anandtech": "https://www.anandtech.com/rss/", @@ -180,4 +214,11 @@ class Internet(commands.Cog): pass embed.set_footer(text = f"News de {choix_site.capitalize()}") await ctx.send(embed = embed) - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + @cog_ext.cog_slash(name="news", description = "Info random dans le domaine de l'informatique, met commme arg liste pour la liste des sources dispo.") + async def __news(self, ctx, source = None): + if source == None: + return await self._news(ctx, True) + else: + return await self._news(ctx, source, True) From ca12edc1e24acaf918d7c9a1ecb09883529c6816 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 29 May 2021 12:31:51 +0200 Subject: [PATCH 11/17] adding link to my discord --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ac54f5a..d91a93a 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ To find reddit tokens, go to [this site](https://www.reddit.com/prefs/apps) and - In the [Discord Dev Portal](https://discord.com/developers/applications) create an application, and make sure it's a `Bot` (third tab). - To invite it, go to the `OAuth2` (second tab) tab, select the scopes `bot` (required) and `applications.commands` (for the slashs commands) and in the bot permissions select `Administrator` (You can select manually at your own risk). - You have the link above between the two blocks scope and permissions +- If you need help, you can [join my Discord](https://discord.gg/Z5ePxH4) ## __Features__ From 673377404e87118089058c4ca1b01302be8df7e5 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 29 May 2021 12:50:18 +0200 Subject: [PATCH 12/17] adding all school commands to slash --- src/cogs/school.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/cogs/school.py b/src/cogs/school.py index 8cf7260..5b41c15 100644 --- a/src/cogs/school.py +++ b/src/cogs/school.py @@ -1,5 +1,6 @@ import discord from discord.ext import commands +from discord_slash import cog_ext def setup(client): client.add_cog(School(client)) @@ -12,13 +13,26 @@ class School(commands.Cog): @commands.command(name='appel') # @commands.has_any_role("Professeur", "professeur", "Prof", "prof") - async def _appel(self, ctx, *, voice_channel: int = None): + async def _appel(self, ctx, *voice_channel: int): """Fais l'appel.⁢⁢⁢⁢⁢\n ➡ Syntaxe: {PREFIX}appel [ID salon vocal]""" + fromSlash = False + if len(voice_channel) > 0: + if voice_channel[-1] == True: + fromSlash = voice_channel[-1] + voice_channel = voice_channel[:-1] + if len(voice_channel) > 0: + voice_channel = voice_channel[0] + else: + voice_channel = None + voice_channels = [] voice_channels.extend(ctx.guild.voice_channels) - await ctx.message.add_reaction(emoji = "✅") + if fromSlash != True: + await ctx.message.add_reaction(emoji = "✅") limite_voice_channels = 7 if len(voice_channels) > limite_voice_channels and not voice_channel: + if fromSlash == True: + ctx.prefix = "/" return await ctx.send(f"""Désolé mais il y a plus de {limite_voice_channels} salons vocaux sur ce serveur, utilisez plutôt `{ctx.prefix}appel {{ID salon vocal}}`. \nPour savoir comment récuperer l'id d'un salon vous pouvez faire `{ctx.prefix}getid`.""") if voice_channel: @@ -52,8 +66,19 @@ class School(commands.Cog): # await ctx.send("Tu n'as pas la permission de faire cette commande, demande à un professeur.") # else: await ctx.send(f"Une erreur est survenue, syntaxe: `{ctx.prefix}appel [ID salon vocal]`.") + @cog_ext.cog_slash(name="appel", description = "Fais l'appel.") + async def __appel(self, ctx, voice_channel: int = None): + if voice_channel == None: + return await self._appel(ctx, True) + else: + return await self._appel(ctx, voice_channel, True) @commands.command(name='getid', hidden = True) - async def _getid(self, ctx): - await ctx.message.add_reaction(emoji = '✅') + async def _getid(self, ctx, fromSlash): + """Tuto vidéo sur comment récupérer l'ID d'un utilisateur/salon⁢⁢⁢⁢⁢""" + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') return await ctx.send("Explication sur comment récuperer l'ID d'un utilisateur/salon : https://cdn.discordapp.com/attachments/640312926892195842/780802253258358834/GetID.mp4") + @cog_ext.cog_slash(name="getid", description = "Tuto vidéo sur comment récupérer l'ID d'un utilisateur/salon⁢⁢⁢⁢⁢") + async def __getid(self, ctx): + return await self._getid(ctx, True) From 9eeb286ff63f47be2c44ad8fe5f5f1f5a6625916 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 29 May 2021 12:50:55 +0200 Subject: [PATCH 13/17] useless sync on reload removed bc we never unload cogs --- src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 8a71588..033f7f0 100644 --- a/src/main.py +++ b/src/main.py @@ -10,7 +10,7 @@ customPrefix = os.environ['PREFIX'] customTimezone = os.environ['TIMEZONE'] client = commands.Bot(command_prefix = customPrefix, case_insensitive = True, intents = discord.Intents.all()) -slash = SlashCommand(client, sync_commands = True, sync_on_cog_reload = True) +slash = SlashCommand(client, sync_commands = True) client.load_extension("cogs.help") client.load_extension("cogs.utils") From 637b7209a75ba3c6ee4fa00823158be832ee7e93 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 29 May 2021 13:25:02 +0200 Subject: [PATCH 14/17] fix appel slash command --- src/cogs/school.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cogs/school.py b/src/cogs/school.py index 5b41c15..1df8604 100644 --- a/src/cogs/school.py +++ b/src/cogs/school.py @@ -67,11 +67,14 @@ class School(commands.Cog): # else: await ctx.send(f"Une erreur est survenue, syntaxe: `{ctx.prefix}appel [ID salon vocal]`.") @cog_ext.cog_slash(name="appel", description = "Fais l'appel.") - async def __appel(self, ctx, voice_channel: int = None): - if voice_channel == None: + async def __appel(self, ctx, voice_channel_id = None): + if voice_channel_id == None: return await self._appel(ctx, True) else: - return await self._appel(ctx, voice_channel, True) + try: + return await self._appel(ctx, int(voice_channel_id), True) + except: + pass @commands.command(name='getid', hidden = True) async def _getid(self, ctx, fromSlash): From 08eba4e42e398f9d2d9d266bccb59dc6f77c7b0a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 30 May 2021 13:11:00 +0200 Subject: [PATCH 15/17] fix get id + better prefix location + appel command fix --- src/cogs/school.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cogs/school.py b/src/cogs/school.py index 1df8604..8a53dd4 100644 --- a/src/cogs/school.py +++ b/src/cogs/school.py @@ -31,8 +31,6 @@ class School(commands.Cog): await ctx.message.add_reaction(emoji = "✅") limite_voice_channels = 7 if len(voice_channels) > limite_voice_channels and not voice_channel: - if fromSlash == True: - ctx.prefix = "/" return await ctx.send(f"""Désolé mais il y a plus de {limite_voice_channels} salons vocaux sur ce serveur, utilisez plutôt `{ctx.prefix}appel {{ID salon vocal}}`. \nPour savoir comment récuperer l'id d'un salon vous pouvez faire `{ctx.prefix}getid`.""") if voice_channel: @@ -42,7 +40,7 @@ class School(commands.Cog): else: return await ctx.send("Tu as spécifié un channel textuelle et non vocal.") if len(voice_channels) > 0: - embed = discord.Embed(title = "Réagissez à ce message avec ✋ pour signaler votre présence.", description = f"(attention, je réagis aussi) — Professeur : {ctx.author.mention}") + embed = discord.Embed(title = "Réagissez à ce message avec ✋ pour signaler votre présence.", description = f"(attention, je réagis aussi) — Demandeur : {ctx.author.mention}") for channel in voice_channels: prof = [] for role in ["Professeur", "professeur", "Prof", "prof"]: @@ -68,6 +66,7 @@ class School(commands.Cog): await ctx.send(f"Une erreur est survenue, syntaxe: `{ctx.prefix}appel [ID salon vocal]`.") @cog_ext.cog_slash(name="appel", description = "Fais l'appel.") async def __appel(self, ctx, voice_channel_id = None): + ctx.prefix = "/" if voice_channel_id == None: return await self._appel(ctx, True) else: @@ -77,7 +76,7 @@ class School(commands.Cog): pass @commands.command(name='getid', hidden = True) - async def _getid(self, ctx, fromSlash): + async def _getid(self, ctx, fromSlash = False): """Tuto vidéo sur comment récupérer l'ID d'un utilisateur/salon⁢⁢⁢⁢⁢""" if fromSlash != True: await ctx.message.add_reaction(emoji = '✅') From 049ba85627f63aa0e496ee226a0c368902fbdeb0 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 30 May 2021 13:20:43 +0200 Subject: [PATCH 16/17] =?UTF-8?q?support=20des=20commandes=20slash=20pour?= =?UTF-8?q?=20la=20cat=C3=A9gorie=20cogs=20compatible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cogs/utils.py | 250 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 188 insertions(+), 62 deletions(-) diff --git a/src/cogs/utils.py b/src/cogs/utils.py index 5b8bab3..b5d7c7b 100644 --- a/src/cogs/utils.py +++ b/src/cogs/utils.py @@ -4,6 +4,8 @@ from random import randint, shuffle from datetime import datetime from pytz import timezone import re, asyncio +from discord_slash import cog_ext +import shlex def setup(client): client.add_cog(Utils(client)) @@ -31,22 +33,49 @@ class Utils(commands.Cog): await ctx.message.add_reaction(emoji = '✅') @commands.command(name='avatar') - async def _avatar(self, ctx, *, user = '0'): + async def _avatar(self, ctx, *user): """Affiche ton avatar ou celui que tu mentionnes.\n ➡ Syntaxe: {PREFIX}avatar [user]""" - if user == '0': + fromSlash = False + if len(user) > 0: + if user[-1] == True: + fromSlash = user[-1] + user = user[:-1] + if len(user) > 0: + user = user[0] + else: + user = None + + if user == None: user = ctx.author else: user = self.client.get_user(int(user[2:-1].replace("!",""))) - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') embed = discord.Embed(description = f"[lien vers la photo de profil]({user.avatar_url}) de {user.mention}", color = discord.Colour.random()) embed.set_author(name = f"Photo de profil de {user.name}") embed.set_image(url = user.avatar_url) await ctx.send(embed = embed) + @cog_ext.cog_slash(name="avatar", description = "Affiche ton avatar ou celui que tu mentionnes.") + async def __avatar(self, ctx, user = None): + if user == None: + return await self._avatar(ctx, True) + else: + return await self._avatar(ctx, user, True) @commands.command(name='calc') - async def _calc(self, ctx, *, msg): + async def _calc(self, ctx, *calcul): """Calculatrice.\n ➡ Syntaxe: {PREFIX}calc ⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" - equation = msg.replace('^', '**').replace('x', '*').replace('×', '*').replace('÷', '/').replace('≥', '>=').replace('≤', '<=') + fromSlash = False + if len(calcul) > 0: + if calcul[-1] == True: + fromSlash = calcul[-1] + calcul = calcul[:-1] + if len(calcul) > 0: + calcul = calcul[0] + else: + raise ModuleNotFoundError + + equation = calcul.replace('^', '**').replace('x', '*').replace('×', '*').replace('÷', '/').replace('≥', '>=').replace('≤', '<=') try: try: if '=' in equation: @@ -79,14 +108,18 @@ class Utils(commands.Cog): embed.add_field(name = 'Calcul :', value = equation, inline = False) embed.add_field(name = 'Réponse :', value = answer.replace('False', 'Faux').replace('True', 'Vrai'), inline = False) - await ctx.message.add_reaction(emoji = '✅') - await ctx.send(content = None, embed = embed) + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + await ctx.send(embed = embed) @_calc.error async def _calc_error(self, ctx, error): await ctx.send("Tu n'as pas spécifié de calcul.") + @cog_ext.cog_slash(name="calc", description = "Calculatrice.") + async def __calc(self, ctx, calcul): + return await self._calc(ctx, calcul, True) @commands.command(name='syntax') - async def _syntax(self, ctx): + async def _syntax(self, ctx, fromSlash = False): """Informations pour bien éditer son texte.⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" syntaxe = "-----------------------------------------------------\n" syntaxe += discord.utils.escape_markdown("```Js\n") @@ -128,32 +161,52 @@ class Utils(commands.Cog): syntaxe += "-----------------------------------------------------\n" syntaxe += discord.utils.escape_markdown(">>> cette ligne est cité\ncelle là aussi (et elles le seront toutes!)\n") syntaxe += ">>> cette ligne est cité\ncelle là aussi (et elles le seront toutes!)\n" - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') await ctx.send(syntaxe) + @cog_ext.cog_slash(name="syntax", description = "Informations pour bien éditer son texte.") + async def __syntax(self, ctx): + return await self._syntax(ctx, True) @commands.command(name='memo', aliases = ['note']) - async def _memo(self, ctx, *, text): + async def _memo(self, ctx, *text): """T'envoie un petit memo par message privé.\n ➡ Syntaxe: {PREFIX}memo/note ⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" + fromSlash = False + if len(text) > 0: + if text[-1] == True: + fromSlash = text[-1] + text = text[:-1] + if len(text) > 0: + text = " ".join(text) + else: + raise ModuleNotFoundError + if len(text) <= 5: - await ctx.message.add_reaction(emoji = '❌') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '❌') return await ctx.send("Ta note doit au moins faire 5 caractères.") elif len(text) >= 2048: - await ctx.message.add_reaction(emoji = '❌') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '❌') return await ctx.send("Ta note doit faire moins de 2048 caractères.") else: - await ctx.message.delete() + if fromSlash != True: + await ctx.message.delete() embed = discord.Embed(description = text, color = discord.Colour.random()) embed.set_author(name = f"Mémo noté depuis {ctx.guild.name}", icon_url = ctx.author.avatar_url) embed.set_footer(text = f'📝 le {datetime.now(pytz.timezone(self.customTimezone)).strftime("%d/%m/%Y à %H:%M:%S")}') await ctx.author.send(embed = embed) return await ctx.send("Tu viens de recevoir ton mémo !", delete_after = 5) @_memo.error - async def _note_error(self, ctx, error): + async def _memo_error(self, ctx, error): if str(error) == "text is a required argument that is missing.": - await ctx.send(f"Vous devez renseigner un message : `{ctx.prefix}note/memo ⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢`.") + await ctx.send(f"Vous devez renseigner un message : `{ctx.prefix}memo/note ⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢`.") + @cog_ext.cog_slash(name="memo", description = "T'envoie un petit memo par message privé.") + async def __memo(self, ctx, memo): + return await self._memo(ctx, memo, True) @commands.command(name='infos', aliases = ['info']) - async def _infos(self, ctx): + async def _infos(self, ctx, fromSlash = False): """Donne des infos sur le bot.\n ➡ Syntaxe: {PREFIX}infos/info⁢""" appinfo = await self.client.application_info() @@ -187,21 +240,60 @@ class Utils(commands.Cog): embed.add_field(name = "Timezone", value = f"`{self.customTimezone}`") embed.add_field(name = "Version", value = f"`{version}`") embed.set_footer(text = f"Basé sur discord.py {discord.__version__}") - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') await ctx.send(embed = embed) + @cog_ext.cog_slash(name="infos", description = "Donne des infos sur le bot.") + async def __infos(self, ctx): + ctx.prefix = "/" + return await self._infos(ctx, True) - def _map_list_among_us(self, map): - maps = {} - maps["skeld"] = ["skeld", "the skeld", "theskeld"] - maps["mira"] = ["mira", "mira hq", "mirahq"] - maps["polus"] = ["polus"] - maps["airship"] = ["airship", "air ship"] - if map == "all": - return maps["skeld"] + maps["mira"] + maps["polus"] + maps["airship"] - return maps[map] - + @commands.command(name='amongus') + async def _amongus(self, ctx, *map): + """Affiche la carte voulue d'Among Us.⁢⁢⁢⁢⁢\n ➡ Syntaxe: {PREFIX}amongus ⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" + fromSlash = False + if len(map) > 0: + if map[-1] == True: + fromSlash = map[-1] + map = map[:-1] + if len(map) > 0: + map = " ".join(map) + else: + map = "0" + + if map.lower() in self._map_list_among_us("mira"): + image = "https://i.imgur.com/6ijrH1h.jpg" + embed = discord.Embed(title = f"Map Mira HQ d'Among Us", color = discord.Colour.random(), description = f"[lien de l'image]({image})") + embed.set_image(url = image) + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + await ctx.send(embed = embed) + elif map.lower() in self._map_list_among_us("polus"): + image = "https://i.imgur.com/mhFmcw3.jpg" + embed = discord.Embed(title = f"Map Polus d'Among Us", color = discord.Colour.random(), description = f"[lien de l'image]({image})") + embed.set_image(url = image) + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + await ctx.send(embed = embed) + elif map.lower() in self._map_list_among_us("skeld"): + image = "https://i.imgur.com/OSXI4Zv.jpg" + embed = discord.Embed(title = f"Map The Skeld d'Among Us", color = discord.Colour.random(), description = f"[lien de l'image]({image})") + embed.set_image(url = image) + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + await ctx.send(embed = embed) + elif map.lower() in self._map_list_among_us("airship"): + image = "https://i.imgur.com/cm8Wogw.png" + embed = discord.Embed(title = f"Map Airship d'Among Us", color = discord.Colour.random(), description = f"[lien de l'image]({image})") + embed.set_image(url = image) + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + await ctx.send(embed = embed) + else: + await ctx.send(f"`{ctx.prefix}amongus `") @commands.command(name='among', hidden = True) async def _among(self, ctx, *, args = ""): + """Raccourci à la commande amongus⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" if not args == "": args = args.split() del args[0] @@ -212,40 +304,29 @@ class Utils(commands.Cog): await ctx.invoke(self.client.get_command("amongus")) else: await ctx.message.add_reaction(emoji = '❓') - - @commands.command(name='amongus') - async def _amongus(self, ctx, *, map = "0"): - """Affiche la carte voulue d'Among Us.⁢⁢⁢⁢⁢\n ➡ Syntaxe: {PREFIX}amongus ⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" - if map.lower() in self._map_list_among_us("mira"): - image = "https://i.imgur.com/6ijrH1h.jpg" - embed = discord.Embed(title = f"Map Mira HQ d'Among Us", color = discord.Colour.random(), description = f"[lien de l'image]({image})") - embed.set_image(url = image) - await ctx.send(embed = embed) - await ctx.message.add_reaction(emoji = '✅') - elif map.lower() in self._map_list_among_us("polus"): - image = "https://i.imgur.com/mhFmcw3.jpg" - embed = discord.Embed(title = f"Map Polus d'Among Us", color = discord.Colour.random(), description = f"[lien de l'image]({image})") - embed.set_image(url = image) - await ctx.send(embed = embed) - await ctx.message.add_reaction(emoji = '✅') - elif map.lower() in self._map_list_among_us("skeld"): - image = "https://i.imgur.com/OSXI4Zv.jpg" - embed = discord.Embed(title = f"Map The Skeld d'Among Us", color = discord.Colour.random(), description = f"[lien de l'image]({image})") - embed.set_image(url = image) - await ctx.send(embed = embed) - await ctx.message.add_reaction(emoji = '✅') - elif map.lower() in self._map_list_among_us("airship"): - image = "https://i.imgur.com/cm8Wogw.png" - embed = discord.Embed(title = f"Map Airship d'Among Us", color = discord.Colour.random(), description = f"[lien de l'image]({image})") - embed.set_image(url = image) - await ctx.send(embed = embed) - await ctx.message.add_reaction(emoji = '✅') - else: - await ctx.send(f"`{ctx.prefix}amongus `") + def _map_list_among_us(self, map): + """Sélecteur de map pour la commande amongus⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" + maps = {} + maps["skeld"] = ["skeld", "the skeld", "theskeld"] + maps["mira"] = ["mira", "mira hq", "mirahq"] + maps["polus"] = ["polus"] + maps["airship"] = ["airship", "air ship"] + if map == "all": + return maps["skeld"] + maps["mira"] + maps["polus"] + maps["airship"] + return maps[map] + @cog_ext.cog_slash(name="amongus", description = "Affiche la carte voulue d'Among Us.") + async def __amongus(self, ctx, map): + return await self._amongus(ctx, map, True) @commands.command(name='whois') async def _whois(self, ctx, *user: discord.Member): """Affiche les infos sur l'utilisateur.⁢⁢⁢⁢⁢\n ➡ Syntaxe: {PREFIX}whois [user]⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" + fromSlash = False + if len(user) > 0: + if user[-1] == True: + fromSlash = user[-1] + user = user[:-1] + if len(user) <= 1: if user == (): user = [ctx.author] @@ -267,9 +348,17 @@ class Utils(commands.Cog): embed.add_field(name = "Serveur rejoint le", value = f"{value[0][8:]}/{value[0][5:-3]}/{value[0][:4]} à {value[1]}") embed.add_field(name = "Est sur le serveur depuis", value = self._ageLayout(self._get_age(user[0].joined_at))) - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') return await ctx.send(embed = embed) return await ctx.send(f"Tu mentionnes trop d'utilisateurs : `{ctx.prefix}whois [@Membre]`") + @cog_ext.cog_slash(name="whois", description = "Affiche les infos sur l'utilisateur.") + async def __whois(self, ctx, user: discord.Member = None): + ctx.prefix = "/" # pas sûr que ce soit utile + if user == None: + return await self._whois(ctx, True) + else: + return await self._whois(ctx, user, True) def _get_age(self, date): joursRestants = datetime.now() - date @@ -358,6 +447,12 @@ class Utils(commands.Cog): @commands.command(name='sondage') async def _sondage(self, ctx, *args): """Fais un sondage.⁢⁢⁢⁢⁢\n ➡ Syntaxe: {PREFIX}sondage "" "" "" "" """ + fromSlash = False + if len(args) > 0: + if args[-1] == True: + fromSlash = args[-1] + args = args[:-1] + args = list(args) if len(args) > 2: question = args[0] @@ -390,15 +485,27 @@ class Utils(commands.Cog): sondage = await ctx.send(embed = embed) for i in range(len(args[1:])): await sondage.add_reaction(emoji = emojis_chosen[i]) - return await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + return await ctx.message.add_reaction(emoji = '✅') else: return await ctx.send(f"Désolé, mais tu as mis trop de possibilités (maximum : 20)") else: return await ctx.send(f'Désolé, mais il manque des arguments : `{ctx.prefix}sondage "" "" "" ""`') + @cog_ext.cog_slash(name="sondage", description = "Fais un sondage.") + async def __sondage(self, ctx, args): + ctx.prefix = "/" + args = shlex.split(args) + return await self._sondage(ctx, *args, True) @commands.command(name='avis', aliases=['vote']) async def _avis(self, ctx, *args): """Demande un avis.⁢⁢⁢⁢⁢\n ➡ Syntaxe: {PREFIX}avis/vote "[Titre]" "" """ + fromSlash = False + if len(args) > 0: + if args[-1] == True: + fromSlash = args[-1] + args = args[:-1] + args = list(args) if len(args) > 2 or len(args) == 0: return await ctx.send("Désolé, la syntaxe est mauvaise.") @@ -415,11 +522,26 @@ class Utils(commands.Cog): reactions = ['✅', '🤷', '❌'] for i in reactions: await message.add_reaction(emoji = i) - return await ctx.message.delete() + if fromSlash != True: + return await ctx.message.delete() + @cog_ext.cog_slash(name="avis", description = "Demande un avis.") + async def __avis(self, ctx, args): + args = shlex.split(args) + return await self._avis(ctx, *args, True) @commands.command(name='reminder', aliases=["remind", "remindme"]) - async def _reminder(self, ctx, time, *, reminder): + async def _reminder(self, ctx, time, *reminder): """Met en place un rappel.⁢⁢⁢⁢⁢\n ➡ Syntaxe: {PREFIX}reminder/remind/remindme [@] """ + fromSlash = False + if len(reminder) > 0: + if reminder[-1] == True: + fromSlash = reminder[-1] + reminder = reminder[:-1] + if len(reminder) > 0: + reminder = " ".join(reminder) + else: + reminder = None + embed = discord.Embed(color = 0xC41B1B) seconds = 0 timestamp = datetime.utcnow() @@ -459,7 +581,8 @@ class Utils(commands.Cog): for i in mentionList: message += f" {i}" try: - await ctx.message.add_reaction(emoji = '✅') + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') except: pass finalEmbed = discord.Embed(description = self._cleanCodeStringWithMentionAndURLs(reminder), timestamp = timestamp, color = discord.Colour.random()) @@ -476,3 +599,6 @@ class Utils(commands.Cog): else: embed.add_field(name="Attention", value="Mauvaise syntaxe : reminder ") await ctx.send(embed = embed) + @cog_ext.cog_slash(name="reminder", description = "Met en place un rappel.") + async def __reminder(self, ctx, time, reminder): + return await self._reminder(ctx, time, reminder, True) From dfc82c6a9278c49a446e6633ba57962b24e4112f Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 30 May 2021 13:24:38 +0200 Subject: [PATCH 17/17] deletion of old music cog --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 044335f..60bddb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .vscode/ update/ -src/cogs/music_old.py src/cogs/__pycache__/ .envrc