From f11dd169d794e0869e34f9d1fb8f6d537127ac3b Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 22 Sep 2018 11:50:59 +0200 Subject: [PATCH] Improved and fixed hooks. --- src/org/april/hebdobot/bot/Hebdobot.java | 12 +++- .../hebdobot/bot/hooks/BadCommandHook.java | 56 ++++++++++++++++++ .../april/hebdobot/bot/hooks/CurrentHook.java | 4 +- .../april/hebdobot/bot/hooks/DefaultHook.java | 10 +--- .../hebdobot/bot/hooks/InputReviewHook.java | 58 +++++++++++++++++++ .../april/hebdobot/bot/hooks/MissingHook.java | 2 +- .../april/hebdobot/bot/hooks/StatsHook.java | 2 +- .../april/hebdobot/bot/hooks/StatusHook.java | 3 +- .../hebdobot/bot/hooks/StopReviewHook.java | 2 +- 9 files changed, 131 insertions(+), 18 deletions(-) create mode 100644 src/org/april/hebdobot/bot/hooks/BadCommandHook.java create mode 100644 src/org/april/hebdobot/bot/hooks/InputReviewHook.java diff --git a/src/org/april/hebdobot/bot/Hebdobot.java b/src/org/april/hebdobot/bot/Hebdobot.java index ffda692..43d1a6b 100644 --- a/src/org/april/hebdobot/bot/Hebdobot.java +++ b/src/org/april/hebdobot/bot/Hebdobot.java @@ -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()); } diff --git a/src/org/april/hebdobot/bot/hooks/BadCommandHook.java b/src/org/april/hebdobot/bot/hooks/BadCommandHook.java new file mode 100644 index 0000000..dd2fb27 --- /dev/null +++ b/src/org/april/hebdobot/bot/hooks/BadCommandHook.java @@ -0,0 +1,56 @@ +/** + * Copyright (C) 2018 Christian Pierre MOMON + * + * 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 + */ +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; + } +} diff --git a/src/org/april/hebdobot/bot/hooks/CurrentHook.java b/src/org/april/hebdobot/bot/hooks/CurrentHook.java index c4d8ab7..a43b0eb 100644 --- a/src/org/april/hebdobot/bot/hooks/CurrentHook.java +++ b/src/org/april/hebdobot/bot/hooks/CurrentHook.java @@ -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 { diff --git a/src/org/april/hebdobot/bot/hooks/DefaultHook.java b/src/org/april/hebdobot/bot/hooks/DefaultHook.java index 7421737..45624ad 100644 --- a/src/org/april/hebdobot/bot/hooks/DefaultHook.java +++ b/src/org/april/hebdobot/bot/hooks/DefaultHook.java @@ -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; diff --git a/src/org/april/hebdobot/bot/hooks/InputReviewHook.java b/src/org/april/hebdobot/bot/hooks/InputReviewHook.java new file mode 100644 index 0000000..3254ad4 --- /dev/null +++ b/src/org/april/hebdobot/bot/hooks/InputReviewHook.java @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2018 Christian Pierre MOMON + * + * 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 + */ +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; + } +} diff --git a/src/org/april/hebdobot/bot/hooks/MissingHook.java b/src/org/april/hebdobot/bot/hooks/MissingHook.java index d0a92dc..421c76b 100644 --- a/src/org/april/hebdobot/bot/hooks/MissingHook.java +++ b/src/org/april/hebdobot/bot/hooks/MissingHook.java @@ -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 { diff --git a/src/org/april/hebdobot/bot/hooks/StatsHook.java b/src/org/april/hebdobot/bot/hooks/StatsHook.java index d4d6baf..9c682d4 100644 --- a/src/org/april/hebdobot/bot/hooks/StatsHook.java +++ b/src/org/april/hebdobot/bot/hooks/StatsHook.java @@ -43,7 +43,7 @@ public class StatsHook extends Hook { boolean result; - if (message.equals("!statut")) + if (message.equals("!stats")) { logger.info("!stats caught."); diff --git a/src/org/april/hebdobot/bot/hooks/StatusHook.java b/src/org/april/hebdobot/bot/hooks/StatusHook.java index e30aaf5..9dbef62 100644 --- a/src/org/april/hebdobot/bot/hooks/StatusHook.java +++ b/src/org/april/hebdobot/bot/hooks/StatusHook.java @@ -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."); diff --git a/src/org/april/hebdobot/bot/hooks/StopReviewHook.java b/src/org/april/hebdobot/bot/hooks/StopReviewHook.java index 20210bb..3dc055a 100644 --- a/src/org/april/hebdobot/bot/hooks/StopReviewHook.java +++ b/src/org/april/hebdobot/bot/hooks/StopReviewHook.java @@ -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 {