91 lines
3.0 KiB
Java
91 lines
3.0 KiB
Java
/**
|
|
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
|
*
|
|
* 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 <http://www.gnu.org/licenses/>
|
|
*/
|
|
package org.april.hebdobot.bot.hooks;
|
|
|
|
import java.util.Collection;
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.april.hebdobot.bot.Hebdobot;
|
|
import org.april.hebdobot.bot.review.Topic;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* The Class MissingHook.
|
|
*/
|
|
public class MissingHook extends Hook
|
|
{
|
|
private static final Logger logger = LoggerFactory.getLogger(MissingHook.class);
|
|
|
|
/* (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;
|
|
|
|
if (StringUtils.equalsIgnoreCase(message, "!manquants"))
|
|
{
|
|
logger.info("!manquants caught.");
|
|
|
|
// Missing.
|
|
if (bot.getReview() == null)
|
|
{
|
|
bot.sendMessage("Pas de revue en cours.");
|
|
}
|
|
else
|
|
{
|
|
Topic topic = bot.getReview().getCurrentTopic();
|
|
if (topic == null)
|
|
{
|
|
bot.sendMessage("Aucun sujet traité");
|
|
}
|
|
else
|
|
{
|
|
Collection<String> participants = bot.getReview().getParticipants();
|
|
Collection<String> currentParticipants = topic.getParticipants();
|
|
|
|
Collection<String> missing = CollectionUtils.subtract(participants, currentParticipants);
|
|
if (missing.isEmpty())
|
|
{
|
|
bot.sendMessage("Aucun participant manquant \\o/");
|
|
}
|
|
else
|
|
{
|
|
bot.sendMessage(
|
|
String.format("Les personnes participantes suivantes sont manquantes : %1s", StringUtils.join(missing, ", ")));
|
|
}
|
|
}
|
|
}
|
|
|
|
result = true;
|
|
}
|
|
else
|
|
{
|
|
result = false;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|