@Override public String process(MessageUpdate update) { StringBuilder response = new StringBuilder(); try { if (canProcess(update.getMessage().getText()) && !update.isEdited()) { List<String> itens = Arrays.asList(update.getMessage().getText().replaceAll("\\r|\\n", " ").split(" ")); HashMap<String, String> finalTargets = new HashMap<>(); String username = update.getMessage().getFrom().getUsername() != null ? update.getMessage().getFrom().getUsername() : update.getMessage().getFrom().getFirstName().toLowerCase(); itens.stream().distinct().forEach(item -> { if ((KARMA_PATTERN.matcher(item).find())) { finalTargets.putIfAbsent(item.substring(0, item.length() - 2).toLowerCase(), item.substring(item.length() - 2)); } }); for (Map.Entry<String, String> entry : finalTargets.entrySet()) { response.append(processKarma(entry.getValue(), entry.getKey(), username)); } } else { log.fine("Message " + update.getMessage().getText() + " is a updated message, ignoring..."); } } catch (final Exception e) { e.printStackTrace(); log.warning(e.getMessage()); } return response.toString(); }
public String registerNotification(MessageUpdate message) { String channel = null; if (message.getMessage().getChat().getType().equals("group") || message.getMessage().getChat().getType().equals("supergroup")) { channel = message.getMessage().getChat().getTitle(); } else { channel = message.getMessage().getFrom().getFirstName(); } return repository.register(new PacktNotification(message.getMessage().getChat().getId(), channel)); }
public String unregisterNotification(MessageUpdate message) { String channel = null; if (message.getMessage().getChat().getType().equals("group") || message.getMessage().getChat().getType().equals("supergroup")) { channel = message.getMessage().getChat().getTitle(); } else { channel = message.getMessage().getFrom().getFirstName(); } return repository.unregister(new PacktNotification(message.getMessage().getChat().getId(), channel)); }