utilisation de la nouvelle méthode isSlash
This commit is contained in:
parent
3cd0f482b8
commit
3f02ece95d
4 changed files with 43 additions and 118 deletions
|
@ -3,7 +3,7 @@ from re import findall
|
|||
from discord.ext import commands
|
||||
from random import randint, choice
|
||||
from discord_slash import cog_ext
|
||||
from utils.core import retirerDoublons, mentionToUser
|
||||
from utils.core import retirerDoublons, mentionToUser, isSlash
|
||||
from utils.time import intToDatetime
|
||||
|
||||
def setup(client):
|
||||
|
@ -17,11 +17,8 @@ class Fun(commands.Cog):
|
|||
@commands.command(name='iq', aliases=["qi"])
|
||||
async def _iq(self, ctx, *user):
|
||||
"""Calcule ton QI.\n ➡ Syntaxe: {PREFIX}iq [user]"""
|
||||
fromSlash = False
|
||||
if len(user) > 0:
|
||||
if user[-1] == True:
|
||||
fromSlash = user[-1]
|
||||
user = user[:-1]
|
||||
_, fromSlash, user = isSlash(user)
|
||||
|
||||
if len(user) == 0:
|
||||
user = ctx.author
|
||||
if fromSlash != True:
|
||||
|
@ -55,11 +52,8 @@ class Fun(commands.Cog):
|
|||
@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 <User1> <User2>"""
|
||||
fromSlash = False
|
||||
if len(users) > 0:
|
||||
if users[-1] == True:
|
||||
fromSlash = users[-1]
|
||||
users = users[:-1]
|
||||
_, fromSlash, users = isSlash(users)
|
||||
|
||||
if len(users) == 2 or len(users) == 1:
|
||||
UneDemande = False
|
||||
if len(users) == 1:
|
||||
|
@ -116,7 +110,7 @@ class Fun(commands.Cog):
|
|||
@commands.command(name='8ball', aliases=['8b', '8balls'])
|
||||
async def _8ball(self, ctx, fromSlash = None):
|
||||
"""Répond à ta question 🔮.\n ➡ Syntaxe: {PREFIX}8ball/8b"""
|
||||
if fromSlash == None:
|
||||
if fromSlash != True:
|
||||
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.",
|
||||
"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'])
|
||||
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]"""
|
||||
fromSlash = False
|
||||
if len(n) > 0:
|
||||
if n[-1] == True:
|
||||
fromSlash = n[-1]
|
||||
n = n[:-1]
|
||||
if len(n) > 0:
|
||||
n, fromSlash, _ = isSlash(n)
|
||||
|
||||
if n:
|
||||
try:
|
||||
n = int(n[0])
|
||||
n = int(n)
|
||||
except:
|
||||
return await ctx.send("Veuillez renseigner un chiffre valide.")
|
||||
else:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from discord_slash import cog_ext
|
||||
from utils.core import isSlash
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(Help(client))
|
||||
|
@ -14,11 +15,7 @@ class Help(commands.Cog):
|
|||
@commands.command(name='help')
|
||||
async def _help(self, ctx, *cog):
|
||||
"""Affiche toutes les commandes du bot.\n ➡ Syntaxe: {PREFIX}help [catégorie]"""
|
||||
fromSlash = False
|
||||
if len(cog) > 0:
|
||||
if cog[-1] == True:
|
||||
fromSlash = cog[-1]
|
||||
cog = cog[:-1]
|
||||
_, fromSlash, cog = isSlash(cog)
|
||||
|
||||
if not cog: # Liste des Cog
|
||||
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')
|
||||
async def _invite(self, ctx, fromSlash = None):
|
||||
"""Invite ce bot sur ton serveur !"""
|
||||
if fromSlash == None:
|
||||
if fromSlash != True:
|
||||
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 !")
|
||||
if fromSlash != True:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from discord_slash import cog_ext
|
||||
from utils.core import isSlash
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(School(client))
|
||||
|
@ -14,15 +15,7 @@ class School(commands.Cog):
|
|||
# @commands.has_any_role("Professeur", "professeur", "Prof", "prof")
|
||||
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_channel, fromSlash, _ = isSlash(voice_channel)
|
||||
|
||||
voice_channels = []
|
||||
voice_channels.extend(ctx.guild.voice_channels)
|
||||
|
@ -77,7 +70,7 @@ class School(commands.Cog):
|
|||
@commands.command(name='getid', hidden = True)
|
||||
async def _getid(self, ctx, fromSlash = None):
|
||||
"""Tuto vidéo sur comment récupérer l'ID d'un utilisateur/salon"""
|
||||
if fromSlash == None:
|
||||
if fromSlash != True:
|
||||
fromSlash = False
|
||||
if fromSlash != True:
|
||||
await ctx.message.add_reaction(emoji = '✅')
|
||||
|
|
|
@ -5,7 +5,7 @@ from discord.ext import commands, tasks
|
|||
from random import randint, shuffle
|
||||
from discord_slash import cog_ext
|
||||
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
|
||||
|
||||
def setup(client):
|
||||
|
@ -20,16 +20,7 @@ class Utils(commands.Cog):
|
|||
|
||||
@commands.command(name='ping')
|
||||
async def _ping(self, ctx, *arg):
|
||||
"""Affiche mon ping.\n ➡ Syntaxe: {PREFIX}ping [help]"""
|
||||
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
|
||||
arg, fromSlash, _ = isSlash(arg)
|
||||
|
||||
if arg == 'help':
|
||||
return await ctx.send(embed = discord.Embed(color = discord.Colour.random(), description =
|
||||
|
@ -60,15 +51,7 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='avatar')
|
||||
async def _avatar(self, ctx, *user):
|
||||
"""Affiche ton avatar ou celui que tu mentionnes.\n ➡ Syntaxe: {PREFIX}avatar [user]"""
|
||||
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
|
||||
user, fromSlash, _ = isSlash(user)
|
||||
|
||||
if user == None:
|
||||
user = ctx.author
|
||||
|
@ -90,14 +73,8 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='calc')
|
||||
async def _calc(self, ctx, *calcul):
|
||||
"""Calculatrice.\n ➡ Syntaxe: {PREFIX}calc <calcul>"""
|
||||
fromSlash = False
|
||||
if len(calcul) > 0:
|
||||
if calcul[-1] == True:
|
||||
fromSlash = calcul[-1]
|
||||
calcul = calcul[:-1]
|
||||
if len(calcul) > 0:
|
||||
calcul = calcul[0]
|
||||
else:
|
||||
calcul, fromSlash, _ = isSlash(calcul)
|
||||
if calcul == None:
|
||||
raise ModuleNotFoundError
|
||||
|
||||
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.send(embed = embed)
|
||||
@_calc.error
|
||||
async def _calc_error(self, ctx, error):
|
||||
print(error)
|
||||
async def _calc_error(self, ctx, _):
|
||||
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):
|
||||
|
@ -147,7 +123,7 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='syntax')
|
||||
async def _syntax(self, ctx, fromSlash = None):
|
||||
"""Informations pour bien éditer son texte."""
|
||||
if fromSlash == None:
|
||||
if fromSlash != True:
|
||||
fromSlash = False
|
||||
separateur = "-----------------------------------------------------\n"
|
||||
syntaxe = separateur
|
||||
|
@ -203,11 +179,7 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='memo', aliases = ['note'])
|
||||
async def _memo(self, ctx, *text):
|
||||
"""T'envoie un petit memo par message privé.\n ➡ Syntaxe: {PREFIX}memo/note <message>"""
|
||||
fromSlash = False
|
||||
if len(text) > 0:
|
||||
if text[-1] == True:
|
||||
fromSlash = text[-1]
|
||||
text = text[:-1]
|
||||
_, fromSlash, text = isSlash(text)
|
||||
if len(text) > 0:
|
||||
text = " ".join(text)
|
||||
else:
|
||||
|
@ -240,7 +212,7 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='infos', aliases = ['info'])
|
||||
async def _infos(self, ctx, fromSlash = None):
|
||||
"""Donne des infos sur le bot.\n ➡ Syntaxe: {PREFIX}infos/info"""
|
||||
if fromSlash == None:
|
||||
if fromSlash != True:
|
||||
fromSlash = False
|
||||
appinfo = await self.client.application_info()
|
||||
|
||||
|
@ -290,11 +262,7 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='amongus')
|
||||
async def _amongus(self, ctx, *map):
|
||||
"""Affiche la carte voulue d'Among Us.\n ➡ Syntaxe: {PREFIX}amongus <mira/polus/skeld/airship>"""
|
||||
fromSlash = False
|
||||
if len(map) > 0:
|
||||
if map[-1] == True:
|
||||
fromSlash = map[-1]
|
||||
map = map[:-1]
|
||||
_, fromSlash, map = isSlash(map)
|
||||
if len(map) > 0:
|
||||
map = " ".join(map)
|
||||
else:
|
||||
|
@ -345,16 +313,13 @@ class Utils(commands.Cog):
|
|||
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>")
|
||||
async def __amongus(self, ctx, map):
|
||||
ctx.prefix = "/"
|
||||
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]
|
||||
_, fromSlash, user = isSlash(user)
|
||||
|
||||
if len(user) <= 1:
|
||||
if user == ():
|
||||
|
@ -390,17 +355,16 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='sondage')
|
||||
async def _sondage(self, ctx, *args):
|
||||
"""Fais un sondage.\n ➡ Syntaxe: {PREFIX}sondage "<Question>" "<Proposition1>" "<Proposition...>" "<Proposition20>" """
|
||||
fromSlash = False
|
||||
if len(args) > 0:
|
||||
if args[-1] == True:
|
||||
fromSlash = args[-1]
|
||||
args = args[0]
|
||||
_, fromSlash, args = isSlash(args)
|
||||
if type(args[0]) == list:
|
||||
args = args[0]
|
||||
|
||||
args = list(args)
|
||||
if len(args) > 2:
|
||||
question = args[0]
|
||||
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:]
|
||||
if len(propositions) <= 20:
|
||||
message = ""
|
||||
|
@ -452,11 +416,9 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='avis', aliases=['vote'])
|
||||
async def _avis(self, ctx, *args):
|
||||
"""Demande un avis.\n ➡ Syntaxe: {PREFIX}avis/vote "[Titre]" "<Demande>" """
|
||||
fromSlash = False
|
||||
if len(args) > 0:
|
||||
if args[-1] == True:
|
||||
fromSlash = args[-1]
|
||||
args = args[0]
|
||||
_, fromSlash, args = isSlash(args)
|
||||
if type(args[0]) == list:
|
||||
args = args[0]
|
||||
|
||||
args = list(args)
|
||||
if len(args) > 2 or len(args) == 0:
|
||||
|
@ -486,11 +448,7 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='reminder', aliases=["remind", "remindme", "rappel"])
|
||||
async def _reminder(self, ctx, time, *reminder):
|
||||
"""Met en place un rappel.\n ➡ Syntaxe: {PREFIX}reminder/remind/remindme/rappel <temps>[@] [message]"""
|
||||
fromSlash = False
|
||||
if len(reminder) > 0:
|
||||
if reminder[-1] == True:
|
||||
fromSlash = reminder[-1]
|
||||
reminder = reminder[:-1]
|
||||
_, fromSlash, reminder = isSlash(reminder)
|
||||
if len(reminder) > 0:
|
||||
reminder = " ".join(reminder)
|
||||
else:
|
||||
|
@ -604,11 +562,7 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='reminderlist', aliases=["remindlist", "rl", "rappeliste"])
|
||||
async def _reminderlist(self, ctx, *utilisateur):
|
||||
"""Affiche la liste des rappels d'un utilisateur.\n ➡ Syntaxe: {PREFIX}reminderlist/rl/remindlist/rappeliste [utilisateur]"""
|
||||
fromSlash = False
|
||||
if len(utilisateur) > 0:
|
||||
if utilisateur[-1] == True:
|
||||
fromSlash = utilisateur[-1]
|
||||
utilisateur = utilisateur[:-1]
|
||||
_, fromSlash, utilisateur = isSlash(utilisateur)
|
||||
if len(utilisateur) > 0:
|
||||
try:
|
||||
utilisateur = mentionToUser(getMentionInString(utilisateur[0])[0])
|
||||
|
@ -647,12 +601,8 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='reminderdelete', aliases=["reminddelete", "rd"])
|
||||
async def _reminderdelete(self, ctx, *id):
|
||||
"""Suppprime un rappel.\n ➡ Syntaxe: {PREFIX}reminderdelete/rd <id>"""
|
||||
fromSlash = False
|
||||
if len(id) > 0:
|
||||
if id[-1] == True:
|
||||
fromSlash = id[-1]
|
||||
id = id[:-1]
|
||||
if len(id) > 0:
|
||||
id, fromSlash, _ = isSlash(id)
|
||||
if id:
|
||||
try:
|
||||
id = int(id[0])
|
||||
except:
|
||||
|
@ -677,16 +627,10 @@ class Utils(commands.Cog):
|
|||
@commands.command(name='changelogs', aliases=["changelog", "changement", "changements"])
|
||||
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]"""
|
||||
fromSlash = False
|
||||
if len(version) > 0:
|
||||
if version[-1] == True:
|
||||
fromSlash = version[-1]
|
||||
version = version[:-1]
|
||||
if len(version) > 0:
|
||||
version = version[0]
|
||||
else:
|
||||
version, fromSlash, _ = isSlash(version)
|
||||
if not version:
|
||||
version = 'latest'
|
||||
changes = getChangelogs(version)
|
||||
changes = getChangelogs(version.replace(',', '.'))
|
||||
if changes == None or changes == 0:
|
||||
if fromSlash != True:
|
||||
await ctx.message.add_reaction(emoji = '❌')
|
||||
|
|
Reference in a new issue