Ejemplo n.º 1
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);
  }