@Override public void process(IncomeMessage message) { List<Karma> result = repository.search(message.command().as(String.class)); if (result.isEmpty()) { message.reply("[e]No karma found[/e]"); } else { message.reply(result.stream() .map(Karma::message) .collect(Collectors.joining("\n"))); } }
@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(); }
/** * Returns a predicate that allows commands that have the given name. * * @param commandName the allowed name * @return a predicate that allows commands that have the given name. */ public static Predicate<IncomeMessage> command(String commandName) { return message -> hasCommand() .and(new AcceptedValuePredicate<>(commandName.toLowerCase(), m -> m.command().name().toLowerCase())) .test(message); }
@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() .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) { String token = message.command().as(String.class); if (this.requestManager.confirm(token)) { message.reply("Confirmation OK!"); } else { message.reply("[e]Invalid token[/e]"); } } }
@Override public void process(IncomeMessage message) { message.command() .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 user = request.user(); user.removeDestination(request.channel()); message.reply("The destination was removed from your user."); }) .on("default", channel -> { User user = message.user(); if (user == null) { message.reply("Your new primary destination was saved!"); }) .execute();
@Override public void process(IncomeMessage message) { message.command().as(LookupCommand.class) .lookup() .and(message::reply) .orElseThrow(() -> new MessageProcessingException("Definition not found")); }
@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")); }