Improved and fixed hooks.

This commit is contained in:
Christian P. MOMON 2018-09-22 11:50:59 +02:00
parent d52d358984
commit f11dd169d7
9 changed files with 131 additions and 18 deletions

View File

@ -26,6 +26,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.CollectiveSubjectHook;
import org.april.hebdobot.bot.hooks.CommentHook;
import org.april.hebdobot.bot.hooks.CurrentHook;
@ -36,6 +37,7 @@ import org.april.hebdobot.bot.hooks.HelloHook;
import org.april.hebdobot.bot.hooks.HelpHook;
import org.april.hebdobot.bot.hooks.HookManager;
import org.april.hebdobot.bot.hooks.IndividualSubjectHook;
import org.april.hebdobot.bot.hooks.InputReviewHook;
import org.april.hebdobot.bot.hooks.LicenseHook;
import org.april.hebdobot.bot.hooks.MissingHook;
import org.april.hebdobot.bot.hooks.StartReviewHook;
@ -122,10 +124,10 @@ public class Hebdobot extends PircBot
//
this.hooker = new HookManager();
this.hooker.add(new CollectiveSubjectHook());
this.hooker.add(new CommentHook());
this.hooker.add(new CurrentHook());
this.hooker.add(new DateHook());
this.hooker.add(new FinishReviewHook());
this.hooker.add(new HelpHook());
this.hooker.add(new IndividualSubjectHook());
@ -134,10 +136,14 @@ public class Hebdobot extends PircBot
this.hooker.add(new StopReviewHook());
this.hooker.add(new StatusHook());
this.hooker.add(new LicenseHook());
this.hooker.add(new VersionHook());
this.hooker.add(new DateHook());
this.hooker.add(new HelloHook());
this.hooker.add(new LicenseHook());
this.hooker.add(new ThanksHook());
this.hooker.add(new VersionHook());
this.hooker.add(new BadCommandHook());
this.hooker.add(new InputReviewHook());
this.hooker.add(new DefaultHook());
}

View File

@ -0,0 +1,56 @@
/**
* 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 org.april.hebdobot.bot.Hebdobot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class DefaultHook.
*/
public class BadCommandHook extends Hook
{
private static final Logger logger = LoggerFactory.getLogger(BadCommandHook.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 (message.matches("^!.*$"))
{
logger.info("!??? caught.");
bot.sendMessage(sender + ", Yo !");
result = true;
}
else
{
result = false;
}
//
return result;
}
}

View File

@ -42,14 +42,14 @@ public class CurrentHook extends Hook
{
boolean result;
if (StringUtils.equalsIgnoreCase(message, "!manquants"))
if (StringUtils.equalsIgnoreCase(message, "!courant"))
{
logger.info("!courant caught.");
// Current.
if (bot.getReview() == null)
{
bot.sendMessage("Pas de revue en cours.");
bot.sendMessage(sender + ", pas de revue en cours.");
}
else
{

View File

@ -38,15 +38,7 @@ public class DefaultHook extends Hook
{
boolean result;
if (message.matches("^!.*$"))
{
logger.info("!??? caught.");
bot.sendMessage(sender, "Yo !");
}
else
{
logger.info("All the other caught.");
}
logger.info("All the other caught.");
result = true;

View File

@ -0,0 +1,58 @@
/**
* 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 org.april.hebdobot.bot.Hebdobot;
import org.april.hebdobot.bot.review.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class DefaultHook.
*/
public class InputReviewHook extends Hook
{
private static final Logger logger = LoggerFactory.getLogger(InputReviewHook.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 (bot.getReview() == null)
{
result = false;
}
else
{
bot.getReview().add(new Message(sender, message));
result = true;
}
result = true;
//
return result;
}
}

View File

@ -50,7 +50,7 @@ public class MissingHook extends Hook
// Missing.
if (bot.getReview() == null)
{
bot.sendMessage("Pas de revue en cours.");
bot.sendMessage(sender + ", pas de revue en cours.");
}
else
{

View File

@ -43,7 +43,7 @@ public class StatsHook extends Hook
{
boolean result;
if (message.equals("!statut"))
if (message.equals("!stats"))
{
logger.info("!stats caught.");

View File

@ -18,6 +18,7 @@
*/
package org.april.hebdobot.bot.hooks;
import org.apache.commons.lang3.StringUtils;
import org.april.hebdobot.bot.Hebdobot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,7 +39,7 @@ public class StatusHook extends Hook
{
boolean result;
if (message.equals("!statut"))
if (StringUtils.equalsAnyIgnoreCase(message, "!status", "!statut"))
{
logger.info("!status caught.");

View File

@ -46,7 +46,7 @@ public class StopReviewHook extends Hook
// Stop.
if (bot.getReview() == null)
{
bot.sendMessage("Aucune revue en cours, abandon impossible.");
bot.sendMessage(sender + ", aucune revue en cours, abandon impossible.");
}
else
{