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;
|
|
|
|
|
|
|
|
import java.time.LocalTime;
|
|
|
|
|
|
|
|
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.april.hebdobot.bot.review.Review;
|
|
|
|
import org.quartz.SchedulerException;
|
|
|
|
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 StartReviewHook.
|
|
|
|
*/
|
|
|
|
public class StartReviewHook extends Hook
|
|
|
|
{
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(StartReviewHook.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, "début", "debut", "start"))
|
|
|
|
{
|
|
|
|
result = new StringList("!début, !debut, !start : commencer une nouvelle revue");
|
|
|
|
}
|
|
|
|
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,
|
|
|
|
final String message)
|
|
|
|
{
|
|
|
|
boolean result;
|
|
|
|
|
2019-05-02 13:05:36 +02:00
|
|
|
if (StringUtils.equalsAnyIgnoreCase(message, "!début", "!debut", "!start"))
|
2018-09-21 01:04:12 +02:00
|
|
|
{
|
|
|
|
logger.info("!debut caught.");
|
|
|
|
|
|
|
|
if ((bot.getReviewWaitTime() != null) && (LocalTime.now().isBefore(bot.getReviewWaitTime())))
|
|
|
|
{
|
|
|
|
bot.sendMessage(sender + ", ce n'est pas encore l'heure.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Start.
|
2019-05-03 16:18:27 +02:00
|
|
|
if (bot.getReview() != null)
|
2018-09-21 01:04:12 +02:00
|
|
|
{
|
2019-05-03 16:18:27 +02:00
|
|
|
bot.sendMessage("% " + sender + ", une revue est déjà en cours.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bot.getCronManager() != null)
|
2018-09-21 01:04:12 +02:00
|
|
|
{
|
2019-05-03 16:18:27 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
bot.getCronManager().shutdown();
|
|
|
|
}
|
|
|
|
catch (SchedulerException exception)
|
|
|
|
{
|
|
|
|
logger.warn("Scheduler shutdown failed.", exception);
|
|
|
|
}
|
2018-09-21 01:04:12 +02:00
|
|
|
}
|
2019-05-03 16:18:27 +02:00
|
|
|
bot.setReview(new Review(sender, bot.getAliases()));
|
|
|
|
bot.sendMessage(sender, "Bonjour " + sender + ", vous êtes le conducteur de réunion.");
|
|
|
|
bot.sendMessage(sender, "Pour terminer la réunion, tapez \"!fin\"");
|
2021-04-15 00:13:33 +02:00
|
|
|
bot.checkReviewAnniversary();
|
2019-05-03 16:18:27 +02:00
|
|
|
bot.sendMessage("% Début de la réunion hebdomadaire");
|
|
|
|
bot.sendMessage(
|
|
|
|
"% rappel : toute ligne commençant par % sera considérée comme un commentaire et non prise en compte dans la synthèse");
|
|
|
|
bot.sendMessage("% pour connaître le point courant, taper !courant");
|
2018-09-21 01:04:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|