/** * Formats the message using the given format and arguments and then * uses the produced content as the {@link #reply(String) reply}. * * @param format the format of the message * @param args the arguments to format the message */ default void reply(String format, Object... args) { reply(String.format(format, args)); }
public ExtractedCommand(IncomeMessage incomeMessage, String name, String rawArguments) { this.incomeMessage = incomeMessage; this.name = name; this.rawArguments = rawArguments; this.actions = new HashMap<>(); this.defaultAction = string -> this.incomeMessage.reply("Invalid action, possible actions: \n" + actions.keySet().stream().collect(Collectors.joining("\n"))); }
/** * Wraps the given content as a {@link Sendable} and sends it as a reply to this message * * @param content the content to reply */ default void reply(String content) { reply(Sendable.message(content)); }
@Override public void orElseReturn(String message) { orElse((string) -> this.incomeMessage.reply(message)); }
@Override public void process(IncomeMessage message) { message.command() .on("ignore", nickname -> { this.ignoreList.add(nickname); message.reply("Added to ignore list"); }) .on("accept", nickname -> { this.ignoreList.remove(nickname); message.reply("Removed from ignore list"); }) .on("ignored", () -> message.reply(this.ignoreList.list().stream().collect(Collectors.joining("\n")))) .execute(); }
@Override public void process(IncomeMessage message) { message.command() .on("enabled", String.class, (name) -> { boolean active = activator.isEnabled(name, message.location()); if (active) { message.reply("[p]Yes, the plugin is enabled for this channel[/p]"); } else { message.reply("[n]No, the plugin is disabled for this channel[/n]"); } }) .on("disable", List.class, (plugins) -> { plugins.forEach(name -> activator.disable(name.toString(), message.location())); message.reply("Plugin(s) disabled successfully!"); }) .on("enable", List.class, (plugins) -> { plugins.forEach(name -> activator.enable(name.toString(), message.location())); message.reply("Plugin(s) enabled successfully!"); }).execute(); }
@Override public void process(IncomeMessage message) { Fact fact = message.command().as(FactRequest.class).fetch(); message.reply(fact); }
@Override public void process(IncomeMessage message) { message.command().as(WeatherCommand.class).search() .and(weather -> message.reply(buildResponse(weather))) .orElseThrow(() -> new MessageProcessingException("No weather forecast found")); }
.on("new", userId -> { userManager.create(userId, message.location()); message.reply("User created"); }) .on("link", LinkRequest.class, request -> { userManager.link(message, request.userId(), request.channel(), request.target()); message.reply("Link requested and will be effective after confirmation."); }) .on("unlink", UnlinkRequest.class, request -> { user.removeDestination(request.channel()); this.repository.update(user); message.reply("The destination was removed from your user."); }) .on("default", channel -> { message.reply("Your new primary destination was saved!"); }) .execute();