utilisation de la nouvelle méthode isSlash

This commit is contained in:
Mylloon 2021-06-23 21:27:56 +02:00
parent 3cd0f482b8
commit 3f02ece95d
4 changed files with 43 additions and 118 deletions

View file

@ -3,7 +3,7 @@ from re import findall
from discord.ext import commands from discord.ext import commands
from random import randint, choice from random import randint, choice
from discord_slash import cog_ext from discord_slash import cog_ext
from utils.core import retirerDoublons, mentionToUser from utils.core import retirerDoublons, mentionToUser, isSlash
from utils.time import intToDatetime from utils.time import intToDatetime
def setup(client): def setup(client):
@ -17,11 +17,8 @@ class Fun(commands.Cog):
@commands.command(name='iq', aliases=["qi"]) @commands.command(name='iq', aliases=["qi"])
async def _iq(self, ctx, *user): async def _iq(self, ctx, *user):
"""Calcule ton QI.\n ➡ Syntaxe: {PREFIX}iq [user]""" """Calcule ton QI.\n ➡ Syntaxe: {PREFIX}iq [user]"""
fromSlash = False _, fromSlash, user = isSlash(user)
if len(user) > 0:
if user[-1] == True:
fromSlash = user[-1]
user = user[:-1]
if len(user) == 0: if len(user) == 0:
user = ctx.author user = ctx.author
if fromSlash != True: if fromSlash != True:
@ -55,11 +52,8 @@ class Fun(commands.Cog):
@commands.command(name='love') @commands.command(name='love')
async def _love(self, ctx, *users: discord.Member): async def _love(self, ctx, *users: discord.Member):
"""Découvre la probabilité que ces deux personnes se mettent en couple.\n ➡ Syntaxe: {PREFIX}love <User1> <User2>""" """Découvre la probabilité que ces deux personnes se mettent en couple.\n ➡ Syntaxe: {PREFIX}love <User1> <User2>"""
fromSlash = False _, fromSlash, users = isSlash(users)
if len(users) > 0:
if users[-1] == True:
fromSlash = users[-1]
users = users[:-1]
if len(users) == 2 or len(users) == 1: if len(users) == 2 or len(users) == 1:
UneDemande = False UneDemande = False
if len(users) == 1: if len(users) == 1:
@ -116,7 +110,7 @@ class Fun(commands.Cog):
@commands.command(name='8ball', aliases=['8b', '8balls']) @commands.command(name='8ball', aliases=['8b', '8balls'])
async def _8ball(self, ctx, fromSlash = None): async def _8ball(self, ctx, fromSlash = None):
"""Répond à ta question 🔮.\n ➡ Syntaxe: {PREFIX}8ball/8b""" """Répond à ta question 🔮.\n ➡ Syntaxe: {PREFIX}8ball/8b"""
if fromSlash == None: if fromSlash != True:
fromSlash = False fromSlash = False
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.", 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.", "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.",
@ -177,14 +171,11 @@ class Fun(commands.Cog):
@commands.command(name='random', aliases=['randint']) @commands.command(name='random', aliases=['randint'])
async def _random(self, ctx, *n): async def _random(self, ctx, *n):
"""Tire au hasard un chiffre entre 1 et n (par défaut n=10)\n ➡ Syntaxe: {PREFIX}random/randint [n]""" """Tire au hasard un chiffre entre 1 et n (par défaut n=10)\n ➡ Syntaxe: {PREFIX}random/randint [n]"""
fromSlash = False n, fromSlash, _ = isSlash(n)
if len(n) > 0:
if n[-1] == True: if n:
fromSlash = n[-1]
n = n[:-1]
if len(n) > 0:
try: try:
n = int(n[0]) n = int(n)
except: except:
return await ctx.send("Veuillez renseigner un chiffre valide.") return await ctx.send("Veuillez renseigner un chiffre valide.")
else: else:

View file

@ -1,6 +1,7 @@
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord_slash import cog_ext from discord_slash import cog_ext
from utils.core import isSlash
def setup(client): def setup(client):
client.add_cog(Help(client)) client.add_cog(Help(client))
@ -14,11 +15,7 @@ class Help(commands.Cog):
@commands.command(name='help') @commands.command(name='help')
async def _help(self, ctx, *cog): async def _help(self, ctx, *cog):
"""Affiche toutes les commandes du bot.\n ➡ Syntaxe: {PREFIX}help [catégorie]""" """Affiche toutes les commandes du bot.\n ➡ Syntaxe: {PREFIX}help [catégorie]"""
fromSlash = False _, fromSlash, cog = isSlash(cog)
if len(cog) > 0:
if cog[-1] == True:
fromSlash = cog[-1]
cog = cog[:-1]
if not cog: # Liste des Cog if not cog: # Liste des Cog
halp = discord.Embed(title = 'Liste des catégories et commandes sans catégorie', halp = discord.Embed(title = 'Liste des catégories et commandes sans catégorie',
@ -79,7 +76,7 @@ class Help(commands.Cog):
@commands.command(name='invite') @commands.command(name='invite')
async def _invite(self, ctx, fromSlash = None): async def _invite(self, ctx, fromSlash = None):
"""Invite ce bot sur ton serveur !""" """Invite ce bot sur ton serveur !"""
if fromSlash == None: if fromSlash != True:
fromSlash = False fromSlash = False
embed = discord.Embed(description = f"[Lien vers l'invitation Discord](https://discord.com/api/oauth2/authorize?client_id={self.client.user.id}&permissions=8&scope=bot%20applications.commands)").set_author(name="Invite moi !") embed = discord.Embed(description = f"[Lien vers l'invitation Discord](https://discord.com/api/oauth2/authorize?client_id={self.client.user.id}&permissions=8&scope=bot%20applications.commands)").set_author(name="Invite moi !")
if fromSlash != True: if fromSlash != True:

View file

@ -1,6 +1,7 @@
import discord import discord
from discord.ext import commands from discord.ext import commands
from discord_slash import cog_ext from discord_slash import cog_ext
from utils.core import isSlash
def setup(client): def setup(client):
client.add_cog(School(client)) client.add_cog(School(client))
@ -14,15 +15,7 @@ class School(commands.Cog):
# @commands.has_any_role("Professeur", "professeur", "Prof", "prof") # @commands.has_any_role("Professeur", "professeur", "Prof", "prof")
async def _appel(self, ctx, *voice_channel: int): async def _appel(self, ctx, *voice_channel: int):
"""Fais l'appel.\n ➡ Syntaxe: {PREFIX}appel [ID salon vocal]""" """Fais l'appel.\n ➡ Syntaxe: {PREFIX}appel [ID salon vocal]"""
fromSlash = False voice_channel, fromSlash, _ = isSlash(voice_channel)
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 = []
voice_channels.extend(ctx.guild.voice_channels) voice_channels.extend(ctx.guild.voice_channels)
@ -77,7 +70,7 @@ class School(commands.Cog):
@commands.command(name='getid', hidden = True) @commands.command(name='getid', hidden = True)
async def _getid(self, ctx, fromSlash = None): async def _getid(self, ctx, fromSlash = None):
"""Tuto vidéo sur comment récupérer l'ID d'un utilisateur/salon""" """Tuto vidéo sur comment récupérer l'ID d'un utilisateur/salon"""
if fromSlash == None: if fromSlash != True:
fromSlash = False fromSlash = False
if fromSlash != True: if fromSlash != True:
await ctx.message.add_reaction(emoji = '') await ctx.message.add_reaction(emoji = '')

View file

@ -5,7 +5,7 @@ from discord.ext import commands, tasks
from random import randint, shuffle from random import randint, shuffle
from discord_slash import cog_ext from discord_slash import cog_ext
from utils.reminder import Reminder from utils.reminder import Reminder
from utils.core import map_list_among_us, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs, cleanUser, userOrNick, mentionToUser, getChangelogs from utils.core import map_list_among_us, getURLsInString, getMentionInString, cleanCodeStringWithMentionAndURLs, cleanUser, userOrNick, mentionToUser, getChangelogs, isSlash
from utils.time import stringTempsVersSecondes, nowUTC, intToDatetime, timedeltaToString, timestampScreen, getAge, ageLayout, nowCustom from utils.time import stringTempsVersSecondes, nowUTC, intToDatetime, timedeltaToString, timestampScreen, getAge, ageLayout, nowCustom
def setup(client): def setup(client):
@ -20,16 +20,7 @@ class Utils(commands.Cog):
@commands.command(name='ping') @commands.command(name='ping')
async def _ping(self, ctx, *arg): async def _ping(self, ctx, *arg):
"""Affiche mon ping.\n ➡ Syntaxe: {PREFIX}ping [help]""" arg, fromSlash, _ = isSlash(arg)
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 = None
if arg == 'help': if arg == 'help':
return await ctx.send(embed = discord.Embed(color = discord.Colour.random(), description = return await ctx.send(embed = discord.Embed(color = discord.Colour.random(), description =
@ -60,15 +51,7 @@ class Utils(commands.Cog):
@commands.command(name='avatar') @commands.command(name='avatar')
async def _avatar(self, ctx, *user): async def _avatar(self, ctx, *user):
"""Affiche ton avatar ou celui que tu mentionnes.\n ➡ Syntaxe: {PREFIX}avatar [user]""" """Affiche ton avatar ou celui que tu mentionnes.\n ➡ Syntaxe: {PREFIX}avatar [user]"""
fromSlash = False user, fromSlash, _ = isSlash(user)
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: if user == None:
user = ctx.author user = ctx.author
@ -90,14 +73,8 @@ class Utils(commands.Cog):
@commands.command(name='calc') @commands.command(name='calc')
async def _calc(self, ctx, *calcul): async def _calc(self, ctx, *calcul):
"""Calculatrice.\n ➡ Syntaxe: {PREFIX}calc <calcul>""" """Calculatrice.\n ➡ Syntaxe: {PREFIX}calc <calcul>"""
fromSlash = False calcul, fromSlash, _ = isSlash(calcul)
if len(calcul) > 0: if calcul == None:
if calcul[-1] == True:
fromSlash = calcul[-1]
calcul = calcul[:-1]
if len(calcul) > 0:
calcul = calcul[0]
else:
raise ModuleNotFoundError raise ModuleNotFoundError
equation = calcul.replace('^', '**').replace('x', '*').replace('×', '*').replace('÷', '/').replace('', '>=').replace('', '<=') equation = calcul.replace('^', '**').replace('x', '*').replace('×', '*').replace('÷', '/').replace('', '>=').replace('', '<=')
@ -137,8 +114,7 @@ class Utils(commands.Cog):
await ctx.message.add_reaction(emoji = '') await ctx.message.add_reaction(emoji = '')
await ctx.send(embed = embed) await ctx.send(embed = embed)
@_calc.error @_calc.error
async def _calc_error(self, ctx, error): async def _calc_error(self, ctx, _):
print(error)
await ctx.send("Tu n'as pas spécifié de calcul.") await ctx.send("Tu n'as pas spécifié de calcul.")
@cog_ext.cog_slash(name="calc", description = "Calculatrice.") @cog_ext.cog_slash(name="calc", description = "Calculatrice.")
async def __calc(self, ctx, calcul): async def __calc(self, ctx, calcul):
@ -147,7 +123,7 @@ class Utils(commands.Cog):
@commands.command(name='syntax') @commands.command(name='syntax')
async def _syntax(self, ctx, fromSlash = None): async def _syntax(self, ctx, fromSlash = None):
"""Informations pour bien éditer son texte.""" """Informations pour bien éditer son texte."""
if fromSlash == None: if fromSlash != True:
fromSlash = False fromSlash = False
separateur = "-----------------------------------------------------\n" separateur = "-----------------------------------------------------\n"
syntaxe = separateur syntaxe = separateur
@ -203,11 +179,7 @@ class Utils(commands.Cog):
@commands.command(name='memo', aliases = ['note']) @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 <message>""" """T'envoie un petit memo par message privé.\n ➡ Syntaxe: {PREFIX}memo/note <message>"""
fromSlash = False _, fromSlash, text = isSlash(text)
if len(text) > 0:
if text[-1] == True:
fromSlash = text[-1]
text = text[:-1]
if len(text) > 0: if len(text) > 0:
text = " ".join(text) text = " ".join(text)
else: else:
@ -240,7 +212,7 @@ class Utils(commands.Cog):
@commands.command(name='infos', aliases = ['info']) @commands.command(name='infos', aliases = ['info'])
async def _infos(self, ctx, fromSlash = None): async def _infos(self, ctx, fromSlash = None):
"""Donne des infos sur le bot.\n ➡ Syntaxe: {PREFIX}infos/info""" """Donne des infos sur le bot.\n ➡ Syntaxe: {PREFIX}infos/info"""
if fromSlash == None: if fromSlash != True:
fromSlash = False fromSlash = False
appinfo = await self.client.application_info() appinfo = await self.client.application_info()
@ -290,11 +262,7 @@ class Utils(commands.Cog):
@commands.command(name='amongus') @commands.command(name='amongus')
async def _amongus(self, ctx, *map): async def _amongus(self, ctx, *map):
"""Affiche la carte voulue d'Among Us.\n ➡ Syntaxe: {PREFIX}amongus <mira/polus/skeld/airship>""" """Affiche la carte voulue d'Among Us.\n ➡ Syntaxe: {PREFIX}amongus <mira/polus/skeld/airship>"""
fromSlash = False _, fromSlash, map = isSlash(map)
if len(map) > 0:
if map[-1] == True:
fromSlash = map[-1]
map = map[:-1]
if len(map) > 0: if len(map) > 0:
map = " ".join(map) map = " ".join(map)
else: else:
@ -345,16 +313,13 @@ class Utils(commands.Cog):
await ctx.message.add_reaction(emoji = '') await ctx.message.add_reaction(emoji = '')
@cog_ext.cog_slash(name="amongus", description = "Affiche la carte voulue d'Among Us. Carte dispo : <mira/polus/skeld/airship>") @cog_ext.cog_slash(name="amongus", description = "Affiche la carte voulue d'Among Us. Carte dispo : <mira/polus/skeld/airship>")
async def __amongus(self, ctx, map): async def __amongus(self, ctx, map):
ctx.prefix = "/"
return await self._amongus(ctx, map, True) return await self._amongus(ctx, map, True)
@commands.command(name='whois') @commands.command(name='whois')
async def _whois(self, ctx, *user: discord.Member): async def _whois(self, ctx, *user: discord.Member):
"""Affiche les infos sur l'utilisateur.\n ➡ Syntaxe: {PREFIX}whois [user]""" """Affiche les infos sur l'utilisateur.\n ➡ Syntaxe: {PREFIX}whois [user]"""
fromSlash = False _, fromSlash, user = isSlash(user)
if len(user) > 0:
if user[-1] == True:
fromSlash = user[-1]
user = user[:-1]
if len(user) <= 1: if len(user) <= 1:
if user == (): if user == ():
@ -390,17 +355,16 @@ class Utils(commands.Cog):
@commands.command(name='sondage') @commands.command(name='sondage')
async def _sondage(self, ctx, *args): async def _sondage(self, ctx, *args):
"""Fais un sondage.\n ➡ Syntaxe: {PREFIX}sondage "<Question>" "<Proposition1>" "<Proposition...>" "<Proposition20>" """ """Fais un sondage.\n ➡ Syntaxe: {PREFIX}sondage "<Question>" "<Proposition1>" "<Proposition...>" "<Proposition20>" """
fromSlash = False _, fromSlash, args = isSlash(args)
if len(args) > 0: if type(args[0]) == list:
if args[-1] == True: args = args[0]
fromSlash = args[-1]
args = args[0]
args = list(args) args = list(args)
if len(args) > 2: if len(args) > 2:
question = args[0] question = args[0]
for i in findall(r'\d+', question): for i in findall(r'\d+', question):
question = cleanUser(ctx, question, i) if len(str(i)) == 18: # id de 18 chiffres
question = cleanUser(ctx, question, i)
propositions = args[1:] propositions = args[1:]
if len(propositions) <= 20: if len(propositions) <= 20:
message = "" message = ""
@ -452,11 +416,9 @@ class Utils(commands.Cog):
@commands.command(name='avis', aliases=['vote']) @commands.command(name='avis', aliases=['vote'])
async def _avis(self, ctx, *args): async def _avis(self, ctx, *args):
"""Demande un avis.\n ➡ Syntaxe: {PREFIX}avis/vote "[Titre]" "<Demande>" """ """Demande un avis.\n ➡ Syntaxe: {PREFIX}avis/vote "[Titre]" "<Demande>" """
fromSlash = False _, fromSlash, args = isSlash(args)
if len(args) > 0: if type(args[0]) == list:
if args[-1] == True: args = args[0]
fromSlash = args[-1]
args = args[0]
args = list(args) args = list(args)
if len(args) > 2 or len(args) == 0: if len(args) > 2 or len(args) == 0:
@ -486,11 +448,7 @@ class Utils(commands.Cog):
@commands.command(name='reminder', aliases=["remind", "remindme", "rappel"]) @commands.command(name='reminder', aliases=["remind", "remindme", "rappel"])
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/rappel <temps>[@] [message]""" """Met en place un rappel.\n ➡ Syntaxe: {PREFIX}reminder/remind/remindme/rappel <temps>[@] [message]"""
fromSlash = False _, fromSlash, reminder = isSlash(reminder)
if len(reminder) > 0:
if reminder[-1] == True:
fromSlash = reminder[-1]
reminder = reminder[:-1]
if len(reminder) > 0: if len(reminder) > 0:
reminder = " ".join(reminder) reminder = " ".join(reminder)
else: else:
@ -604,11 +562,7 @@ class Utils(commands.Cog):
@commands.command(name='reminderlist', aliases=["remindlist", "rl", "rappeliste"]) @commands.command(name='reminderlist', aliases=["remindlist", "rl", "rappeliste"])
async def _reminderlist(self, ctx, *utilisateur): async def _reminderlist(self, ctx, *utilisateur):
"""Affiche la liste des rappels d'un utilisateur.\n ➡ Syntaxe: {PREFIX}reminderlist/rl/remindlist/rappeliste [utilisateur]""" """Affiche la liste des rappels d'un utilisateur.\n ➡ Syntaxe: {PREFIX}reminderlist/rl/remindlist/rappeliste [utilisateur]"""
fromSlash = False _, fromSlash, utilisateur = isSlash(utilisateur)
if len(utilisateur) > 0:
if utilisateur[-1] == True:
fromSlash = utilisateur[-1]
utilisateur = utilisateur[:-1]
if len(utilisateur) > 0: if len(utilisateur) > 0:
try: try:
utilisateur = mentionToUser(getMentionInString(utilisateur[0])[0]) utilisateur = mentionToUser(getMentionInString(utilisateur[0])[0])
@ -647,12 +601,8 @@ class Utils(commands.Cog):
@commands.command(name='reminderdelete', aliases=["reminddelete", "rd"]) @commands.command(name='reminderdelete', aliases=["reminddelete", "rd"])
async def _reminderdelete(self, ctx, *id): async def _reminderdelete(self, ctx, *id):
"""Suppprime un rappel.\n ➡ Syntaxe: {PREFIX}reminderdelete/rd <id>""" """Suppprime un rappel.\n ➡ Syntaxe: {PREFIX}reminderdelete/rd <id>"""
fromSlash = False id, fromSlash, _ = isSlash(id)
if len(id) > 0: if id:
if id[-1] == True:
fromSlash = id[-1]
id = id[:-1]
if len(id) > 0:
try: try:
id = int(id[0]) id = int(id[0])
except: except:
@ -677,16 +627,10 @@ class Utils(commands.Cog):
@commands.command(name='changelogs', aliases=["changelog", "changement", "changements"]) @commands.command(name='changelogs', aliases=["changelog", "changement", "changements"])
async def _changelogs(self, ctx, *version): async def _changelogs(self, ctx, *version):
"""Affiche les changements de la dernière version ou d'une version précise.\n ➡ Syntaxe: {PREFIX}changelogs/changelog/changement/changements [version]""" """Affiche les changements de la dernière version ou d'une version précise.\n ➡ Syntaxe: {PREFIX}changelogs/changelog/changement/changements [version]"""
fromSlash = False version, fromSlash, _ = isSlash(version)
if len(version) > 0: if not version:
if version[-1] == True:
fromSlash = version[-1]
version = version[:-1]
if len(version) > 0:
version = version[0]
else:
version = 'latest' version = 'latest'
changes = getChangelogs(version) changes = getChangelogs(version.replace(',', '.'))
if changes == None or changes == 0: if changes == None or changes == 0:
if fromSlash != True: if fromSlash != True:
await ctx.message.add_reaction(emoji = '') await ctx.message.add_reaction(emoji = '')