2018-09-21 01:04:12 +02:00
|
|
|
|
/**
|
2021-04-15 00:13:33 +02:00
|
|
|
|
* Copyright (C) 2018-2021 Christian Pierre MOMON <cmomon@april.org>
|
2018-09-21 01:04:12 +02:00
|
|
|
|
*
|
2018-11-07 14:01:29 +01:00
|
|
|
|
* This file is part of (April) Hebdobot.
|
2018-09-21 01:04:12 +02:00
|
|
|
|
*
|
2018-11-07 14:01:29 +01:00
|
|
|
|
* Hebdobot is free software: you can redistribute it and/or modify
|
2018-09-21 01:04:12 +02:00
|
|
|
|
* 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.
|
|
|
|
|
*
|
2018-11-07 14:01:29 +01:00
|
|
|
|
* Hebdobot is distributed in the hope that it will be useful,
|
2018-09-21 01:04:12 +02:00
|
|
|
|
* 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
|
2018-11-07 14:01:29 +01:00
|
|
|
|
* along with Hebdobot. If not, see <http://www.gnu.org/licenses/>
|
2018-09-21 01:04:12 +02:00
|
|
|
|
*/
|
|
|
|
|
package org.april.hebdobot.bot.hooks;
|
|
|
|
|
|
2021-04-17 01:17:40 +02:00
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
2018-09-21 01:04:12 +02:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2021-04-17 01:17:40 +02:00
|
|
|
|
import org.april.hebdobot.HebdobotException;
|
2018-09-21 01:04:12 +02:00
|
|
|
|
import org.april.hebdobot.bot.Hebdobot;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
2021-04-17 01:17:40 +02:00
|
|
|
|
import fr.devinsy.strings.StringList;
|
|
|
|
|
import fr.devinsy.strings.StringsUtils;
|
|
|
|
|
|
2018-09-21 01:04:12 +02:00
|
|
|
|
/**
|
|
|
|
|
* The Class HelpHook.
|
|
|
|
|
*/
|
|
|
|
|
public class HelpHook extends Hook
|
|
|
|
|
{
|
2021-04-17 01:17:40 +02:00
|
|
|
|
private static final Pattern COMMAND_HELP_PATTERN = Pattern.compile("^!(aide|help)\\s+(?<token>\\S+)$");
|
|
|
|
|
|
2018-09-21 01:04:12 +02:00
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(HelpHook.class);
|
|
|
|
|
|
2021-04-17 01:17:40 +02:00
|
|
|
|
/* (non-Javadoc)
|
|
|
|
|
* @see org.april.hebdobot.bot.hooks.Hook#attemptHelp(java.lang.String)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public StringList attemptHelp(final String token) throws HebdobotException
|
|
|
|
|
{
|
|
|
|
|
StringList result;
|
|
|
|
|
|
|
|
|
|
if (StringsUtils.equalsAnyIgnoreCase(token, "aide", "help"))
|
|
|
|
|
{
|
|
|
|
|
result = new StringList();
|
|
|
|
|
result.append("!aide, !help : afficher l'aide générale");
|
2021-04-21 16:12:03 +02:00
|
|
|
|
result.append("!aide commande, !help commande : afficher l'aide de la commande !commande");
|
2021-04-17 01:17:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-21 01:04:12 +02:00
|
|
|
|
/* (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,
|
2021-04-17 01:17:40 +02:00
|
|
|
|
final String message) throws HebdobotException
|
2018-09-21 01:04:12 +02:00
|
|
|
|
{
|
|
|
|
|
boolean result;
|
|
|
|
|
|
|
|
|
|
if (StringUtils.equalsAnyIgnoreCase(message, "!aide", "!help"))
|
|
|
|
|
{
|
|
|
|
|
logger.info("!help caught.");
|
|
|
|
|
|
|
|
|
|
// Help.
|
2021-04-16 19:35:37 +02:00
|
|
|
|
bot.sendMessage(sender,
|
|
|
|
|
String.format("Bienvenue %s. Je suis %s, le robot de gestion des revues hebdomadaires de l'April.", sender, bot.getName()));
|
2018-09-21 01:04:12 +02:00
|
|
|
|
bot.sendMessage(sender, "Voici les commandes que je comprends :");
|
|
|
|
|
bot.sendMessage(sender, " ");
|
2021-04-21 16:12:03 +02:00
|
|
|
|
bot.sendMessage(sender, " !aide,!help : afficher cette aide");
|
|
|
|
|
bot.sendMessage(sender, " !aide commande : afficher l'aide de la commande !commande");
|
|
|
|
|
bot.sendMessage(sender, " !début : commencer une nouvelle revue");
|
|
|
|
|
bot.sendMessage(sender, " % message : traiter comme un commentaire");
|
|
|
|
|
bot.sendMessage(sender, " # titre : démarrer un sujet individuel");
|
|
|
|
|
bot.sendMessage(sender, " ## titre : démarrer un sujet collectif");
|
|
|
|
|
bot.sendMessage(sender, " !oups : annuler la dernière entrée dans un point de revue");
|
|
|
|
|
bot.sendMessage(sender, " !courant : afficher le sujet en cours");
|
|
|
|
|
bot.sendMessage(sender, " !fin : terminer la revue en cours");
|
|
|
|
|
bot.sendMessage(sender, " !stop : abandonner la revue en cours");
|
2018-09-21 01:04:12 +02:00
|
|
|
|
bot.sendMessage(sender, " ");
|
2021-04-18 01:25:59 +02:00
|
|
|
|
bot.sendMessage(sender,
|
|
|
|
|
"Autres commandes : !anniv, !bonjour, !chrono, !date, !hello, !licence, !manquants, !merci, !record, !salut, !stats, !status, !version");
|
2018-09-21 01:04:12 +02:00
|
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-17 01:17:40 +02:00
|
|
|
|
String token = extractTargetHelp(message);
|
|
|
|
|
|
|
|
|
|
if (token == null)
|
|
|
|
|
{
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
StringList help = bot.getHelp(token);
|
|
|
|
|
if (help == null)
|
|
|
|
|
{
|
|
|
|
|
bot.sendMessage("aide indisponible pour la commande " + token);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (String line : help)
|
|
|
|
|
{
|
|
|
|
|
bot.sendMessage(line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extract target help.
|
|
|
|
|
*
|
|
|
|
|
* @return the string
|
|
|
|
|
*/
|
|
|
|
|
private String extractTargetHelp(final String message)
|
|
|
|
|
{
|
|
|
|
|
String result;
|
|
|
|
|
|
|
|
|
|
Matcher matcher = COMMAND_HELP_PATTERN.matcher(message);
|
|
|
|
|
if (matcher.find())
|
|
|
|
|
{
|
|
|
|
|
result = matcher.group("token");
|
|
|
|
|
|
|
|
|
|
if (StringUtils.startsWith(result, "!"))
|
|
|
|
|
{
|
|
|
|
|
result = result.substring(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = null;
|
2018-09-21 01:04:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-04-17 01:17:40 +02:00
|
|
|
|
|
2018-09-21 01:04:12 +02:00
|
|
|
|
}
|