diff --git a/Benne_a_ordure.py b/Benne_a_ordure.py new file mode 100644 index 0000000..a5d01e5 --- /dev/null +++ b/Benne_a_ordure.py @@ -0,0 +1,138 @@ +import discord +from discord.ext import commands + + #Paramètres + +deletion_minimal = -2 #quantité de votes totale nécessaire + #pour supprimer un post. + #Prends en compte le nombre de votes + #pour le conserver et pour le supprimer. +delet_symbole = "🗑" #Réaction permettant la suppression du post. +cons_symbole = "♻" #Réaction permettant la conservation du post. + +authorized_to_start_deletion = ["156484695083843585","177393521051959306"] +blocked_from_deleted = [".156484695083843585",".384104235375001632"] + + + +reactDict = {} +messageDict = {} + + + + +def authorized_verif(id): + for i in range(len(authorized_to_start_deletion)): + if id == authorized_to_start_deletion[i]: + return True + return False + +def anti_delete(id): + for i in range(len(blocked_from_deleted)): + if str(id) == blocked_from_deleted[i]: + return False + return True + + +async def first_reaction(self , reaction , user): + if authorized_verif(user.id): + print("creation") + if reaction.emoji == delet_symbole: + reactDict[reaction.message.id]=-1 + elif reaction.emoji == cons_symbole: + reactDict[reaction.message.id]=1 + date,heure = timeCorrect(reaction.message.timestamp) + + + message = str(reaction.message.author.mention)+" a recut un vote pour la suppression ou la conservation de son message du "+str(reaction.message.timestamp)+".Si vous souhaitez voir son message supprimé, votez "+delet_symbole+". Si vous pensez que son message est correct, votez "+str(cons_symbole)+"." + m = await self.bot.send_message(reaction.message.channel,message) + messageDict[reaction.message.id]=m + await self.bot.add_reaction(reaction.message,cons_symbole) + await self.bot.add_reaction(reaction.message,delet_symbole) + +async def delete(self , reaction , user): + await self.bot.delete_message(reaction.message) + await self.bot.delete_message(messageDict[reaction.message.id]) + + +def timeCorrect(temps): + date = "5" + heure = "6" + + + + + + return date,heure + + + +class Ben: + def __init__(self,bot): + self.bot = bot + f = open("log_test.txt","a") #Montres le début de l'enregistrement dans les logs. + f.write("\n\nDébut de l'enregistrement des réactions.\n\n\n") + f.close + + + async def on_reaction_remove(self,reaction,user):#Récupères la réaction + print("-"+str(reaction.emoji)) #si on retire une réaction. + print(reaction.count) + print(user.name) + print(reaction.message.id) + if str(reaction.emoji) == cons_symbole: #Vérifie si le caractère + reactDict[reaction.message.id]-=1 #corresponds au symbole + elif str(reaction.emoji) == delet_symbole: #de suppression + reactDict[reaction.message.id]+=1 + #ou au symbole de conservation. + print("num = "+str(reactDict[reaction.message.id])) + if reactDict[reaction.message.id]==deletion_minimal: + await delete(self , reaction , user) #si le + #nombre est + #suppérieur, + #suppression. + + + + + #def auto_deletion(self,Message): + # await self.bot.delete_message(Message) + # print(Message.content) + + + + async def on_reaction_add(self, reaction, user): #Récupères la réaction + print("+"+str(reaction.emoji)) #si on ajoute une réaction. + print(reaction.count) + print(user.name) + print(reaction.message.id) + if anti_delete(reaction.message.author.id)== True: + print("message autorise") + if str(reaction.emoji) <= cons_symbole: + if reactDict.get(reaction.message.id)!=None: + reactDict[reaction.message.id]+=1 + print("message present") + else: + await first_reaction(self,reaction,user) + + + + if str(reaction.emoji) == delet_symbole: + if reactDict.get(reaction.message.id)!=None: + reactDict[reaction.message.id]-=1 + print("message present") + else: + await first_reaction(self,reaction,user) + + + + if reactDict.get(reaction.message.id) != None : + if reactDict[reaction.message.id]<=deletion_minimal: + await delete(self , reaction , user) + else: + print(reactDict[reaction.message.id]) + + print("tzdsqdzqs"+str(reactDict[reaction.message.id])) + +def setup(bot): + bot.add_cog(Ben(bot)) \ No newline at end of file diff --git a/DefaultCMD.py b/DefaultCMD.py new file mode 100644 index 0000000..ff0aada --- /dev/null +++ b/DefaultCMD.py @@ -0,0 +1,66 @@ +import discord +from discord.ext import commands + +class DefaultCMD: + def __init__(self, bot): + self.bot = bot + + #Commande ping + @commands.command(pass_context=True) + async def ping(self, ctx): + """La commande la plus stupide de se bot""" + await self.bot.say("Pong!") + print("Commande ping lancer par: "+str(ctx.message.author)) + + #Commande dis + @commands.command(pass_context=True) + async def dis(self, ctx, *, something): + """Un mode peroquet""" + await self.bot.say(something) + print("Commande dis lancer par: "+str(ctx.message.author)+" argument: "+str(something)) + + #Commande kick + @commands.command(pass_context=True) + async def kick(self, ctx, member:discord.Member): + """Expulse un jouer""" + #await self.bot.kick(member) + await self.bot.say("Kick de: "+str(member)+" par: "+str(ctx.message.author)) + print("Commande kick lancer par: "+str(ctx.message.author)+" sur: "+str(member)) + + #Commande flash + @commands.command(pass_context=True) + async def flash(self, ctx, *, something): + """Fait apparaitre un text siblimiquement""" + await self.bot.delete_message(ctx.message) + print("Commande flash lancer par: "+str(ctx.message.author)+" argument: "+str(something)) + + #Commande indirect + @commands.command(pass_context=True) + async def say(self, ctx, *, something): + """Fait passer un message indirectement""" + await self.bot.say("**{} said:** {}".format(str(ctx.message.author), something)) + await self.bot.delete_message(ctx.message) + print("Commande say lancer par: "+str(ctx.message.author)+" argument: "+str(something)) + + #Groupe de commande role + @commands.group(pass_context=True) + async def role(self, ctx): + if ctx.invoked_subcommand is None: + """Permet la gestion de roles""" + await self.bot.say("role: create; ...") + print("Commande role lancer par: "+str(ctx.message.author)) + + #Commande role create + @role.command(pass_context=True) + async def create(self, ctx, *, name): + """Permer de crée un role""" + await self.bot.say("Creation du role : "+str(name)) + print("Commande role create lancer par: "+str(ctx.message.author)+" argument: "+str(name)) + + @commands.command(pass_context=True, aliases=["id"]) + async def ID(self, ctx): + await self.bot.say("ID de l'envoyeur: "+ctx.message.author.id) + print("Commande ID lancer par: "+str(ctx.message.author)+" résultat: "+str(ctx.message.author.id)) + +def setup(bot): + bot.add_cog(DefaultCMD(bot)) diff --git a/ExampleRepl.py b/ExampleRepl.py new file mode 100644 index 0000000..c28c202 --- /dev/null +++ b/ExampleRepl.py @@ -0,0 +1,165 @@ +from discord.ext import commands +import time +import datetime +import math +import asyncio +import traceback +import discord +import inspect +import textwrap +from contextlib import redirect_stdout +import io + +ownerid = "177393521051959306" + +class REPL: + def __init__(self, bot): + self.bot = bot + self._last_result = None + self.sessions = set() + + def cleanup_code(self, content): + """Automatically removes code blocks from the code.""" + # remove ```py\n``` + if content.startswith('```') and content.endswith('```'): + return '\n'.join(content.split('\n')[1:-1]) + + # remove `foo` + return content.strip('` \n') + + def get_syntax_error(self, e): + if e.text is None: + return '```py\n{0.__class__.__name__}: {0}\n```'.format(e) + return '```py\n{0.text}{1:>{0.offset}}\n{2}: {0}```'.format(e, '^', type(e).__name__) + + @commands.command(pass_context=True, hidden=True, name='exec') + async def _eval(self, ctx, *, body: str): + if ctx.message.author.id != ownerid: + return + env = { + 'bot': self.bot, + 'ctx': ctx, + 'channel': ctx.message.channel, + 'author': ctx.message.author, + 'server': ctx.message.server, + 'message': ctx.message, + '_': self._last_result + } + + env.update(globals()) + + body = self.cleanup_code(body) + stdout = io.StringIO() + + to_compile = 'async def func():\n%s' % textwrap.indent(body, ' ') + + try: + exec(to_compile, env) + except SyntaxError as e: + return await self.bot.say(self.get_syntax_error(e)) + + func = env['func'] + try: + with redirect_stdout(stdout): + ret = await func() + except Exception as e: + value = stdout.getvalue() + await self.bot.say('```py\n{}{}\n```'.format(value, traceback.format_exc())) + else: + value = stdout.getvalue() + try: + await self.bot.add_reaction(ctx.message, '\u2705') + except: + pass + + if ret is None: + if value: + await self.bot.say('```py\n%s\n```' % value) + else: + self._last_result = ret + await self.bot.say('```py\n%s%s\n```' % (value, ret)) + + @commands.command(pass_context=True, hidden=True) + async def repl(self, ctx): + if ctx.message.author.id != ownerid: + return + msg = ctx.message + + variables = { + 'ctx': ctx, + 'bot': self.bot, + 'message': msg, + 'server': msg.server, + 'channel': msg.channel, + 'author': msg.author, + '_': None, + } + + if msg.channel.id in self.sessions: + await self.bot.say('Already running a REPL session in this channel. Exit it with `quit`.') + return + + self.sessions.add(msg.channel.id) + await self.bot.say('Enter code to execute or evaluate. `exit()` or `quit` to exit.') + while True: + response = await self.bot.wait_for_message(author=msg.author, channel=msg.channel, + check=lambda m: m.content.startswith('`')) + + cleaned = self.cleanup_code(response.content) + + if cleaned in ('quit', 'exit', 'exit()'): + await self.bot.say('Exiting.') + self.sessions.remove(msg.channel.id) + return + + executor = exec + if cleaned.count('\n') == 0: + # single statement, potentially 'eval' + try: + code = compile(cleaned, '', 'eval') + except SyntaxError: + pass + else: + executor = eval + + if executor is exec: + try: + code = compile(cleaned, '', 'exec') + except SyntaxError as e: + await self.bot.say(self.get_syntax_error(e)) + continue + + variables['message'] = response + + fmt = None + stdout = io.StringIO() + + try: + with redirect_stdout(stdout): + result = executor(code, variables) + if inspect.isawaitable(result): + result = await result + except Exception as e: + value = stdout.getvalue() + fmt = '```py\n{}{}\n```'.format(value, traceback.format_exc()) + else: + value = stdout.getvalue() + if result is not None: + fmt = '```py\n{}{}\n```'.format(value, result) + variables['_'] = result + elif value: + fmt = '```py\n{}\n```'.format(value) + + try: + if fmt is not None: + if len(fmt) > 2000: + await self.bot.send_message(msg.channel, 'Content too big to be printed.') + else: + await self.bot.send_message(msg.channel, fmt) + except discord.Forbidden: + pass + except discord.HTTPException as e: + await self.bot.send_message(msg.channel, 'Unexpected error: `{}`'.format(e)) + +def setup(bot): + bot.add_cog(REPL(bot)) diff --git a/Reactionner.py b/Reactionner.py new file mode 100644 index 0000000..8fcd273 --- /dev/null +++ b/Reactionner.py @@ -0,0 +1,42 @@ +import discord +from discord.ext import commands + +licorne_symbole = "🦄" +licorne = ["licorne"] + +caca_symbole = "💩" +caca = ["caca", "merde"] + +sel_symbole = ":PJSalt:232086190545829888" +sel = ["sel", "salty", "putain"] + +troll_symbole = ":troll:232080409083641856" +troll = ["troll", "trol", "trololo"] + +class Reactionner: + def __init__(self, bot): + self.bot = bot + + async def on_message(self, message): + for i in range(len(licorne)): + if licorne[i] in message.content.lower(): + print("licorne detecter !") + await self.bot.add_reaction(message,licorne_symbole) + + for i in range(len(caca)): + if caca[i] in message.content.lower(): + print("caca detecter !") + await self.bot.add_reaction(message,caca_symbole ) + + for i in range(len(sel)): + if sel[i] in message.content.lower(): + print("sel detecter !") + await self.bot.add_reaction(message,sel_symbole) + + for i in range(len(troll)): + if troll[i] in message.content.lower(): + print("troll detecter !") + await self.bot.add_reaction(message,troll_symbole) + +def setup(bot): + bot.add_cog(Reactionner(bot)) \ No newline at end of file diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..aad18e3 --- /dev/null +++ b/bot.py @@ -0,0 +1,71 @@ +import discord +from discord.ext import commands + +bot = commands.Bot(description="Je suis le bot du serveur FTW !", command_prefix="<@384094872820252674> ") + +owner = ["177393521051959306"] + +def is_owner(id): + for i in range(len(owner)): + if id == owner[i]: + return True + return False + +#Démarrage +@bot.event +async def on_ready(): + print("Démarrage de DefaultCMD") + bot.load_extension("DefaultCMD") + + print("Démarrage de ExampleRepl") + bot.load_extension("ExampleRepl") + + print("Démarrage de Benne_a_ordure") + bot.load_extension("Benne_a_ordure") + + print("Démarrage de Reactionner") + bot.load_extension("Reactionner") + + print("FTW's Bot operationelle") + +@bot.command(pass_context = True) +async def load(ctx, ext): + """: Charge une extension""" + if is_owner(ctx.message.author.id) == True: + bot.load_extension(ext) + print("Extention "+str(ext)+" charger par: "+str(ctx.message.author)) + await bot.say("Extension "+str(ext)+" charger") + else: + await bot.say("Désoler <@"+str(ctx.message.author.id)+"> mais vous n'avez pas le droit de faire ca !") + print("Refue de charger: "+str(ext)+" car "+str(ctx.message.author)+" n'a pas le droit !") + +@bot.command(pass_context = True) +async def unload(ctx,ext): + """: Décharge une extension""" + if is_owner(ctx.message.author.id) == True: + bot.unload_extension(ext) + print("extention "+str(ext)+" décharger") + await bot.say("Extension "+str(ext)+" décharger") + else: + await bot.say("Désoler <@"+str(ctx.message.author.id)+"> mais vous n'avez pas le droit de faire ca !") + print("Refue de décharger: "+str(ext)+" car "+str(ctx.message.author)+" n'a pas le droit !") + +@bot.command(pass_context = True) +async def reload(ctx,ext): + """: Recharge une extension avec ses modifications""" + if is_owner(ctx.message.author.id) == True: + bot.unload_extension(ext) + bot.load_extension(ext) + print("Extention "+str(ext)+" mis à jour par: "+str(ctx.message.author)) + await bot.say("Extension "+str(ext)+" mis à jour") + else: + await bot.say("Désoler <@"+str(ctx.message.author.id)+"> mais vous n'avez pas le droit de faire ca !") + print("Refue de mettre à jour: "+str(ext)+" car "+str(ctx.message.author)+" n'a pas le droit !") + +""" +@bot.event +async def on_message(msg): + print(msg.content) +""" + +bot.run("Mzg0MDk0ODcyODIwMjUyNjc0.DPt74w.2t6XZoFVYgk-7eMeS702dqyvoP4") \ No newline at end of file