Sécuriter sur Music et message de démmarage
This commit is contained in:
parent
719d3984a1
commit
5b8be19e8a
2 changed files with 76 additions and 39 deletions
111
Music.py
111
Music.py
|
@ -63,6 +63,7 @@ class VoiceState:
|
|||
await self.bot.send_message(self.current.channel, ' Joue maintenant ' + str(self.current))
|
||||
self.current.player.start()
|
||||
await self.play_next_song.wait()
|
||||
|
||||
class Music:
|
||||
"""Commandes de musique.
|
||||
"""
|
||||
|
@ -92,6 +93,12 @@ class Music:
|
|||
except:
|
||||
pass
|
||||
|
||||
def is_listening(self, user_channel):
|
||||
for bot_channel in self.bot.voice_clients:
|
||||
if bot_channel.channel == user_channel:
|
||||
return True
|
||||
return False
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def join(self, ctx, *, channel : discord.Channel):
|
||||
"""Rejoins le channel vocal. Ne fonctionne que si l'utilisateur est deja dans un channel.
|
||||
|
@ -155,68 +162,96 @@ class Music:
|
|||
await self.bot.say('La musique ' + str(entry)+" a été mise en queue")
|
||||
await state.songs.put(entry)
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def listening(self, ctx):
|
||||
voice_channel_id = ctx.message.author.voice_channel
|
||||
if self.is_listening(voice_channel_id) == True:
|
||||
await self.bot.say("Vous écouter le bot !")
|
||||
|
||||
elif self.is_listening(voice_channel_id) == False:
|
||||
await self.bot.say("Vous n'écouter pas le bot !")
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def volume(self, ctx, value : int):
|
||||
"""Définie le volume du bot."""
|
||||
voice_channel_id = ctx.message.author.voice_channel
|
||||
if self.is_listening(voice_channel_id) == True:
|
||||
state = self.get_voice_state(ctx.message.server)
|
||||
if state.is_playing():
|
||||
player = state.player
|
||||
player.volume = value / 100
|
||||
await self.bot.say('Volume mit à {:.0%}'.format(player.volume))
|
||||
|
||||
elif self.is_listening(voice_channel_id) == False:
|
||||
await self.bot.say("Désoler mais vous n'écouter pas le bot !")
|
||||
|
||||
state = self.get_voice_state(ctx.message.server)
|
||||
if state.is_playing():
|
||||
player = state.player
|
||||
player.volume = value / 100
|
||||
await self.bot.say('Volume mit à {:.0%}'.format(player.volume))
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def resume(self, ctx):
|
||||
"""Relance la misique jouée."""
|
||||
state = self.get_voice_state(ctx.message.server)
|
||||
if state.is_playing():
|
||||
player = state.player
|
||||
player.resume()
|
||||
voice_channel_id = ctx.message.author.voice_channel
|
||||
if self.is_listening(voice_channel_id) == True:
|
||||
state = self.get_voice_state(ctx.message.server)
|
||||
if state.is_playing():
|
||||
player = state.player
|
||||
player.resume()
|
||||
|
||||
elif self.is_listening(voice_channel_id) == False:
|
||||
await self.bot.say("Désoler mais vous n'écouter pas le bot !")
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def stop(self, ctx):
|
||||
"""Arrete la musique jouée et quitte le channel.
|
||||
Cela vide aussi la queue.
|
||||
"""
|
||||
server = ctx.message.server
|
||||
state = self.get_voice_state(server)
|
||||
voice_channel_id = ctx.message.author.voice_channel
|
||||
if self.is_listening(voice_channel_id) == True:
|
||||
server = ctx.message.server
|
||||
state = self.get_voice_state(server)
|
||||
|
||||
if state.is_playing():
|
||||
player = state.player
|
||||
player.stop()
|
||||
if state.is_playing():
|
||||
player = state.player
|
||||
player.stop()
|
||||
|
||||
try:
|
||||
state.audio_player.cancel()
|
||||
del self.voice_states[server.id]
|
||||
await state.voice.disconnect()
|
||||
await self.bot.say("Queue vidée et channel quitté. ")
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
state.audio_player.cancel()
|
||||
del self.voice_states[server.id]
|
||||
await state.voice.disconnect()
|
||||
await self.bot.say("Queue vidée et channel quitté. ")
|
||||
except:
|
||||
pass
|
||||
|
||||
elif self.is_listening(voice_channel_id) == False:
|
||||
await self.bot.say("Désoler mais vous n'écouter pas le bot !")
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def skip(self, ctx):
|
||||
"""Vote pour passer la chanson en cours.
|
||||
Il faut trois votes pour passer la chanson.
|
||||
"""
|
||||
voice_channel_id = ctx.message.author.voice_channel
|
||||
if self.is_listening(voice_channel_id) == True:
|
||||
state = self.get_voice_state(ctx.message.server)
|
||||
if not state.is_playing():
|
||||
await self.bot.say("Aucune chanson n'est jouée actuellement...")
|
||||
return
|
||||
|
||||
state = self.get_voice_state(ctx.message.server)
|
||||
if not state.is_playing():
|
||||
await self.bot.say("Aucune chanson n'est jouée actuellement...")
|
||||
return
|
||||
|
||||
voter = ctx.message.author
|
||||
if voter == state.current.requester:
|
||||
await self.bot.say('Une requete pour passer la chanson a été faite.')
|
||||
state.skip()
|
||||
elif voter.id not in state.skip_votes:
|
||||
state.skip_votes.add(voter.id)
|
||||
total_votes = len(state.skip_votes)
|
||||
if total_votes >= 3:
|
||||
await self.bot.say('Vote pour passer effectué,chanson passée...')
|
||||
voter = ctx.message.author
|
||||
if voter == state.current.requester:
|
||||
await self.bot.say('Une requete pour passer la chanson a été faite.')
|
||||
state.skip()
|
||||
elif voter.id not in state.skip_votes:
|
||||
state.skip_votes.add(voter.id)
|
||||
total_votes = len(state.skip_votes)
|
||||
if total_votes >= 3:
|
||||
await self.bot.say('Vote pour passer effectué,chanson passée...')
|
||||
state.skip()
|
||||
else:
|
||||
await self.bot.say('Vote pour passer effectué, actuellement à [{}/3]'.format(total_votes))
|
||||
else:
|
||||
await self.bot.say('Vote pour passer effectué, actuellement à [{}/3]'.format(total_votes))
|
||||
else:
|
||||
await self.bot.say('Vous avez deja voté pour passer cette chanson.')
|
||||
await self.bot.say('Vous avez deja voté pour passer cette chanson.')
|
||||
|
||||
elif self.is_listening(voice_channel_id) == False:
|
||||
await self.bot.say("Désoler mais vous n'écouter pas le bot !")
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def playing(self, ctx):
|
||||
|
|
2
bot.py
2
bot.py
|
@ -41,6 +41,8 @@ async def on_ready():
|
|||
bot.load_extension("Music")
|
||||
|
||||
print("FTW's Bot operationelle")
|
||||
channel = bot.get_channel("389209382388498445")
|
||||
await bot.send_message(channel, "FTW's Bot operationelle")
|
||||
|
||||
@bot.command(pass_context = True)
|
||||
async def load(ctx, ext):
|
||||
|
|
Reference in a new issue