/** * Copyright (C) 2018 Christian Pierre MOMON * * This file is part of (April) Ememem. * * Ememem is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Ememem is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Ememem. If not, see */ package org.april.hebdobot.bot.hooks; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * The Class HelpByCommandHook. */ public class HelpByCommandHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(HelpByCommandHook.class); private static final Pattern PATTERN = Pattern.compile("^!help\\s+(\\S+)$"); /* (non-Javadoc) * @see org.april.hebdobot.bot.hooks.Hook#attemptProcess(org.april.hebdobot.bot.Hebdobot, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @Override public boolean attemptProcess(final Hebdobot bot, final String channel, final String sender, final String login, final String hostname, final String message) { boolean result; Matcher matcher = PATTERN.matcher(message); if (matcher.find()) { String command = matcher.group(1); if (StringUtils.equals(command, "help")) { bot.sendMessage(sender + ": help display help commands"); bot.sendMessage(sender + ": help command display help on specific command"); } else if (StringUtils.equals(command, "ignore")) { bot.sendMessage(sender + ": ignore host:service ignore a specific probe"); bot.sendMessage(sender + ": ignore list ignore probes"); } else if (StringUtils.equals(command, "unignore")) { bot.sendMessage(sender + ": unignore host:service ignore a specific probe"); } else if (StringUtils.equals(command, "ack")) { bot.sendMessage(sender + ": ack unack an alert"); } else if (StringUtils.equals(command, "unack")) { bot.sendMessage(sender + ": unack unack an alert"); } else if (StringUtils.equalsAnyIgnoreCase(command, "!mute", "!tagueule", "!ta gueule", "!chut", "!sieste")) { bot.sendMessage(sender + ": mute|tagueule|chut|sieste mute alert display"); } else if (StringUtils.equalsAnyIgnoreCase(command, "!unmute")) { bot.sendMessage(sender + ": unmute mute alert display"); } else if (StringUtils.equals(command, "list")) { bot.sendMessage(sender + ": list display current alerts"); } else if (StringUtils.equals(command, "refresh")) { bot.sendMessage(sender + ": refresh update alert list"); } else if (StringUtils.equals(command, "recheck")) { bot.sendMessage(sender + ": recheck reschedule current alerts"); } else { bot.sendMessage(sender + ": no help available for this command"); } result = true; } else { result = false; } // return result; } }