hebdobot/src/org/april/hebdobot/bot/hooks/CancelPreviousInputHook.java

108 lines
3.4 KiB
Java
Raw Normal View History

2021-01-30 20:12:01 +01:00
/**
* Copyright (C) 2019-2021 Christian Pierre MOMON <cmomon@april.org>
*
* This file is part of (April) Hebdobot.
*
* Hebdobot 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.
*
* Hebdobot 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 Hebdobot. If not, see <http://www.gnu.org/licenses/>
*/
package org.april.hebdobot.bot.hooks;
2021-04-17 01:17:40 +02:00
import org.april.hebdobot.HebdobotException;
2021-01-30 20:12:01 +01:00
import org.april.hebdobot.bot.Hebdobot;
import org.april.hebdobot.bot.review.Topic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2021-04-17 01:17:40 +02:00
import fr.devinsy.strings.StringList;
2021-04-13 20:23:48 +02:00
import fr.devinsy.strings.StringsUtils;
2021-01-30 20:12:01 +01:00
/**
* The Class CancelPreviousInputHook.
*/
public class CancelPreviousInputHook extends Hook
{
private static final Logger logger = LoggerFactory.getLogger(CancelPreviousInputHook.class);
2021-04-17 01:17:40 +02:00
/* (non-Javadoc)
* @see org.april.hebdobot.bot.hooks.Hook#attemptHelp(org.april.hebdobot.bot.Hebdobot, java.lang.String)
*/
@Override
public StringList attemptHelp(final String token) throws HebdobotException
{
StringList result;
if (StringsUtils.equalsAnyIgnoreCase(token, "cancelprevious", "oops", "oups"))
{
result = new StringList("!oups, !oops, !cancelprevious : annuler la dernière entrée dans un point de revue");
}
else
{
result = null;
}
//
return result;
}
2021-01-30 20:12:01 +01: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,
final String message)
{
boolean result;
2021-04-13 20:23:48 +02:00
if (StringsUtils.containsAnyIgnoreCase(message, "!cancelprevious", "!oops", "!oups"))
2021-01-30 20:12:01 +01:00
{
logger.info("!cancelprevious/!oops caught.");
2021-01-30 20:12:01 +01:00
// Missing.
if (bot.getReview() == null)
{
bot.sendMessage(sender + ", pas de revue en cours.");
}
else
{
Topic topic = bot.getReview().getCurrentTopic();
if (topic == null)
{
bot.sendMessage("Pas de sujet en cours.");
}
else
{
2021-04-13 20:23:48 +02:00
String previousMessage = topic.cancelPreviousMessage(sender);
if (previousMessage == null)
2021-01-30 20:12:01 +01:00
{
bot.sendMessage(sender + ", vous n'avez pas d'entrée en cours.");
2021-01-30 20:12:01 +01:00
}
else
{
bot.sendMessage(sender + ", suppression de votre précédente entrée : " + previousMessage);
2021-01-30 20:12:01 +01:00
}
}
}
result = true;
}
else
{
result = false;
}
//
return result;
}
}