Esempio n. 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());
        }
      }
    }
  }
Esempio n. 2
0
 @Command("\\.rev")
 public void rev(CommandContext ctx) {
   final Git.Revision rev = this.bot.revision;
   ctx.respond(
       "Currently on revision %(#hash)s by %(#author)s -- %(#description)s",
       rev.getHash(), rev.getAuthor(), rev.getDescription());
   ctx.respond("%s", Git.revisionLink(rev));
 }
Esempio n. 3
0
  @Command(value = "(?:\\.help|:question:) (.+)", allowPM = true)
  public JSONObject specific(CommandContext ctx, String search)
      throws JSONException, InvocationTargetException {
    // First, try module names
    for (NoiseModule module : this.bot.getModules().values()) {
      if (!module.showInHelp()) {
        continue;
      }
      if (search.equalsIgnoreCase(module.getFriendlyName())) {
        return new JSONObject()
            .put("name", module.getFriendlyName())
            .put("description", module.getDescription())
            .put("examples", module.getExamples());
      }
    }

    // Then try command pattern matching. This depends on BotUtils
    final NoiseModule botUtilsModule = this.bot.getModules().get("BotUtils");
    if (botUtilsModule != null) {
      final MessageResult result =
          botUtilsModule.processMessage(ctx.deriveMessage(".which " + search));
      final String[] modules = result.data.get().getStringArray("modules");
      if (modules.length > 0) {
        // TODO Show all modules if the command matches more than one?
        return this.specific(ctx, modules[0]);
      }
    }

    return new JSONObject().put("error", "Unknown module: " + search);
  }
Esempio n. 4
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());
       }
     }
   }
 }
Esempio n. 5
0
 @Command("\\.sync")
 public void sync(CommandContext ctx) {
   try {
     Git.attemptUpdate();
     // attemptUpdate() will call NoiseBot.syncAll(), which handles outputting sync info to all
     // channels
   } catch (Git.SyncException e) {
     // Only output the error to the channel/user that requested the sync
     ctx.respond("#error %s", e.getMessage());
   }
 }
Esempio n. 6
0
 @Command("\\.owner\\?")
 public void isOwner(CommandContext ctx) {
   this.triggerIfOwner(ctx, () -> ctx.respond("#success You own this NoiseBot"), true);
 }