Archived
1
0
Fork 0

Merge pull request #2 from flifloo/beta

Channeller, Garou, etc...
This commit is contained in:
Ethanell 2018-06-20 00:21:22 +02:00 committed by GitHub
commit b115dc2202
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 231 additions and 61 deletions

141
Channeller.py Normal file
View file

@ -0,0 +1,141 @@
import json
import discord
from discord.ext import commands
class Channeller:
def __init__(self, bot):
self.bot = bot
with open('config.json') as json_data_file:
parameter = json.load(json_data_file)
self.owner = parameter['Perms']['Admin']
self.server = self.bot.get_server("177396472294277120")
self.ow_role = discord.utils.get(self.server.roles, name="🔫 Overwatch")
ow_chan = dict()
pv_chan = dict()
"""await def __unload(self):
print("Channeller off")
for c in self.ow_chan.values():
await self.bot.delete_channel(c)"""
def is_owner(self, id):
if id in self.owner:
return True
return False
#Groupe de commande du Channeller
@commands.group(pass_context=True)
async def channeller(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.invoke(self.help)
#Le help
@channeller.command(pass_context=True)
async def help(self, ctx):
embed=discord.Embed(title="Channeller", description="Aide", color=0xff0000)
embed.set_thumbnail(url="https://i.imgur.com/F7M1e6s.png")
embed.add_field(name="jeux", value="Crée un channel vocal pour jouer !", inline=True)
embed.add_field(name="private", value="Crée un channel vocal privée", inline=True)
embed.add_field(name="publique", value="Crée un channel vocal publique", inline=True)
await self.bot.say(embed=embed)
#Crée un Channel jeux
@channeller.command(pass_context=True)
async def jeux(self, ctx, jeux):
help=discord.Embed(title="Channeller jeux", description="Aide", color=0xff0000)
help.set_thumbnail(url="https://i.imgur.com/F7M1e6s.png")
help.add_field(name="overwatch", value="Crée un channel vocal pour jouer !", inline=True)
help.add_field(name="fortinte", value="Crée un channel vocal privée", inline=True) #TODO: Changer "fortninte",et mettre fortnite
help.add_field(name="factorio", value="Crée un channel vocal publique", inline=True)
help.add_field(name="minecraft", value="Crée un channel", inline=True)
help.add_field(name="minecrafticka", value="Crée un channel vocal", inline=True)
if jeux == "list":
await self.bot.say(embed=help)
elif jeux == None:
await self.bot.say(embed=help)
elif jeux == "overwatch":
if self.ow_role in ctx.message.author.roles:
everyone_perms = discord.PermissionOverwrite(connect=False)
ow_perms = discord.PermissionOverwrite(connect=True)
everyone = discord.ChannelPermissions(target=self.server.default_role, overwrite=everyone_perms)
ow = discord.ChannelPermissions(target=self.ow_role, overwrite=ow_perms)
name = "Overwatch "+str(len(self.ow_chan)+1)
self.ow_chan[name] = await self.bot.create_channel(self.server, name, everyone, ow, type=discord.ChannelType.voice)
embed=discord.Embed(title="Channeller jeux", description="Info", color=0xff0000)
embed.set_thumbnail(url="https://i.imgur.com/F7M1e6s.png")
embed.add_field(name="jeux overwatch", value="Channel créé ! Déplacement automatique...", inline=True)
await self.bot.say(embed=embed)
print("Channel "+str(name)+" créé par: "+str(ctx.message.author))
await self.bot.move_member(ctx.message.author, self.ow_chan[name])
else:
await self.bot.say("No")
embed=discord.Embed(title="Channeller jeux", description="Erreur", color=0xff0000)
embed.set_thumbnail(url="https://i.imgur.com/F7M1e6s.png")
embed.add_field(name="jeux overwatch", value="Désolé mais vous n'avez pas le grade du jeu corespondant !", inline=True)
await self.bot.say(embed=embed)
print("Refus de création d'un channel Overwatch, "+str(ctx.message.author)+" ne possède pas le grade")
else:
await self.bot.say(embed=help)
@channeller.command(pass_context=True)
async def private(self, ctx, nom, perso):
if nom in self.pv_chan.values():
print("nom deja existant !")
else:
everyone_perms = discord.PermissionOverwrite(connect=False)
pv_perms = discord.PermissionOverwrite(connect=True)
everyone = discord.ChannelPermissions(target=self.server.default_role, overwrite=everyone_perms)
pv = discord.ChannelPermissions(target=ctx.message.author, overwrite=pv_perms)
self.pv_chan[nom] = await self.bot.create_channel(self.server, nom, everyone, pv, type=discord.ChannelType.voice)
"""for player in perso:
test"""
print(perso)
embed=discord.Embed(title="Channeller priver", description="Info", color=0xff0000)
embed.set_thumbnail(url="https://i.imgur.com/F7M1e6s.png")
embed.add_field(name="Priver", value="Channel créé ! Déplacement automatique...", inline=True)
await self.bot.say(embed=embed)
print("Channel "+str(nom)+" créé par: "+str(ctx.message.author))
await self.bot.move_member(ctx.message.author, self.pv_chan[nom])
"""@channeller.command(pass_contexte=True)
async def delete(self):
for n in range(0, self.ow_num):
await self.bot.delete_channel(self.ow_chan["ow_"+str(n+1)])
self.ow_chan = dict()"""
async def on_voice_state_update(self, x, y):
#OW clear
for c in self.ow_chan.values():
self.ow_chan[str(c)] = self.bot.get_channel(c.id)
if len(self.ow_chan[str(c)].voice_members) == 0:
await self.bot.delete_channel(c)
del self.ow_chan[str(c)]
#PV clear
for c in self.pv_chan.values():
self.pv_chan[str(c)] = self.bot.get_channel(c.id)
if len(self.pv_chan[str(c)].voice_members) == 0:
await self.bot.delete_channel(c)
del self.pv_chan[str(c)]
def setup(bot):
bot.add_cog(Channeller(bot))
print("Channeller chargé")

View file

@ -3,7 +3,6 @@ import discord
import random import random
from random import randint from random import randint
from discord.ext import commands from discord.ext import commands
#from threading import Thread
class Garou: class Garou:
@ -16,12 +15,13 @@ class Garou:
self.owner = self.parameter['Perms']['Admin'] self.owner = self.parameter['Perms']['Admin']
#Truc utile self.server = self.bot.get_server("177396472294277120") #On defini le serveur
self.server = self.bot.get_server("177396472294277120")
self.garou_role = discord.utils.get(self.server.roles, name="Garou")
self.mort_role = discord.utils.get(self.server.roles, name="Morts")
#Get des channels. #Get des roles :
self.garou_role = discord.utils.get(self.server.roles, name="🐺 Garou")
self.mort_role = discord.utils.get(self.server.roles, name="☠️ Morts")
#Get des channels :
self.forum_channel = self.bot.get_channel("402067902469242900") self.forum_channel = self.bot.get_channel("402067902469242900")
self.Garou_channel = self.bot.get_channel("403500093380100106") self.Garou_channel = self.bot.get_channel("403500093380100106")
self.soeur_channel = self.bot.get_channel("403518380017057792") self.soeur_channel = self.bot.get_channel("403518380017057792")
@ -62,6 +62,9 @@ class Garou:
self.perms_jour_soeur.send_messages = False self.perms_jour_soeur.send_messages = False
self.perms_jour_soeur.read_messages = True self.perms_jour_soeur.read_messages = True
"""async def __unload(self):
await self.end()"""
#Variables de base #Variables de base
game = 0 #Dit si une partie est en cours et a quelle stade elle en est game = 0 #Dit si une partie est en cours et a quelle stade elle en est
@ -534,10 +537,17 @@ class Garou:
loup=discord.Embed(title="Garou", description="Nuit", color=0xff0000) loup=discord.Embed(title="Garou", description="Nuit", color=0xff0000)
loup.set_thumbnail(url="https://i.imgur.com/XLPDenM.png") loup.set_thumbnail(url="https://i.imgur.com/XLPDenM.png")
loup.add_field(name="Vote", value="Les votes sont ouvert pour chosir qui tuer ce soir !", inline=False) loup.add_field(name="Vote", value="Les votes sont ouvert pour chosir qui tuer ce soir !", inline=False)
loup.add_field(name="Victime", value="")
self.LG = 1 self.LG = 1
elif self.LG == 2:
print("Fin du vote des Loups-Garou")
loup=discord.Embed(title="Garou", description="Nuit", color=0xff0000)
loup.set_thumbnail(url="https://i.imgur.com/XLPDenM.png")
loup.add_field(name="Vote", value="Les votes sont fini !", inline=False)
loup.add_field(name="Vote", value="Vous avez choisi "+str(self.LG_victime)+" !", inline=False)
self.LG = 3
return None return None
if "GML" in self.def_joueurs.values(): if "GML" in self.def_joueurs.values():
@ -887,11 +897,11 @@ class Garou:
elif r == "LG": elif r == "LG":
if self.LG == 1: if self.LG == 1:
#Vote des loup Garous
print("Vote des loups-garou") print("Vote des loups-garou")
#Faut faire le system de vote et aprés cela if valuraupif == True:
#self.LG = 2 self.LG = 2
await self.night_start()
elif r == "VY": elif r == "VY":

View file

@ -71,8 +71,8 @@ class VoiceState:
class Musique: class Musique:
"""Commandes de musique. #Commandes de musique.
"""
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.voice_states = {} self.voice_states = {}
@ -133,14 +133,14 @@ class Musique:
embed.add_field(name="skip", value="Passer la musique", inline=True) embed.add_field(name="skip", value="Passer la musique", inline=True)
embed.add_field(name="stop", value="Arrêter la musique", inline=True) embed.add_field(name="stop", value="Arrêter la musique", inline=True)
embed.add_field(name="summon", value="Faire apparaître le bot", inline=True) embed.add_field(name="summon", value="Faire apparaître le bot", inline=True)
embed.add_field(name="volume", value="Définir le volume de la musique", inline=True) #embed.add_field(name="volume", value="Définir le volume de la musique", inline=True)
await self.bot.say(embed=embed) await self.bot.say(embed=embed)
#Permmet de faire connecter vocalement le bot #Permmet de faire connecter vocalement le bot
@music.command(pass_context=True, no_pm=True) @music.command(pass_context=True, no_pm=True)
async def summon(self, ctx): async def summon(self, ctx):
"""Invoque le bot dans le channel vocal. #Invoque le bot dans le channel vocal.
Ne fonctionne que si l'utilisateur est déja dans un channel.""" #Ne fonctionne que si l'utilisateur est déja dans un channel.
summoned_channel = ctx.message.author.voice_channel summoned_channel = ctx.message.author.voice_channel
if summoned_channel is None: if summoned_channel is None:
print("Commande musique summon lancée par: "+str(ctx.message.author)+" refuser car il n'est pas dans un channel vocal") print("Commande musique summon lancée par: "+str(ctx.message.author)+" refuser car il n'est pas dans un channel vocal")
@ -171,13 +171,12 @@ class Musique:
#Permet de mettre a jouer une musique #Permet de mettre a jouer une musique
@music.command(pass_context=True, no_pm=True) @music.command(pass_context=True, no_pm=True)
async def play(self, ctx, *, song : str): async def play(self, ctx, *, song : str):
"""Joue une musique. #Joue une musique.
S'il y a une musique qui joue déjà, alors elle est mise dans #S'il y a une musique qui joue déjà, alors elle est mise dans
la queue jusqu'a la derniere musique de la queue. #la queue jusqu'a la derniere musique de la queue.
Le bot recherche automatiquement sur youtube. #Le bot recherche automatiquement sur youtube.
La liste des sites supportés est trouvée ici: #La liste des sites supportés est trouvée ici:
https://rg3.github.io/youtube-dl/supportedsites.html #https://rg3.github.io/youtube-dl/supportedsites.html
"""
state = self.get_voice_state(ctx.message.server) state = self.get_voice_state(ctx.message.server)
opts = { opts = {
"format":"bestaudio/worstvideo", "format":"bestaudio/worstvideo",
@ -218,9 +217,9 @@ class Musique:
await state.songs.put(entry) await state.songs.put(entry)
#Permmet de definit le volume #Permmet de definit le volume
@music.command(pass_context=True, no_pm=True) """@music.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 voice_channel_id = ctx.message.author.voice_channel
if self.is_listening(voice_channel_id) == True: if self.is_listening(voice_channel_id) == True:
state = self.get_voice_state(ctx.message.server) state = self.get_voice_state(ctx.message.server)
@ -238,9 +237,9 @@ class Musique:
embed=discord.Embed(title="Musique", description="Erreur", color=0x80ff00) embed=discord.Embed(title="Musique", description="Erreur", color=0x80ff00)
embed.set_thumbnail(url="http://www.icone-png.com/png/16/15638.png") embed.set_thumbnail(url="http://www.icone-png.com/png/16/15638.png")
embed.add_field(name="volume", value="Vous n'étes pas dans le channel vocal !", inline=True) embed.add_field(name="volume", value="Vous n'étes pas dans le channel vocal !", inline=True)
await self.bot.say(embed=embed) await self.bot.say(embed=embed)"""
#MEt en pause la musique #Met en pause la musique
@music.command(pass_context=True,no_pm=True) @music.command(pass_context=True,no_pm=True)
async def pause(self,ctx): async def pause(self,ctx):
voice_channel_id = ctx.message.author.voice_channel voice_channel_id = ctx.message.author.voice_channel
@ -283,7 +282,7 @@ class Musique:
embed.add_field(name="resume", value="Vous n'étes pas dans le channel vocal !", inline=True) embed.add_field(name="resume", value="Vous n'étes pas dans le channel vocal !", inline=True)
await self.bot.say(embed=embed) await self.bot.say(embed=embed)
async def on_voice_state_update(self,before,after): """async def on_voice_state_update(self,before,after):
state = self.get_voice_state(after.server) state = self.get_voice_state(after.server)
if type(state.voice) != type(None): if type(state.voice) != type(None):
if type(before.voice_channel) != type(None): if type(before.voice_channel) != type(None):
@ -294,14 +293,30 @@ class Musique:
if type(after.voice_channel) != type(None): if type(after.voice_channel) != type(None):
if len(after.voice_channel.voice_members)>=2: if len(after.voice_channel.voice_members)>=2:
try:await self.get_resume(state.voice.channel.server) try:await self.get_resume(state.voice.channel.server)
except:pass except:pass"""
async def on_voice_state_update(self,before,after):
state = self.get_voice_state(after.server)
if type(state.voice) != type(None):
if len(state.voice.channel.voice_members)<2:
server = after.server
if state.is_playing():
player = state.player
player.stop()
print("Stop lancer, channel vide !")
try:
state.audio_player.cancel()
del self.voice_states[server.id]
await state.voice.disconnect()
except:
pass
#Arret la musique et fait quitter le bot #Arret la musique et fait quitter le bot
@music.command(pass_context=True, no_pm=True) @music.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.
"""
voice_channel_id = ctx.message.author.voice_channel voice_channel_id = ctx.message.author.voice_channel
if self.is_listening(voice_channel_id) == True: if self.is_listening(voice_channel_id) == True:
server = ctx.message.server server = ctx.message.server
@ -333,9 +348,9 @@ class Musique:
#Permet de passer la musique en cours #Permet de passer la musique en cours
@music.command(pass_context=True, no_pm=True) @music.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 voice_channel_id = ctx.message.author.voice_channel
if self.is_listening(voice_channel_id) == True: if self.is_listening(voice_channel_id) == True:
state = self.get_voice_state(ctx.message.server) state = self.get_voice_state(ctx.message.server)

3
bot.py
View file

@ -34,6 +34,9 @@ async def on_ready():
print("Démarrage de Music") print("Démarrage de Music")
bot.load_extension("Music") bot.load_extension("Music")
print("Démarrage de Channeller")
bot.load_extension("Channeller")
print("FTW's Bot opérationel") print("FTW's Bot opérationel")
embed=discord.Embed(title="Administration", description="", color=0xffff00) embed=discord.Embed(title="Administration", description="", color=0xffff00)
embed.set_thumbnail(url="https://icon-icons.com/icons2/562/PNG/512/on-off-power-button_icon-icons.com_53938.png") embed.set_thumbnail(url="https://icon-icons.com/icons2/562/PNG/512/on-off-power-button_icon-icons.com_53938.png")

1
run.sh
View file

@ -10,3 +10,4 @@ fi
printf "\nMise a jour terminer !\n" printf "\nMise a jour terminer !\n"
printf "\nLancement du FTW-Bot...\n" printf "\nLancement du FTW-Bot...\n"
python3.6 bot.py python3.6 bot.py
exit