adding

This commit is contained in:
Mylloon 2021-08-16 17:58:02 +02:00
parent f48f644910
commit b686b057cd

View file

@ -30,7 +30,7 @@ from discord.ext import commands, menus
from time import sleep from time import sleep
import socket import socket
from discord_slash import cog_ext from discord_slash import cog_ext
from utils.core import isSlash, multipleArgsToTuple, mySendHidden from utils.core import isSlash, multipleArgsToTuple, mySendHidden, addReaction
from sys import _getframe from sys import _getframe
# Genius API # Genius API
@ -159,7 +159,7 @@ class Player(wavelink.Player):
embed.set_thumbnail(url=track.thumb) embed.set_thumbnail(url=track.thumb)
embed.add_field(name="Durée", value=str(datetime.timedelta(milliseconds=int(track.length)))) embed.add_field(name="Durée", value=str(datetime.timedelta(milliseconds=int(track.length))))
embed.add_field(name="Longueur de la file d'attente", value=str(qsize)) embed.add_field(name="Longueur file d'attente", value=str(qsize))
embed.add_field(name="Volume", value=f"**`{self.volume}%`**") embed.add_field(name="Volume", value=f"**`{self.volume}%`**")
embed.add_field(name="Demandé par", value=track.requester.mention) embed.add_field(name="Demandé par", value=track.requester.mention)
embed.add_field(name="DJ", value=self.dj.mention) embed.add_field(name="DJ", value=self.dj.mention)
@ -475,8 +475,7 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if player.is_connected: if player.is_connected:
mySendHidden(ctx, fromSlash, "Déjà connecté.") return await mySendHidden(ctx, fromSlash, "Déjà connecté.")
return
channel = getattr(ctx.author.voice, 'channel', channel) channel = getattr(ctx.author.voice, 'channel', channel)
if channel is None: if channel is None:
@ -484,6 +483,8 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
await player.connect(channel.id) await player.connect(channel.id)
await ctx.send(f":thumbsup: **Connecté à __{channel.name}__**") await ctx.send(f":thumbsup: **Connecté à __{channel.name}__**")
if fromSlash != True:
return await addReaction(ctx.message, 1)
@cog_ext.cog_slash(name="join", description = "Se connecte au salon vocal.") @cog_ext.cog_slash(name="join", description = "Se connecte au salon vocal.")
async def _connect(self, ctx, channel = None): async def _connect(self, ctx, channel = None):
return await self.connect(ctx = ctx, channel = channel, fromSlash = True) return await self.connect(ctx = ctx, channel = channel, fromSlash = True)
@ -530,6 +531,9 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
if not player.is_playing: if not player.is_playing:
await player.do_next() await player.do_next()
if fromSlash != True:
return await addReaction(ctx.message, 1)
@cog_ext.cog_slash(name="play", description = "Joue ou met dans la file d'attente le son demandé.") @cog_ext.cog_slash(name="play", description = "Joue ou met dans la file d'attente le son demandé.")
async def _play(self, ctx, son): async def _play(self, ctx, son):
return await self.play(ctx = ctx, query = son, fromSlash = True) return await self.play(ctx = ctx, query = son, fromSlash = True)
@ -541,8 +545,10 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if player.is_paused or not player.is_connected: if player.is_paused or not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.")
return
if fromSlash != True:
await addReaction(ctx.message, 1)
if self.is_privileged(ctx): if self.is_privileged(ctx):
await ctx.send(f"{ctx.author.mention} a mis la musique en pause.", delete_after=10) await ctx.send(f"{ctx.author.mention} a mis la musique en pause.", delete_after=10)
@ -570,8 +576,10 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if not player.is_paused or not player.is_connected: if not player.is_paused or not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique en pause n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique en pause n'est en cours.")
return
if fromSlash != True:
await addReaction(ctx.message, 1)
if self.is_privileged(ctx): if self.is_privileged(ctx):
await ctx.send(f"{ctx.author.mention} a relancé la musique.", delete_after=10) await ctx.send(f"{ctx.author.mention} a relancé la musique.", delete_after=10)
@ -599,8 +607,10 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if not player.is_connected: if not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.")
return
if fromSlash != True:
await addReaction(ctx.message, 1)
if self.is_privileged(ctx) or ctx.author == player.current.requester: if self.is_privileged(ctx) or ctx.author == player.current.requester:
await ctx.send(f"{ctx.author.mention} passe le son.", delete_after=10) await ctx.send(f"{ctx.author.mention} passe le son.", delete_after=10)
@ -628,8 +638,10 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if not player.is_connected: if not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.")
return
if fromSlash != True:
await addReaction(ctx.message, 1)
if self.is_privileged(ctx): if self.is_privileged(ctx):
await ctx.send(f"{ctx.author.mention} a déconnecté le bot et a supprimé la file d'attente.", delete_after=10) await ctx.send(f"{ctx.author.mention} a déconnecté le bot et a supprimé la file d'attente.", delete_after=10)
@ -653,18 +665,22 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
_, fromSlash, _ = isSlash(multipleArgsToTuple(_getframe(0))) _, fromSlash, _ = isSlash(multipleArgsToTuple(_getframe(0)))
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if not vol:
return await mySendHidden(ctx, fromSlash, f"Le volume est actuellement réglé à **{player.volume}%**.")
if not player.is_connected: if not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.")
return
if not self.is_privileged(ctx): if not self.is_privileged(ctx):
return await mySendHidden(ctx, fromSlash, "Seuls le DJ ou les admins peuvent modifier le volume.") return await mySendHidden(ctx, fromSlash, "Seuls le DJ ou les admins peuvent modifier le volume.")
if not 0 < vol < 101: if not vol:
return await mySendHidden(ctx, fromSlash, "Veuillez saisir une valeur comprise entre 1 et 100.") await mySendHidden(ctx, fromSlash, f"Le volume est actuellement réglé à **{player.volume}%**.")
if fromSlash != True:
return await addReaction(ctx.message, 1)
else:
if not 0 < vol < 101:
return await mySendHidden(ctx, fromSlash, "Veuillez saisir une valeur comprise entre 1 et 100.")
if fromSlash != True:
await addReaction(ctx.message, 1)
await player.set_volume(vol) await player.set_volume(vol)
await ctx.send(f"Volume réglé sur **{vol}%** par {ctx.author.mention}", delete_after=7) await ctx.send(f"Volume réglé sur **{vol}%** par {ctx.author.mention}", delete_after=7)
@ -679,12 +695,14 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if not player.is_connected: if not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.")
return
if player.queue.qsize() < 3: if player.queue.qsize() < 3:
return await mySendHidden(ctx, fromSlash, "Ajoutez d'autres sons à la file d'attente avant de les mélanger (3 minimum).", delete_after=15) return await mySendHidden(ctx, fromSlash, "Ajoutez d'autres sons à la file d'attente avant de les mélanger (3 minimum).", delete_after=15)
if fromSlash != True:
await addReaction(ctx.message, 1)
if self.is_privileged(ctx): if self.is_privileged(ctx):
await ctx.send(f"{ctx.author.mention} a mélangé la liste de lecture.", delete_after=10) await ctx.send(f"{ctx.author.mention} a mélangé la liste de lecture.", delete_after=10)
player.shuffle_votes.clear() player.shuffle_votes.clear()
@ -736,14 +754,13 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
await player.set_volume(vol) await player.set_volume(vol)
@commands.command(aliases=['eq']) @commands.command(aliases=['eq'])
async def equalizer(self, ctx: commands.Context, *, equalizer: str, fromSlash = None): async def equalizer(self, ctx: commands.Context, *, equalizer: str = "", fromSlash = None):
"""Change l'égaliseur de musique.\n ➡ Syntaxe: {PREFIX}equalizer/eq (flat/boost/metal/piano)""" """Change l'égaliseur de musique.\n ➡ Syntaxe: {PREFIX}equalizer/eq (flat/boost/metal/piano)"""
_, fromSlash, _ = isSlash(multipleArgsToTuple(_getframe(0))) _, fromSlash, _ = isSlash(multipleArgsToTuple(_getframe(0)))
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if not player.is_connected: if not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.")
return
if not self.is_privileged(ctx): if not self.is_privileged(ctx):
return await mySendHidden(ctx, fromSlash, "Seul le DJ ou les admins peuvent modifier l'égaliseur.") return await mySendHidden(ctx, fromSlash, "Seul le DJ ou les admins peuvent modifier l'égaliseur.")
@ -760,6 +777,8 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
await ctx.send(f"Changement d'état de l'égaliseur en `{equalizer}` par {ctx.author.mention}.", delete_after=15) await ctx.send(f"Changement d'état de l'égaliseur en `{equalizer}` par {ctx.author.mention}.", delete_after=15)
await player.set_eq(eq) await player.set_eq(eq)
if fromSlash != True:
return await addReaction(ctx.message, 1)
@cog_ext.cog_slash(name="equalizer", description = "Change l'égaliseur de musique. (flat/boost/metal/piano)") @cog_ext.cog_slash(name="equalizer", description = "Change l'égaliseur de musique. (flat/boost/metal/piano)")
async def _equalizer(self, ctx, equalizer: str): async def _equalizer(self, ctx, equalizer: str):
return await self.equalizer(ctx = ctx, equalizer = equalizer, fromSlash = True) return await self.equalizer(ctx = ctx, equalizer = equalizer, fromSlash = True)
@ -771,8 +790,7 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if not player.is_connected: if not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.")
return
if player.queue.qsize() == 0: if player.queue.qsize() == 0:
return await mySendHidden(ctx, fromSlash, "Il n'y a plus de sons dans la file d'attente.", delete_after=15) return await mySendHidden(ctx, fromSlash, "Il n'y a plus de sons dans la file d'attente.", delete_after=15)
@ -783,6 +801,8 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
if fromSlash: if fromSlash:
await ctx.send("Affichage de la liste ci-dessous.", hidden = True) await ctx.send("Affichage de la liste ci-dessous.", hidden = True)
else:
return await addReaction(ctx.message, 1)
await paginator.start(ctx) await paginator.start(ctx)
@cog_ext.cog_slash(name="queue", description = "Affiche les sons en attente.") @cog_ext.cog_slash(name="queue", description = "Affiche les sons en attente.")
async def _queue(self, ctx,): async def _queue(self, ctx,):
@ -795,12 +815,13 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if not player.is_connected: if not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.")
return
await player.invoke_controller() await player.invoke_controller()
if fromSlash: if fromSlash:
await mySendHidden(ctx, fromSlash, "Mise à jour effectuée.") await mySendHidden(ctx, fromSlash, "Mise à jour effectuée.")
else:
return await addReaction(ctx.message, 1)
@cog_ext.cog_slash(name="nowplaying", description = "Met à jour l'embed qui affiche les informations sur la chanson en cours si besoin.") @cog_ext.cog_slash(name="nowplaying", description = "Met à jour l'embed qui affiche les informations sur la chanson en cours si besoin.")
async def _nowplaying(self, ctx,): async def _nowplaying(self, ctx,):
return await self.nowplaying(ctx = ctx, fromSlash = True) return await self.nowplaying(ctx = ctx, fromSlash = True)
@ -812,8 +833,7 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx) player: Player = self.bot.wavelink.get_player(guild_id=ctx.guild.id, cls=Player, context=ctx)
if not player.is_connected: if not player.is_connected:
await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.") return await mySendHidden(ctx, fromSlash, "Aucune musique n'est en cours.")
return
if not self.is_privileged(ctx): if not self.is_privileged(ctx):
return await mySendHidden(ctx, fromSlash, "Seuls les admins et le DJ peuvent utiliser cette commande.", delete_after=15) return await mySendHidden(ctx, fromSlash, "Seuls les admins et le DJ peuvent utiliser cette commande.", delete_after=15)
@ -829,6 +849,9 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
if len(members) <= 2: if len(members) <= 2:
return await mySendHidden(ctx, fromSlash, "Aucun autre membre à qui donner le rôle de DJ.", delete_after=15) return await mySendHidden(ctx, fromSlash, "Aucun autre membre à qui donner le rôle de DJ.", delete_after=15)
if fromSlash != True:
await addReaction(ctx.message, 1)
if member: if member:
player.dj = member player.dj = member
return await ctx.send(f"{member.mention} est maintenant le DJ.") return await ctx.send(f"{member.mention} est maintenant le DJ.")
@ -861,13 +884,13 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
try: try:
paroles = song_genius.lyrics paroles = song_genius.lyrics
except: except:
await ctx.message.add_reaction(emoji = '') await addReaction(ctx.message, 2)
return await message.edit(content = f"Pas de résultats trouvés pour `{song}`.") return await message.edit(content = f"Pas de résultats trouvés pour `{song}`.")
paroles = re.sub(r"3?EmbedShare URLCopyEmbedCopy", "", paroles) # Fix temporaire bug Genius paroles = re.sub(r"3?EmbedShare URLCopyEmbedCopy", "", paroles) # Fix temporaire bug Genius
lignetotal = "" lignetotal = ""
premierembed = True premierembed = True
if len(paroles) > 7500: if len(paroles) > 7500:
await ctx.message.add_reaction(emoji = '') await addReaction(ctx.message, 2)
return await message.edit(content = f"Les paroles sont trop longues pour être affichés (lien vers la page des paroles : {song_genius.url}).") return await message.edit(content = f"Les paroles sont trop longues pour être affichés (lien vers la page des paroles : {song_genius.url}).")
title_first_embed = f"Paroles de {song_genius.title} par {song_genius.artist}." title_first_embed = f"Paroles de {song_genius.title} par {song_genius.artist}."
desc_first_embed = f"[Lien vers les paroles sur le site]({song_genius.url})" desc_first_embed = f"[Lien vers les paroles sur le site]({song_genius.url})"
@ -891,7 +914,7 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
temps_requete = int(round(nowCustom() * 1000)) - temps_requete temps_requete = int(round(nowCustom() * 1000)) - temps_requete
footer_embed = f"Pour {userOrNick(ctx.author)} par Genius en {round(temps_requete / 1000, 2)} s." footer_embed = f"Pour {userOrNick(ctx.author)} par Genius en {round(temps_requete / 1000, 2)} s."
await ctx.message.add_reaction(emoji = '') await addReaction(ctx.message, 1)
if premierembed == True: if premierembed == True:
premierembed = False premierembed = False
embed = discord.Embed(title = title_first_embed, description = f"{desc_first_embed}{lignetotal}", color = couleur_embed) embed = discord.Embed(title = title_first_embed, description = f"{desc_first_embed}{lignetotal}", color = couleur_embed)
@ -902,7 +925,7 @@ class Music(commands.Cog, wavelink.WavelinkMixin):
embed.set_footer(icon_url = ctx.author.avatar_url, text = footer_embed) embed.set_footer(icon_url = ctx.author.avatar_url, text = footer_embed)
return await ctx.send(embed = embed) return await ctx.send(embed = embed)
else: else:
await ctx.message.add_reaction(emoji = '') await addReaction(ctx.message, 2)
await mySendHidden(ctx, fromSlash, f"Aucune musique demandé... `{ctx.prefix}lyrics/l/lyrics <song>`.") await mySendHidden(ctx, fromSlash, f"Aucune musique demandé... `{ctx.prefix}lyrics/l/lyrics <song>`.")
@cog_ext.cog_slash(name="lyrics", description = "Affiche les paroles de la musique en cours, ou de la chanson spécifiée.") @cog_ext.cog_slash(name="lyrics", description = "Affiche les paroles de la musique en cours, ou de la chanson spécifiée.")
async def __lyrics(self, ctx, song: str): async def __lyrics(self, ctx, song: str):