feat: Add command to manually add messages to the starboard

This commit is contained in:
Slipstream 2025-05-17 20:12:06 -06:00
parent 62bf7a36c9
commit 3f0d36f236
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -9,6 +9,10 @@ import logging
import sys
import os
# Regular expression to extract message ID from Discord message links
# Format: https://discord.com/channels/{guild_id}/{channel_id}/{message_id}
MESSAGE_LINK_PATTERN = re.compile(r"https?://(?:www\.)?discord(?:app)?\.com/channels/\d+/\d+/(\d+)")
# Add the parent directory to sys.path to allow imports
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@ -504,6 +508,91 @@ class StarboardCog(commands.Cog):
log.exception(f"Error clearing starboard: {e}")
await ctx.send(f"❌ An error occurred while clearing the starboard: {str(e)}")
@starboard_group.command(name="add", description="Manually add a message to the starboard")
@commands.has_permissions(administrator=True)
@app_commands.default_permissions(administrator=True)
@app_commands.describe(message_id_or_link="The message ID or link to add to the starboard")
async def starboard_add(self, ctx, message_id_or_link: str):
"""Manually add a message to the starboard using its ID or link."""
# Get starboard settings
settings = await settings_manager.get_starboard_settings(ctx.guild.id)
if not settings or not settings.get('enabled') or not settings.get('starboard_channel_id'):
await ctx.send("❌ Starboard is not properly configured. Please set up the starboard first.")
return
# Get the starboard channel
starboard_channel = ctx.guild.get_channel(settings.get('starboard_channel_id'))
if not starboard_channel:
await ctx.send("❌ Starboard channel not found.")
return
# Extract message ID from link if needed
message_id = message_id_or_link
link_match = MESSAGE_LINK_PATTERN.search(message_id_or_link)
if link_match:
message_id = link_match.group(1)
# Try to convert the message ID to an integer
try:
message_id = int(message_id)
except ValueError:
await ctx.send("❌ Invalid message ID or link format.")
return
# Defer the response since fetching the message might take time
await ctx.defer()
# Try to find the message in the guild
message = None
channel_found = False
# Search for the message in all text channels
for channel in ctx.guild.text_channels:
try:
message = await channel.fetch_message(message_id)
channel_found = True
break
except discord.NotFound:
continue
except discord.Forbidden:
continue
except discord.HTTPException:
continue
if not message:
if channel_found:
await ctx.send("❌ Message not found. Make sure the message ID is correct.")
else:
await ctx.send("❌ Message not found. The bot might not have access to the channel containing this message.")
return
# Check if the message is already in the starboard
entry = await settings_manager.get_starboard_entry(ctx.guild.id, message.id)
if entry:
await ctx.send(f"⚠️ This message is already in the starboard with {entry.get('star_count', 0)} stars.")
return
# Check if the message is from the starboard channel
if message.channel.id == starboard_channel.id:
await ctx.send("❌ Cannot add a message from the starboard channel to the starboard.")
return
# Set a default star count (1 more than the threshold)
threshold = settings.get('threshold', 3)
star_count = threshold
# Create a new starboard entry
starboard_message = await self._create_starboard_message(starboard_channel, message, star_count)
if starboard_message:
await settings_manager.create_starboard_entry(
ctx.guild.id, message.id, message.channel.id,
starboard_message.id, message.author.id, star_count
)
await ctx.send(f"✅ Message successfully added to the starboard with {star_count} stars.")
log.info(f"Admin {ctx.author.id} manually added message {message.id} to starboard in guild {ctx.guild.id}")
else:
await ctx.send("❌ Failed to create starboard message.")
@starboard_group.command(name="stats", description="Show starboard statistics")
async def starboard_stats(self, ctx):
"""Display statistics about the starboard."""