diff --git a/bot.py b/bot.py index 11a40d2..668ec9a 100644 --- a/bot.py +++ b/bot.py @@ -137,45 +137,38 @@ async def lfm(interaction: discord.Interaction, type: str, dungeon: str, level: 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) + thread_id = interaction.channel.id - # Load the logs and find the corresponding message + # Load the current logs logs = load_lfm_logs() - thread_message_id = None - for message_id, info in logs.items(): - if info.get("thread_id") == interaction.channel.id: - thread_message_id = int(message_id) + + # Check if the thread ID is in the logs + found_message_id = None + for message_id, log_entry in logs.items(): + if log_entry.get("thread_id") == thread_id: + found_message_id = message_id break - if thread_message_id: - # Retrieve the original message + if found_message_id is not None: + # Lock the thread + await interaction.channel.edit(locked=True) + + # Get the original message object and edit it to show that the run has ended try: - original_message = await interaction.channel.parent.fetch_message(thread_message_id) - if original_message: - # Edit the original message to indicate the run has ended - embed = original_message.embeds[0] - - # Update the field that says "Join the thread here" - embed.set_field_at( - 3, # The index of the field to replace (Join the Thread field is the 4th, so index is 3) - name="Status", - value="This run has now ended", # Replace "Join the thread here" with this message - inline=False - ) - - await original_message.edit(embed=embed) - - # Mark the run as ended in the logs - logs[str(thread_message_id)]["status"] = "ended" - save_lfm_logs(logs) - + original_message = await interaction.channel.fetch_message(int(found_message_id)) + await original_message.edit(content="This run has now ended.", embed=None) except discord.NotFound: - await interaction.response.send_message("Could not find the original message.", ephemeral=True) + await interaction.followup.send(f"Original message not found.", ephemeral=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) + # Remove the entry from the logs + del logs[found_message_id] + save_lfm_logs(logs) + + # 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 and the logs have been cleared.", ephemeral=True) + else: + await interaction.response.send_message("This thread was not found in the logs.", ephemeral=True) else: await interaction.response.send_message("This command can only be used in a thread.", ephemeral=True) diff --git a/bot.py.bak b/bot.py.bak deleted file mode 100644 index ec33aee..0000000 --- a/bot.py.bak +++ /dev/null @@ -1,119 +0,0 @@ -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)