edit some stuff

This commit is contained in:
driftywinds
2025-05-11 18:16:27 +00:00
parent 56a1f0edfc
commit 4e71faf0fe

View File

@@ -15,9 +15,9 @@ load_dotenv()
# Configuration # Configuration
API_BASE_URL = os.getenv("API_BASE_URL") # Configure in .env API_BASE_URL = os.getenv("API_BASE_URL") # Configure in .env
BEARER_TOKEN = os.getenv("BEARER_TOKEN") # Configure in .env BEARER_TOKEN = os.getenv("BEARER_TOKEN") # Configure in .env
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") # Configure in .env DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") # Configure in .env
ALLOWED_CHANNELS = [123456789] # REPLACE WITH YOUR CHANNEL IDS ALLOWED_CHANNELS = [123456789] # Replace with your channel IDs
# UUID validation pattern # UUID validation pattern
UUID_PATTERN = re.compile(r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$') UUID_PATTERN = re.compile(r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$')
@@ -34,6 +34,7 @@ class SearchResultsView(View):
def __init__(self, results): def __init__(self, results):
super().__init__(timeout=60) super().__init__(timeout=60)
self.results = results self.results = results
self.original_message = None
self.add_buttons() self.add_buttons()
def add_buttons(self): def add_buttons(self):
@@ -50,6 +51,11 @@ class ResultButton(Button):
self.item = item self.item = item
async def callback(self, interaction: discord.Interaction): async def callback(self, interaction: discord.Interaction):
if self.view.original_message:
try:
await self.view.original_message.delete()
except (discord.NotFound, discord.Forbidden):
pass
await self.show_addon_embed(interaction) await self.show_addon_embed(interaction)
async def show_addon_embed(self, interaction: discord.Interaction): async def show_addon_embed(self, interaction: discord.Interaction):
@@ -110,13 +116,10 @@ async def on_message(message):
if message.author == bot.user: if message.author == bot.user:
return return
# Channel check # Allow DMs and specified channels
# the below line will make it so the bot does not reply in DMs
# if message.channel.id not in ALLOWED_CHANNELS:
if not isinstance(message.channel, discord.DMChannel) and message.channel.id not in ALLOWED_CHANNELS: if not isinstance(message.channel, discord.DMChannel) and message.channel.id not in ALLOWED_CHANNELS:
return return
# Command prefix check
if not message.content.startswith('!mpbot'): if not message.content.startswith('!mpbot'):
return return
@@ -175,7 +178,8 @@ async def perform_search(ctx, query):
) )
view = SearchResultsView(search_data) view = SearchResultsView(search_data)
await ctx.send(embed=embed, view=view) sent_message = await ctx.send(embed=embed, view=view)
view.original_message = sent_message
except requests.exceptions.HTTPError as e: except requests.exceptions.HTTPError as e:
embed = discord.Embed( embed = discord.Embed(
@@ -256,4 +260,4 @@ async def process_uuid(ctx, uuid):
await ctx.send(embed=embed, ephemeral=True) await ctx.send(embed=embed, ephemeral=True)
if __name__ == '__main__': if __name__ == '__main__':
bot.run(DISCORD_TOKEN) bot.run(DISCORD_TOKEN)