import discord import os import random from flask import Flask import time app = Flask(__name__) intents = discord.Intents.all() intents.members = True bot = discord.Bot(intents=intents) NL = "\n" PREFIX = "f!" cmds = [] @bot.event async def on_ready(): print(f"Bot vivo! \nUsuario: {bot.user}") await bot.user.edit(username="GIFbot") await bot.change_presence( status=discord.Status.online, activity=discord.Activity( type=discord.ActivityType.playing, name="f!helpme para obtener la lista de comandos")) channel = bot.get_channel(1153429735527948399) msg = await channel.fetch_message(1153429808429158460) print(f"características actuales: {msg.content}") await send_log(f"hora de inicio: {time.ctime(time.time())}") @bot.event async def on_message(message): for cmd in cmds: if message.content.startswith(f'{PREFIX}{cmd[0]}'): await message.channel.send(random.choice(cmd[1])) break if message.content.startswith(f'{PREFIX}helpme'): await message.channel.send(make_help()) @bot.command(description="Añade una característica más de Arnau!") async def add(ctx, attr: str, user: discord.Option(choices=[os.environ['N1'], os.environ['N2']])): msg = 0 if user == os.environ['N1']: channel = bot.get_channel(1166495380003889232) msg = await channel.fetch_message(1167496435944652891) elif user == os.environ['N2']: channel = bot.get_channel(1153429735527948399) msg = await channel.fetch_message(1153429808429158460) if attr.lower() not in msg.content.lower(): await msg.edit(content=f'{msg.content}\n- {attr}') await ctx.respond(f"Característica añadida! ", ephemeral=True) await send_log(f"Característica añadida: {attr} por {ctx.user}") else: await ctx.respond("Característica ya añadida!", ephemeral=True) @bot.command(description="Borrar una característica de Arnau (sólo admins)") async def delete(ctx, attr: discord.Option(choices=[os.environ['N1'], os.environ['N2']])): channel = bot.get_channel(1153429735527948399) msg = await channel.fetch_message(1153429808429158460) role = discord.utils.get(ctx.guild.roles, name="Admin") foca = 518377522485002241 if ctx.author.id == foca: await msg.edit(content=f'{msg.content.replace(f"{NL}- {attr}", "")}') await ctx.respond("Característica eliminada :(", ephemeral=True) await send_log(f"Característica eliminada: {attr} por {ctx.user}") return if role not in ctx.author.roles or ctx.author.id == os.environ['AID'] or ctx.author.id == os.environ['JID']: await ctx.respond("No tienes permiso para hacerlo!", ephemeral=True) return if attr.lower() not in msg.content.lower(): await ctx.respond("Característica no encontrada.", ephemeral=True) else: await msg.edit(content=f'{msg.content.replace(f"{NL}- {attr}", "")}') await ctx.respond("Característica eliminada :(", ephemeral=True) await send_log(f"Característica eliminada: {attr} por {ctx.user}") async def send_log(msg): channel = bot.get_channel(1153800096761262152) await channel.send(msg) def parse_cmds(f): cmd_file = open(f) for line in cmd_file.readlines(): if len(line.rstrip()) == 0: continue cmd = line.split(" ")[0] links = [_ for _ in line.split()[1:]] cmds.append((cmd, links)) def make_help(): help = ("helpme", f"""El prefijo de este bot es: f! Los comandos son: {NL.join(_[0] for _ in cmds)} Disfrutad del bot \~\~Mike & BinLAB\~\~ """) return help[1] if __name__ == '__main__': parse_cmds("cmds.txt") make_help() bot.run(os.environ['TOKEN'])