|
| 1 | +from bronxbot import * |
| 2 | + |
| 3 | +@bot.event |
| 4 | +async def on_message(message): |
| 5 | + """Handle messages""" |
| 6 | + if message.author.bot: |
| 7 | + return |
| 8 | + if message.content.startswith(bot.command_prefix): |
| 9 | + if message.guild in bot.MAIN_GUILD_IDS: |
| 10 | + if message.channel.id in [1378156495144751147, 1260347806699491418]: |
| 11 | + return await message.reply("<#1314685928614264852>") |
| 12 | + await bot.process_commands(message) |
| 13 | + |
| 14 | +@bot.event |
| 15 | +async def on_message_edit(before, after): |
| 16 | + """Handle message edits and re-process commands if edited""" |
| 17 | + # Ignore bot messages |
| 18 | + if after.author.bot: |
| 19 | + return |
| 20 | + |
| 21 | + # Ignore if message content didn't change (e.g., embed updates) |
| 22 | + if before.content == after.content: |
| 23 | + return |
| 24 | + |
| 25 | + # Only process if the edited message starts with a command prefix |
| 26 | + if not after.content.startswith(bot.command_prefix): |
| 27 | + return |
| 28 | + |
| 29 | + # Add rate limiting to prevent spam processing |
| 30 | + current_time = time.time() |
| 31 | + user_id = after.author.id |
| 32 | + |
| 33 | + # Check if user has processed a command edit recently (within 2 seconds) |
| 34 | + if not hasattr(bot, 'last_edit_times'): |
| 35 | + bot.last_edit_times = {} |
| 36 | + |
| 37 | + if user_id in bot.last_edit_times: |
| 38 | + if current_time - bot.last_edit_times[user_id] < 2.0: |
| 39 | + return # Skip if too recent |
| 40 | + |
| 41 | + bot.last_edit_times[user_id] = current_time |
| 42 | + |
| 43 | + # Check if the message is in a main guild and restricted channel |
| 44 | + if after.guild and after.guild.id in bot.MAIN_GUILD_IDS: |
| 45 | + if after.channel.id in [1378156495144751147, 1260347806699491418]: |
| 46 | + return await after.reply("<#1314685928614264852>") |
| 47 | + |
| 48 | + try: |
| 49 | + # Re-process the edited message as a command |
| 50 | + await bot.process_commands(after) |
| 51 | + |
| 52 | + # Log the command edit for debugging |
| 53 | + command_name = after.content.split()[0][1:] if after.content.split() else "unknown" |
| 54 | + logging.info(f"Command edited and re-processed: {command_name} by {after.author} ({after.author.id}) in {after.guild.name if after.guild else 'DM'}") |
| 55 | + |
| 56 | + except Exception as e: |
| 57 | + # Log any errors but don't crash |
| 58 | + logging.error(f"Error processing edited command: {e}") |
| 59 | + # Optionally, you could add a small reaction or reply to indicate the edit was processed |
| 60 | + try: |
| 61 | + await after.add_reaction("🔄") # Indicate command was re-processed |
| 62 | + except: |
| 63 | + pass # Ignore if we can't add reactions |
0 commit comments