import discord from discord.ext import commands from discord.ext import tasks import os import random import time intents = discord.Intents.all() # intents.members = True bot = commands.Bot(intents=intents) NL = "\n" PREFIX = "f!" cmds = [] OrdenTorturas = [] @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() + 3600)}") mensaje_jueves.start() horario.start() @bot.event async def on_message(message): try: ctx = await bot.get_context(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()) else: await rima(ctx,message) except Exception as e: await send_log(f"rip. Error: ```{e}```") @bot.slash_command(name="add", description=f"Añade una característica más de {os.environ['N1']} o {os.environ['N2']}!") async def add(ctx, attr: str, user: discord.Option(choices=[os.environ['N1'], os.environ['N2']])): try: 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) except Exception as e: await send_log(f"rip. Error: ```{e}```") @bot.slash_command(name="delete", description=f"Borrar una característica de {os.environ['N1']} o {os.environ['N2']} (sólo admins)") async def delete(ctx, attr: str, user: discord.Option(choices=[os.environ['N1'], os.environ['N2']])): try: msg = 0 role = discord.utils.get(ctx.guild.roles, name="Admin") foca = 518377522485002241 if ctx.author.id == foca or role in ctx.author.roles or ctx.author.id != os.environ['AID'] or ctx.author.id != os.environ['JID']: 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) 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 else: 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) except Exception as e: await send_log(f"rip. Error: ```{e}```") @tasks.loop(hours = 1) async def mensaje_jueves(): try: if time.localtime().tm_hour + 1 != 24: return channel = bot.get_channel(782191552247234632) c2 = bot.get_channel(1153800096761262152) await c2.send(time.localtime().tm_hour + 1) await c2.send(time.localtime().tm_wday + 1) if time.localtime().tm_wday + 1 == 3: await channel.send("<@688355617681047574> FELIZ JUEVES!!!!") await channel.send(random.choices(["https://media.tenor.com/riA830QHvC8AAAAC/feliz-jueves-asuka.gif","https://media.tenor.com/L2-mDROrwgwAAAAd/racism.gif"], k=1, weights=[9,1])[0]) except Exception as e: await send_log(f"rip. Error: ```{e}```") @tasks.loop(hours = 1) async def horario(): try: if not 7 <= time.localtime().tm_hour <= 9: return user = bot.get_user(670695670486794260) dia = time.localtime().tm_wday if 0 <= dia <= 4: horario = f'{NL}'.join([hora for hora in OrdenTorturas[dia][1]]) else: return if dia == 0: await user.send(f"""Buenos días, hoy es lunes, estas son las asignaturas que tienes hoy: {horario}""") if dia == 1: await user.send(f"""Buenos días, hoy es martes, estas son las asignaturas que tienes hoy: {horario}""") if dia == 2: await user.send(f"""Buenos días, hoy es miércoles, estas son las asignaturas que tienes hoy: {horario}""") if dia == 3: await user.send(f"""¡Felíz jueves! Estas son las asignaturas que tienes hoy: {horario}""") if dia == 4: await user.send(f"""Buenos días, hoy es viernes, estas son las asignaturas que tienes hoy: {horario}""") except Exception as e: await send_log(f"rip. Error: ```{e}```") async def rima(ctx, message): try: if message.content.lower().endswith("murciano") and message.author != bot.user: await ctx.reply("Me la agarras con la mano", mention_author=True, delete_after=5) elif message.content.lower().endswith(("cinco", "5", "25", "veinticinco")) and message.author != bot.user: await ctx.reply("Por el culo te la hinco", mention_author=True, delete_after=5) elif message.content.lower().endswith(("ocho", "8")) and not message.content.lower().endswith("endocho") and message.author != bot.user: await ctx.reply("Por el culo te la endocho", mention_author=True, delete_after=5) elif message.content.lower().endswith(("trece", "13")) and message.author != bot.user: await ctx.reply("Agárramela que me crece", mention_author=True, delete_after=5) elif message.content.lower().endswith(("seis", "6")) and message.author != bot.user: await ctx.reply("Os la meto y no me veis", mention_author=True, delete_after=5) elif message.content.lower().endswith("juan") and message.author != bot.user: await ctx.reply("Pan", mention_author=True, delete_after=5) elif message.content.lower().endswith("foca") and message.author != bot.user: await ctx.reply(random.choices(["Está como una roca 🗿","Mi rabo en tu boca"], k=1, weights=[9,1])[0], mention_author=True, delete_after=5) elif message.content.lower().endswith("catalán") and message.author != bot.user: await ctx.reply(random.choices(["Por el culo te la meterán","El culo te arrasarán"], k=1, weights=[9, 1])[0], mention_author=True, delete_after=5) elif message.content.lower().endswith("valero") and message.author != bot.user: await ctx.reply(random.choices(["Te la mete en el pesquero","Apaliza a un forastero"], k=1, weights=[9,1])[0], mention_author=True, delete_after=5) elif message.content.lower().endswith("jueves") and message.author != bot.user: await ctx.reply(random.choices(["https://media.tenor.com/riA830QHvC8AAAAC/feliz-jueves-asuka.gif","https://media.tenor.com/L2-mDROrwgwAAAAd/racism.gif"], k=1, weights=[9,1])[0], mention_author=True) except Exception as e: await send_log(f"rip. Error: ```{e}```") 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 parse_OrdenTorturas(f): OrdenTorturas_file = open(f) for line in OrdenTorturas_file.readlines(): if len(line.rstrip()) == 0: continue dia = line.split(" ")[0] asignaturas = [_ for _ in line.split()[1:]] OrdenTorturas.append((dia, asignaturas)) 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") parse_OrdenTorturas("horario.txt") make_help() bot.run(os.environ['TOKEN'])