Example #1
0
  @Command(value = "\\.unload(\\??) (" + MODULE_REGEX + ")", allowPM = false)
  public void unloadModules(CommandContext ctx, String qm, String moduleNames) {
    final boolean showErrors = qm.isEmpty();
    for (String moduleName : moduleNames.split(" ")) {
      // Don't allow unloading Core
      if (moduleName.equals(this.getClass().getSimpleName())) {
        this.bot.sendNoticeTo(
            ctx.getResponseTarget(),
            "#error .unload cannot unload the %(#module)s module",
            this.getFriendlyName());
        continue;
      }

      try {
        this.bot.unloadModule(moduleName, false);
        try {
          this.bot.saveModules();
        } catch (ModuleSaveException e) {
          Log.e(e);
        }

        this.bot.sendNoticeTo(ctx.getResponseTarget(), "Module %(#module)s unloaded", moduleName);
      } catch (ModuleUnloadException e) {
        Log.e(e);
        if (showErrors) {
          this.bot.sendNoticeTo(ctx.getResponseTarget(), "#error %s", e.getMessage());
        }
      }
    }
  }
Example #2
0
 @Command(value = "\\.reload(\\??) (" + MODULE_REGEX + ")", allowPM = false)
 public void reloadModules(CommandContext ctx, String qm, String moduleNames) {
   final boolean showErrors = qm.isEmpty();
   for (String moduleName : moduleNames.split(" ")) {
     try {
       if (this.bot.getModules().containsKey(moduleName)) {
         this.bot.reloadModule(moduleName);
         this.bot.sendNoticeTo(ctx.getResponseTarget(), "Module %(#module)s reloaded", moduleName);
       } else {
         this.bot.loadModule(moduleName);
         this.bot.sendNoticeTo(ctx.getResponseTarget(), "Module %(#module)s loaded", moduleName);
       }
     } catch (ModuleInitException | ModuleUnloadException e) {
       Log.e(e);
       if (showErrors) {
         this.bot.sendNoticeTo(ctx.getResponseTarget(), "#error %s", e.getMessage());
       }
     }
   }
 }