import discord import asyncio class UserManagementCommands: def __init__(self, bot): self.bot = bot # Store lists of ignored/muted users and channels self.ignored_channels = set() self.muted_channels = set() self.muted_users = set() async def cmd_ignore(self, message): """ Ignore all users in the current channel except for self Usage: .ignore """ try: channel_id = message.channel.id self.ignored_channels.add(channel_id) await message.edit(content=f"✅ Ignoring users in this channel. Use `.unignore` to revert.") except Exception as e: await message.edit(content=f"❌ Error ignoring channel: {str(e)}") async def cmd_unignore(self, message): """ Stop ignoring users in the current channel Usage: .unignore """ try: channel_id = message.channel.id if channel_id in self.ignored_channels: self.ignored_channels.remove(channel_id) await message.edit(content=f"✅ No longer ignoring users in this channel.") else: await message.edit(content=f"❌ This channel is not being ignored.") except Exception as e: await message.edit(content=f"❌ Error: {str(e)}") async def cmd_close(self, message): """ Close the DM channel Usage: .close """ try: # Only works in DM channels if isinstance(message.channel, discord.DMChannel): await message.edit(content="✅ Closing DM...") await asyncio.sleep(1) # Give a second for the message to be seen await message.channel.close() else: await message.edit(content="❌ This command only works in DM channels.") except Exception as e: await message.edit(content=f"❌ Error closing DM: {str(e)}") async def cmd_mute(self, message): """ Mute the current channel (no notifications) Usage: .mute """ try: channel_id = message.channel.id self.muted_channels.add(channel_id) await message.edit(content=f"✅ Channel muted. Use `.unmute` to revert.") except Exception as e: await message.edit(content=f"❌ Error muting channel: {str(e)}") async def cmd_unmute(self, message): """ Unmute the current channel Usage: .unmute """ try: channel_id = message.channel.id if channel_id in self.muted_channels: self.muted_channels.remove(channel_id) await message.edit(content=f"✅ Channel unmuted.") else: await message.edit(content=f"❌ This channel is not muted.") except Exception as e: await message.edit(content=f"❌ Error: {str(e)}") async def cmd_block(self, message): """ Block a user Usage: .block @user or .block [in reply to a message] """ try: # Check if we have a mention or if it's a reply if message.mentions: user = message.mentions[0] elif message.reference and message.reference.resolved: user = message.reference.resolved.author else: await message.edit(content="❌ Usage: `.block @user` or reply to a message with `.block`") return if user == self.bot.user: await message.edit(content="❌ Cannot block yourself.") return await user.block() await message.edit(content=f"✅ Blocked user {user.name}#{user.discriminator}.") except Exception as e: await message.edit(content=f"❌ Error blocking user: {str(e)}") async def cmd_unblock(self, message): """ Unblock a user Usage: .unblock @user or user_id """ try: content = message.content.strip() # Check if we have a mention if message.mentions: user = message.mentions[0] await user.unblock() await message.edit(content=f"✅ Unblocked user {user.name}#{user.discriminator}.") return # Try to get user by ID parts = content.split() if len(parts) >= 2: try: user_id = int(parts[1]) user = await self.bot.fetch_user(user_id) await user.unblock() await message.edit(content=f"✅ Unblocked user {user.name}#{user.discriminator}.") except: await message.edit(content="❌ Could not find user with that ID.") else: await message.edit(content="❌ Usage: `.unblock @user` or `.unblock user_id`") except Exception as e: await message.edit(content=f"❌ Error unblocking user: {str(e)}") # Method to check if a channel is ignored def is_channel_ignored(self, channel_id): return channel_id in self.ignored_channels # Method to check if a channel is muted def is_channel_muted(self, channel_id): return channel_id in self.muted_channels