from __future__ import annotations import discord from discord.ext import commands from bot.i18n import get_cmd_desc class ServerManager(commands.Cog): def __init__(self, bot: commands.Bot) -> None: self.bot = bot async def ensure_category(self, guild: discord.Guild, name: str) -> discord.CategoryChannel: category = discord.utils.get(guild.categories, name=name) if category is None: category = await guild.create_category(name) return category async def ensure_text(self, guild: discord.Guild, category: discord.CategoryChannel, name: str, topic: str | None = None) -> discord.TextChannel: channel = discord.utils.get(guild.text_channels, name=name) if channel is None: channel = await guild.create_text_channel(name, category=category, topic=topic) elif channel.category_id != category.id: await channel.edit(category=category) return channel async def ensure_voice(self, guild: discord.Guild, category: discord.CategoryChannel, name: str, user_limit: int = 0) -> discord.VoiceChannel: channel = discord.utils.get(guild.voice_channels, name=name) if channel is None: channel = await guild.create_voice_channel(name, category=category, user_limit=user_limit) elif channel.category_id != category.id: await channel.edit(category=category) return channel @commands.hybrid_command(name="setupserver", description=get_cmd_desc("commands.tools.setupserver_desc")) @commands.has_permissions(administrator=True) async def setupserver_cmd(self, ctx: commands.Context) -> None: guild = ctx.guild category_general = await self.ensure_category(guild, "📌・الإدارة") category_community = await self.ensure_category(guild, "💬・المجتمع") category_support = await self.ensure_category(guild, "🛠️・الدعم") category_gaming_text = await self.ensure_category(guild, "🎮・Gaming Hub") category_gaming_voice = await self.ensure_category(guild, "🔊・Gaming Voice") verify = await self.ensure_text(guild, category_general, "✅-verify", "خطوات التحقق ودخول الأعضاء") welcome = await self.ensure_text(guild, category_general, "👋-welcome", "الترحيب بالأعضاء الجدد") logs = await self.ensure_text(guild, category_general, "🧾-logs", "سجل الأحداث والتنبيهات") daily = await self.ensure_text(guild, category_general, "🗓️-daily", "رسالة يومية للمجتمع") suggestions = await self.ensure_text(guild, category_community, "💡-suggestions", "اقتراحات الأعضاء") await self.ensure_text(guild, category_support, "🎫-support", "الدعم الفني") await self.ensure_text(guild, category_gaming_text, "📰-game-news", "أخبار الألعاب") await self.ensure_voice(guild, category_gaming_voice, "🎮 Lobby", user_limit=0) verified_role = discord.utils.get(guild.roles, name="✅ Verified") if verified_role is None: verified_role = await guild.create_role(name="✅ Verified", color=discord.Color.green(), mentionable=True) everyone = guild.default_role for channel in guild.channels: if channel.id == verify.id: await channel.set_permissions(everyone, view_channel=True, send_messages=False) await channel.set_permissions(verified_role, view_channel=True, send_messages=False) else: await channel.set_permissions(everyone, view_channel=False) await channel.set_permissions(verified_role, view_channel=True) await self.bot.db.execute( """ INSERT INTO guild_config( guild_id, log_channel_id, welcome_channel_id, suggestion_channel_id, daily_channel_id, ticket_category_id, verify_channel_id, verify_role_id ) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT(guild_id) DO UPDATE SET log_channel_id = excluded.log_channel_id, welcome_channel_id = excluded.welcome_channel_id, suggestion_channel_id = excluded.suggestion_channel_id, daily_channel_id = excluded.daily_channel_id, ticket_category_id = excluded.ticket_category_id, verify_channel_id = excluded.verify_channel_id, verify_role_id = excluded.verify_role_id """, guild.id, logs.id, welcome.id, suggestions.id, daily.id, category_support.id, verify.id, verified_role.id, ) embed = discord.Embed( title="✅ Professional Setup Completed", description="Server structure is ready, verification access control enabled, and core channels linked.", color=discord.Color.green(), ) embed.add_field(name="Verify", value=f"{verify.mention} | role: {verified_role.mention}", inline=False) embed.add_field(name="Core", value=f"{welcome.mention} | {logs.mention} | {daily.mention} | {suggestions.mention}", inline=False) await ctx.reply(embed=embed) @commands.hybrid_command(name="organizechannels", description=get_cmd_desc("commands.tools.organizechannels_desc")) @commands.has_permissions(administrator=True) async def organize_channels(self, ctx: commands.Context) -> None: guild = ctx.guild mapping = { "general": "💬・المجتمع", "chat": "💬・المجتمع", "suggest": "💬・المجتمع", "ticket": "🛠️・الدعم", "support": "🛠️・الدعم", "report": "🛠️・الدعم", "log": "📌・الإدارة", "rule": "📌・الإدارة", "welcome": "📌・الإدارة", "verify": "📌・الإدارة", "game": "🎮・Gaming Hub", "lfg": "🎮・Gaming Hub", "voice": "🔊・Gaming Voice", "vc": "🔊・Gaming Voice", } moved = 0 for channel in guild.channels: if isinstance(channel, discord.CategoryChannel): continue lower = channel.name.lower() target_name = None for keyword, category_name in mapping.items(): if keyword in lower: target_name = category_name break if not target_name: target_name = "💬・المجتمع" if isinstance(channel, discord.TextChannel) else "🔊・Gaming Voice" target = await self.ensure_category(guild, target_name) if channel.category_id != target.id: await channel.edit(category=target) moved += 1 await ctx.reply(f"🗂️ Organized **{moved}** channels under suitable categories.") async def setup(bot: commands.Bot) -> None: await bot.add_cog(ServerManager(bot))