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
113
Music.py
113
Music.py
|
@ -63,6 +63,7 @@ class VoiceState:
|
||||||
await self.bot.send_message(self.current.channel, ' Joue maintenant ' + str(self.current))
|
await self.bot.send_message(self.current.channel, ' Joue maintenant ' + str(self.current))
|
||||||
self.current.player.start()
|
self.current.player.start()
|
||||||
await self.play_next_song.wait()
|
await self.play_next_song.wait()
|
||||||
|
|
||||||
class Music:
|
class Music:
|
||||||
"""Commandes de musique.
|
"""Commandes de musique.
|
||||||
"""
|
"""
|
||||||
|
@ -92,6 +93,12 @@ class Music:
|
||||||
except:
|
except:
|
||||||
pass
|
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)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def join(self, ctx, *, channel : discord.Channel):
|
async def join(self, ctx, *, channel : discord.Channel):
|
||||||
"""Rejoins le channel vocal. Ne fonctionne que si l'utilisateur est deja dans un 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 self.bot.say('La musique ' + str(entry)+" a été mise en queue")
|
||||||
await state.songs.put(entry)
|
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)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def volume(self, ctx, value : int):
|
async def volume(self, ctx, value : int):
|
||||||
"""Définie le volume du bot."""
|
"""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)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def resume(self, ctx):
|
async def resume(self, ctx):
|
||||||
"""Relance la misique jouée."""
|
"""Relance la misique jouée."""
|
||||||
state = self.get_voice_state(ctx.message.server)
|
voice_channel_id = ctx.message.author.voice_channel
|
||||||
if state.is_playing():
|
if self.is_listening(voice_channel_id) == True:
|
||||||
player = state.player
|
state = self.get_voice_state(ctx.message.server)
|
||||||
player.resume()
|
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)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def stop(self, ctx):
|
async def stop(self, ctx):
|
||||||
"""Arrete la musique jouée et quitte le channel.
|
"""Arrete la musique jouée et quitte le channel.
|
||||||
Cela vide aussi la queue.
|
Cela vide aussi la queue.
|
||||||
"""
|
"""
|
||||||
server = ctx.message.server
|
voice_channel_id = ctx.message.author.voice_channel
|
||||||
state = self.get_voice_state(server)
|
if self.is_listening(voice_channel_id) == True:
|
||||||
|
server = ctx.message.server
|
||||||
|
state = self.get_voice_state(server)
|
||||||
|
|
||||||
if state.is_playing():
|
if state.is_playing():
|
||||||
player = state.player
|
player = state.player
|
||||||
player.stop()
|
player.stop()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
state.audio_player.cancel()
|
state.audio_player.cancel()
|
||||||
del self.voice_states[server.id]
|
del self.voice_states[server.id]
|
||||||
await state.voice.disconnect()
|
await state.voice.disconnect()
|
||||||
await self.bot.say("Queue vidée et channel quitté. ")
|
await self.bot.say("Queue vidée et channel quitté. ")
|
||||||
except:
|
except:
|
||||||
pass
|
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)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def skip(self, ctx):
|
async def skip(self, ctx):
|
||||||
"""Vote pour passer la chanson en cours.
|
"""Vote pour passer la chanson en cours.
|
||||||
Il faut trois votes pour passer la chanson.
|
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)
|
voter = ctx.message.author
|
||||||
if not state.is_playing():
|
if voter == state.current.requester:
|
||||||
await self.bot.say("Aucune chanson n'est jouée actuellement...")
|
await self.bot.say('Une requete pour passer la chanson a été faite.')
|
||||||
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...')
|
|
||||||
state.skip()
|
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:
|
else:
|
||||||
await self.bot.say('Vote pour passer effectué, actuellement à [{}/3]'.format(total_votes))
|
await self.bot.say('Vous avez deja voté pour passer cette chanson.')
|
||||||
else:
|
|
||||||
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)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def playing(self, ctx):
|
async def playing(self, ctx):
|
||||||
|
@ -228,7 +263,7 @@ class Music:
|
||||||
else:
|
else:
|
||||||
skip_count = len(state.skip_votes)
|
skip_count = len(state.skip_votes)
|
||||||
await self.bot.say('Joue actuellement {} [skips: {}/3]'.format(state.current, skip_count))
|
await self.bot.say('Joue actuellement {} [skips: {}/3]'.format(state.current, skip_count))
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Music(bot))
|
bot.add_cog(Music(bot))
|
||||||
print('Music is loaded')
|
print('Music is loaded')
|
||||||
|
|
2
bot.py
2
bot.py
|
@ -41,6 +41,8 @@ async def on_ready():
|
||||||
bot.load_extension("Music")
|
bot.load_extension("Music")
|
||||||
|
|
||||||
print("FTW's Bot operationelle")
|
print("FTW's Bot operationelle")
|
||||||
|
channel = bot.get_channel("389209382388498445")
|
||||||
|
await bot.send_message(channel, "FTW's Bot operationelle")
|
||||||
|
|
||||||
@bot.command(pass_context = True)
|
@bot.command(pass_context = True)
|
||||||
async def load(ctx, ext):
|
async def load(ctx, ext):
|
||||||
|
|
Reference in a new issue