|
22 | 22 | from core import checks
|
23 | 23 | from core.models import PermissionLevel
|
24 | 24 | from core.paginator import EmbedPaginatorSession
|
25 |
| -from core.utils import truncate |
| 25 | +from core.utils import truncate, trigger_typing |
26 | 26 |
|
27 | 27 | logger = logging.getLogger("Modmail")
|
28 | 28 |
|
@@ -235,6 +235,14 @@ async def load_plugin(self, plugin):
|
235 | 235 |
|
236 | 236 | async def parse_user_input(self, ctx, plugin_name, check_version=False):
|
237 | 237 |
|
| 238 | + if not self._ready_event.is_set(): |
| 239 | + embed = discord.Embed( |
| 240 | + description="Plugins are still loading, please try again later.", |
| 241 | + color=self.bot.main_color, |
| 242 | + ) |
| 243 | + await ctx.send(embed=embed) |
| 244 | + return |
| 245 | + |
238 | 246 | if plugin_name in self.registry:
|
239 | 247 | details = self.registry[plugin_name]
|
240 | 248 | user, repo = details["repository"].split("/", maxsplit=1)
|
@@ -281,6 +289,7 @@ async def plugins(self, ctx):
|
281 | 289 |
|
282 | 290 | @plugins.command(name="add", aliases=["install", "load"])
|
283 | 291 | @checks.has_permissions(PermissionLevel.OWNER)
|
| 292 | + @trigger_typing |
284 | 293 | async def plugins_add(self, ctx, *, plugin_name: str):
|
285 | 294 | """
|
286 | 295 | Install a new plugin for the bot.
|
@@ -313,53 +322,51 @@ async def plugins_add(self, ctx, *, plugin_name: str):
|
313 | 322 | )
|
314 | 323 | msg = await ctx.send(embed=embed)
|
315 | 324 |
|
316 |
| - async with ctx.typing(): |
317 |
| - try: |
318 |
| - await self.download_plugin(plugin, force=True) |
319 |
| - except Exception: |
320 |
| - logger.warning(f"Unable to download plugin %s.", plugin, exc_info=True) |
321 |
| - |
322 |
| - embed = discord.Embed( |
323 |
| - description=f"Failed to download plugin, check logs for error.", |
324 |
| - color=self.bot.error_color, |
325 |
| - ) |
326 |
| - |
327 |
| - return await msg.edit(embed=embed) |
| 325 | + try: |
| 326 | + await self.download_plugin(plugin, force=True) |
| 327 | + except Exception: |
| 328 | + logger.warning(f"Unable to download plugin %s.", plugin, exc_info=True) |
328 | 329 |
|
329 |
| - self.bot.config["plugins"].append(str(plugin)) |
330 |
| - await self.bot.config.update() |
| 330 | + embed = discord.Embed( |
| 331 | + description=f"Failed to download plugin, check logs for error.", |
| 332 | + color=self.bot.error_color, |
| 333 | + ) |
331 | 334 |
|
332 |
| - if self.bot.config.get("enable_plugins"): |
| 335 | + return await msg.edit(embed=embed) |
333 | 336 |
|
334 |
| - invalidate_caches() |
| 337 | + self.bot.config["plugins"].append(str(plugin)) |
| 338 | + await self.bot.config.update() |
335 | 339 |
|
336 |
| - try: |
337 |
| - await self.load_plugin(plugin) |
338 |
| - except Exception: |
339 |
| - logger.warning(f"Unable to load plugin %s.", plugin, exc_info=True) |
| 340 | + if self.bot.config.get("enable_plugins"): |
340 | 341 |
|
341 |
| - embed = discord.Embed( |
342 |
| - description=f"Failed to download plugin, check logs for error.", |
343 |
| - color=self.bot.error_color, |
344 |
| - ) |
| 342 | + invalidate_caches() |
345 | 343 |
|
346 |
| - return await msg.edit(embed=embed) |
| 344 | + try: |
| 345 | + await self.load_plugin(plugin) |
| 346 | + except Exception: |
| 347 | + logger.warning(f"Unable to load plugin %s.", plugin, exc_info=True) |
347 | 348 |
|
348 | 349 | embed = discord.Embed(
|
349 |
| - description="Successfully installed plugin.\n" |
350 |
| - "*Friendly reminder, plugins have absolute control over your bot. " |
351 |
| - "Please only install plugins from developers you trust.*", |
352 |
| - color=self.bot.main_color, |
| 350 | + description=f"Failed to download plugin, check logs for error.", |
| 351 | + color=self.bot.error_color, |
353 | 352 | )
|
| 353 | + |
354 | 354 | else:
|
355 | 355 | embed = discord.Embed(
|
356 | 356 | description="Successfully installed plugin.\n"
|
357 | 357 | "*Friendly reminder, plugins have absolute control over your bot. "
|
358 |
| - "Please only install plugins from developers you trust.*\n\n" |
359 |
| - "This plugin is currently not enabled due to `ENABLE_PLUGINS=false`, " |
360 |
| - "to re-enable plugins, remove or change `ENABLE_PLUGINS=true` and restart your bot.", |
| 358 | + "Please only install plugins from developers you trust.*", |
361 | 359 | color=self.bot.main_color,
|
362 | 360 | )
|
| 361 | + else: |
| 362 | + embed = discord.Embed( |
| 363 | + description="Successfully installed plugin.\n" |
| 364 | + "*Friendly reminder, plugins have absolute control over your bot. " |
| 365 | + "Please only install plugins from developers you trust.*\n\n" |
| 366 | + "This plugin is currently not enabled due to `ENABLE_PLUGINS=false`, " |
| 367 | + "to re-enable plugins, remove or change `ENABLE_PLUGINS=true` and restart your bot.", |
| 368 | + color=self.bot.main_color, |
| 369 | + ) |
363 | 370 | return await msg.edit(embed=embed)
|
364 | 371 |
|
365 | 372 | @plugins.command(name="remove", aliases=["del", "delete"])
|
@@ -390,6 +397,15 @@ async def plugins_remove(self, ctx, *, plugin_name: str):
|
390 | 397 |
|
391 | 398 | self.bot.config["plugins"].remove(str(plugin))
|
392 | 399 | await self.bot.config.update()
|
| 400 | + shutil.rmtree( |
| 401 | + plugin.abs_path, |
| 402 | + onerror=lambda *args: logger.warning('Failed to remove plugin files %s: %s', plugin, str(args[2])) |
| 403 | + ) |
| 404 | + try: |
| 405 | + plugin.abs_path.parent.rmdir() |
| 406 | + plugin.abs_path.parent.parent.rmdir() |
| 407 | + except OSError: |
| 408 | + pass # dir not empty |
393 | 409 |
|
394 | 410 | embed = discord.Embed(
|
395 | 411 | description="The plugin is successfully uninstalled.",
|
|
0 commit comments