Added cancel previous input hook.
This commit is contained in:
parent
77d501937a
commit
12fe4ede50
6 changed files with 146 additions and 1 deletions
|
@ -27,6 +27,7 @@ import java.time.LocalTime;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.april.hebdobot.HebdobotException;
|
||||
import org.april.hebdobot.bot.hooks.BadCommandHook;
|
||||
import org.april.hebdobot.bot.hooks.CancelPreviousInputHook;
|
||||
import org.april.hebdobot.bot.hooks.CollectiveSubjectHook;
|
||||
import org.april.hebdobot.bot.hooks.CommentHook;
|
||||
import org.april.hebdobot.bot.hooks.CurrentHook;
|
||||
|
@ -147,6 +148,7 @@ public class Hebdobot extends PircBot
|
|||
this.hooker.add(new StopReviewHook());
|
||||
this.hooker.add(new StatsHook());
|
||||
this.hooker.add(new StatusHook());
|
||||
this.hooker.add(new CancelPreviousInputHook());
|
||||
|
||||
this.hooker.add(new DateHook());
|
||||
this.hooker.add(new HelloHook());
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
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 CancelPreviousInputHook.
|
||||
*/
|
||||
public class CancelPreviousInputHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(CancelPreviousInputHook.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(sender + ", pas de revue en cours.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Topic topic = bot.getReview().getCurrentTopic();
|
||||
if (topic == null)
|
||||
{
|
||||
bot.sendMessage("Pas de sujet en cours.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bot.getReview().getParticipants().contains(sender))
|
||||
{
|
||||
topic.cancelPreviousMessage(sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.sendMessage("Vous n'avez pas d'entrée en cours.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -52,6 +52,19 @@ public class CollectiveTopic extends Topic
|
|||
this.messages.add(message);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.april.hebdobot.bot.review.Topic#cancelPrevious(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void cancelPreviousMessage(final String author)
|
||||
{
|
||||
Message previousMessage = this.messages.getByAuthor(author).getLast();
|
||||
if (previousMessage != null)
|
||||
{
|
||||
this.messages.remove(previousMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the messages.
|
||||
*
|
||||
|
|
|
@ -58,6 +58,19 @@ public class IndividualTopic extends Topic
|
|||
this.messages.get(author).add(message);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.april.hebdobot.bot.review.Topic#cancelPrevious(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void cancelPreviousMessage(final String participant)
|
||||
{
|
||||
Messages authorMessages = this.messages.get(participant);
|
||||
if (authorMessages != null)
|
||||
{
|
||||
authorMessages.removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the messages.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* This file is part of (April) Hebdobot.
|
||||
*
|
||||
|
@ -20,6 +20,8 @@ package org.april.hebdobot.bot.review;
|
|||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* The Class MessageLinkedList.
|
||||
*/
|
||||
|
@ -34,4 +36,29 @@ public class Messages extends LinkedList<Message>
|
|||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the by author.
|
||||
*
|
||||
* @param author
|
||||
* the author
|
||||
* @return the by author
|
||||
*/
|
||||
public Messages getByAuthor(final String author)
|
||||
{
|
||||
Messages result;
|
||||
|
||||
result = new Messages();
|
||||
|
||||
for (Message message : this)
|
||||
{
|
||||
if (StringUtils.equals(message.getAuthor(), author))
|
||||
{
|
||||
result.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,14 @@ public abstract class Topic
|
|||
*/
|
||||
public abstract void add(Message message);
|
||||
|
||||
/**
|
||||
* Cancel previous.
|
||||
*
|
||||
* @param participant
|
||||
* the participant
|
||||
*/
|
||||
public abstract void cancelPreviousMessage(final String participant);
|
||||
|
||||
/**
|
||||
* Gets the participants.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue