diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..ec33aee --- /dev/null +++ b/bot.py @@ -0,0 +1,119 @@ +import discord +from discord.ext import commands +from discord import app_commands +import os +from dotenv import load_dotenv +import asyncio + +# Load environment variables from .env file +load_dotenv() +TOKEN = os.getenv('DISCORD_TOKEN') + +# Define your bot +intents = discord.Intents.default() +intents.members = True # Ensure the bot has permission to read member statuses +intents.message_content = True # Ensure the bot can read message content +bot = commands.Bot(command_prefix='/', intents=intents) + +# Define dungeon aliases +dungeon_aliases = { + "Ara-Kara, City of Echoes": ["ara", "city of echoes", "coe"], + "City of Threads": ["threads", "city of threads", "cot"], + "The Stonevault": ["stonevault", "vault"], + "The Dawnbreaker": ["dawnbreaker", "breaker"], + "Mists of Tirna Scithe": ["mists", "tirna", "scithe", "mots"], + "The Necrotic Wake": ["nw", "necrotic wake", "necrotic"], + "Siege of Boralus": ["siege", "boralus", "sob"], + "Grim Batol": ["grim", "batol", "gb"] +} + +# Reverse the dictionary for easier lookup +dungeon_lookup = {} +for full_name, aliases in dungeon_aliases.items(): + for alias in aliases: + dungeon_lookup[alias] = full_name + +@bot.event +async def on_ready(): + print(f'Logged in as {bot.user}') + try: + synced = await bot.tree.sync() + print(f"Synced {len(synced)} commands.") + except Exception as e: + print(f"Error syncing commands: {e}") + +@bot.tree.command(name="lfm", description="Start looking for members for a Mythic+ run.") +@app_commands.describe( + type="Are you wanting to push? Or clear?", + dungeon="Name of the dungeon", + level="Keystone level", + private="Should the thread be private?" +) +async def lfm(interaction: discord.Interaction, type: str, dungeon: str, level: int, private: bool = False): + if type not in ['pushing', 'completion']: + await interaction.response.send_message("Please specify the type as either 'pushing' or 'completion'.", ephemeral=True) + return + + # Correct the dungeon name using the alias lookup + dungeon_lower = dungeon.lower() + full_dungeon_name = dungeon_lookup.get(dungeon_lower) + + # Fail if the dungeon name is invalid + if full_dungeon_name is None: + await interaction.response.send_message( + f"**'{dungeon}'** is not a recognized dungeon name. Please try again with a valid dungeon name or an alias.", + ephemeral=True + ) + return # Exit the command + + # Send an initial response to acknowledge the command + await interaction.response.send_message("Creating your group... Please wait.", ephemeral=True) + + try: + # Create a message for the channel + thread_name = f"{full_dungeon_name} - +{level} - {type.capitalize()}" + + # Create the thread + thread = await interaction.channel.create_thread(name=thread_name, message=interaction.message, invitable=not private) + + # Tag the user in the message + user_mention = interaction.user.mention # This will mention the user + thread_link = f"[Join the thread here]({thread.jump_url})" + + # Create the embed + embed = discord.Embed(title="Looking for Members!", color=discord.Color.blue()) + embed.add_field(name="Dungeon", value=full_dungeon_name, inline=False) + embed.add_field(name="Keystone Level", value=f"+{level}", inline=False) + embed.add_field(name="Type", value=type.capitalize(), inline=False) + embed.add_field(name="Join the Thread", value=thread_link, inline=False) + embed.set_footer(text=f"Created by {interaction.user.display_name}", icon_url=interaction.user.avatar.url) + + # Send the embed to the original channel + await interaction.channel.send(f"@here", embed=embed) + + # Post a welcome message in the new thread + welcome_message = ( + f"Welcome to **{full_dungeon_name}**! 🎉\n" + "Don't forget to use `/end` when you're done to lock the thread!" + ) + await thread.send(welcome_message) + + except discord.Forbidden: + await interaction.followup.send("I don't have permission to create a thread in this channel.") + except Exception as e: + await interaction.followup.send(f"An error occurred: {e}") + +@bot.tree.command(name="end", description="End the current Mythic+ run.") +async def end(interaction: discord.Interaction): + # Check if the command is executed within a thread + if interaction.channel.type in (discord.ChannelType.public_thread, discord.ChannelType.private_thread): + # Lock the thread + await interaction.channel.edit(locked=True) + # Send a message indicating the run has ended + await interaction.channel.send("This run has now ended.") + await interaction.response.send_message("The run has been successfully ended.", ephemeral=True) + else: + await interaction.response.send_message("This command can only be used in a thread.", ephemeral=True) + +# Run the bot +bot.run(TOKEN)