|
13 | 13 |
|
14 | 14 | __all__ = ("AdminCommands", "setup") |
15 | 15 |
|
16 | | -from byte_bot.byte.lib.checks import is_byte_dev |
17 | 16 | from byte_bot.byte.lib import settings |
| 17 | +from byte_bot.byte.lib.checks import is_byte_dev |
18 | 18 | from byte_bot.byte.lib.log import get_logger |
19 | 19 | from byte_bot.server.lib.settings import ServerSettings |
20 | 20 |
|
@@ -101,47 +101,47 @@ async def tree_sync(self, interaction: Interaction) -> None: |
101 | 101 | @is_byte_dev() |
102 | 102 | async def bootstrap_guild(self, ctx: Context, guild_id: int | None = None) -> None: |
103 | 103 | """Bootstrap an existing guild to the database. |
104 | | - |
| 104 | +
|
105 | 105 | Args: |
106 | 106 | ctx: Context object. |
107 | 107 | guild_id: Guild ID to bootstrap. If not provided, uses current guild. |
108 | 108 | """ |
109 | 109 | guild = await self._get_target_guild(ctx, guild_id) |
110 | 110 | if not guild: |
111 | 111 | return |
112 | | - |
| 112 | + |
113 | 113 | await ctx.send(f"🔄 Bootstrapping guild {guild.name} (ID: {guild.id})...") |
114 | | - |
| 114 | + |
115 | 115 | await self._sync_guild_commands(guild) |
116 | 116 | await self._register_guild_in_database(ctx, guild) |
117 | 117 |
|
118 | 118 | async def _get_target_guild(self, ctx: Context, guild_id: int | None) -> discord.Guild | None: |
119 | 119 | """Get the target guild for bootstrapping.""" |
120 | 120 | target_guild_id = guild_id or (ctx.guild.id if ctx.guild else None) |
121 | | - |
| 121 | + |
122 | 122 | if not target_guild_id: |
123 | 123 | await ctx.send("❌ No guild ID provided and command not used in a guild.") |
124 | 124 | return None |
125 | | - |
| 125 | + |
126 | 126 | guild = self.bot.get_guild(target_guild_id) |
127 | 127 | if not guild: |
128 | 128 | await ctx.send(f"❌ Bot is not in guild with ID {target_guild_id}") |
129 | 129 | return None |
130 | | - |
| 130 | + |
131 | 131 | return guild |
132 | 132 |
|
133 | 133 | async def _sync_guild_commands(self, guild: discord.Guild) -> None: |
134 | 134 | """Sync commands to the guild.""" |
135 | 135 | try: |
136 | 136 | await self.bot.tree.sync(guild=guild) |
137 | 137 | logger.info("Commands synced to guild %s (id: %s)", guild.name, guild.id) |
138 | | - except Exception as e: |
139 | | - logger.error("Failed to sync commands to guild %s: %s", guild.name, e) |
| 138 | + except Exception: |
| 139 | + logger.exception("Failed to sync commands to guild %s", guild.name) |
140 | 140 |
|
141 | 141 | async def _register_guild_in_database(self, ctx: Context, guild: discord.Guild) -> None: |
142 | 142 | """Register guild in database via API.""" |
143 | 143 | api_url = f"http://{server_settings.HOST}:{server_settings.PORT}/api/guilds/create?guild_id={guild.id}&guild_name={guild.name}" |
144 | | - |
| 144 | + |
145 | 145 | try: |
146 | 146 | async with httpx.AsyncClient() as client: |
147 | 147 | response = await client.post(api_url) |
@@ -180,11 +180,11 @@ async def _notify_dev_channel(self, guild: discord.Guild) -> None: |
180 | 180 | dev_guild = self.bot.get_guild(settings.discord.DEV_GUILD_ID) |
181 | 181 | if not dev_guild: |
182 | 182 | return |
183 | | - |
| 183 | + |
184 | 184 | dev_channel = dev_guild.get_channel(settings.discord.DEV_GUILD_INTERNAL_ID) |
185 | 185 | if not dev_channel or not hasattr(dev_channel, "send"): |
186 | 186 | return |
187 | | - |
| 187 | + |
188 | 188 | embed = discord.Embed( |
189 | 189 | title="Guild Bootstrapped", |
190 | 190 | description=f"Guild {guild.name} (ID: {guild.id}) was manually bootstrapped", |
|
0 commit comments