/** * Formats the message using the given format and arguments and then * uses the produced content as the {@link #sendBack(String) reply to sender}. * * @param format the format of the message * @param args the arguments to format the message */ default void sendBack(String format, Object... args) { sendBack(String.format(format, args)); }
/** * Wraps the given content as a {@link Sendable} and sends it back to the same channel. * * @param content the content to reply */ default void sendBack(String content) { sendBack(Sendable.message(content)); }
@Override public void process(IncomeMessage message) { Matcher matcher = pattern.matcher(message.content()); StringBuilder replyMessage = new StringBuilder(); Set<String> evaluated = new HashSet<>(); while (matcher.find()) { String term = matcher.group("term"); String operation = matcher.group("operation"); if (!evaluated.contains(term.toLowerCase())) { int value = update(term, operation); replyMessage.append(buildReplyMessage(term, value)).append("\n"); evaluated.add(term.toLowerCase()); } } if (replyMessage.length() > 0) { // remove the last \n replyMessage.deleteCharAt(replyMessage.length() - 1); message.sendBack(replyMessage.toString()); } }