From d7093286662599a02309677315aa79a868f92c4a Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sat, 17 Apr 2021 01:17:40 +0200 Subject: [PATCH] Improved !help feature. --- src/org/april/hebdobot/bot/Hebdobot.java | 33 +++++- .../hebdobot/bot/hooks/BadCommandHook.java | 14 ++- .../bot/hooks/CancelPreviousInputHook.java | 23 ++++ .../april/hebdobot/bot/hooks/ChronoHook.java | 25 ++++ .../bot/hooks/CollectiveSubjectHook.java | 25 ++++ .../april/hebdobot/bot/hooks/CommentHook.java | 27 ++++- .../april/hebdobot/bot/hooks/CurrentHook.java | 27 ++++- .../april/hebdobot/bot/hooks/DateHook.java | 27 ++++- .../april/hebdobot/bot/hooks/DefaultHook.java | 19 ++- .../hebdobot/bot/hooks/FinishReviewHook.java | 25 ++++ .../april/hebdobot/bot/hooks/HelloHook.java | 25 +++- .../hebdobot/bot/hooks/HelpByCommandHook.java | 110 ------------------ .../april/hebdobot/bot/hooks/HelpHook.java | 98 ++++++++++++++-- src/org/april/hebdobot/bot/hooks/Hook.java | 16 ++- .../hooks/{HookManager.java => Hooker.java} | 52 ++++++++- .../bot/hooks/IndividualSubjectHook.java | 25 ++++ .../hebdobot/bot/hooks/InputReviewHook.java | 19 ++- .../april/hebdobot/bot/hooks/LicenseHook.java | 25 +++- .../april/hebdobot/bot/hooks/MissingHook.java | 26 ++++- .../april/hebdobot/bot/hooks/RecordHook.java | 27 ++++- .../hebdobot/bot/hooks/StartReviewHook.java | 25 ++++ .../april/hebdobot/bot/hooks/StatsHook.java | 27 ++++- .../april/hebdobot/bot/hooks/StatusHook.java | 27 ++++- .../hebdobot/bot/hooks/StopReviewHook.java | 25 ++++ .../april/hebdobot/bot/hooks/ThanksHook.java | 25 +++- .../april/hebdobot/bot/hooks/VersionHook.java | 27 ++++- 26 files changed, 682 insertions(+), 142 deletions(-) delete mode 100644 src/org/april/hebdobot/bot/hooks/HelpByCommandHook.java rename src/org/april/hebdobot/bot/hooks/{HookManager.java => Hooker.java} (74%) diff --git a/src/org/april/hebdobot/bot/Hebdobot.java b/src/org/april/hebdobot/bot/Hebdobot.java index 08715e4..d267095 100644 --- a/src/org/april/hebdobot/bot/Hebdobot.java +++ b/src/org/april/hebdobot/bot/Hebdobot.java @@ -38,7 +38,7 @@ import org.april.hebdobot.bot.hooks.DefaultHook; import org.april.hebdobot.bot.hooks.FinishReviewHook; 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.Hooker; import org.april.hebdobot.bot.hooks.IndividualSubjectHook; import org.april.hebdobot.bot.hooks.InputReviewHook; import org.april.hebdobot.bot.hooks.LicenseHook; @@ -66,6 +66,7 @@ import org.quartz.SchedulerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; import twitter4j.TwitterException; /** @@ -92,7 +93,7 @@ public class Hebdobot extends PircBot private CronSettings cronSettings; private UserAliases aliases; private CronManager cronManager; - private HookManager hooker; + private Hooker hooker; /** * Instantiates a new hebdobot. @@ -139,7 +140,7 @@ public class Hebdobot extends PircBot this.cronManager = null; // - this.hooker = new HookManager(); + this.hooker = new Hooker(); this.hooker.add(new CollectiveSubjectHook()); this.hooker.add(new CommentHook()); @@ -236,6 +237,32 @@ public class Hebdobot extends PircBot return this.cronSettings; } + /** + * Gets the help. + * + * @param source + * the source + * @return the help + * @throws HebdobotException + * the hebdobot exception + */ + public StringList getHelp(final String source) throws HebdobotException + { + StringList result; + + if (source == null) + { + result = null; + } + else + { + result = this.hooker.attemptHelp(source); + } + + // + return result; + } + /** * Gets the home directory. * diff --git a/src/org/april/hebdobot/bot/hooks/BadCommandHook.java b/src/org/april/hebdobot/bot/hooks/BadCommandHook.java index ec85191..05b53e7 100644 --- a/src/org/april/hebdobot/bot/hooks/BadCommandHook.java +++ b/src/org/april/hebdobot/bot/hooks/BadCommandHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -18,10 +18,13 @@ */ package org.april.hebdobot.bot.hooks; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; + /** * The Class DefaultHook. */ @@ -29,6 +32,15 @@ public class BadCommandHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(BadCommandHook.class); + /* (non-Javadoc) + * @see org.april.hebdobot.bot.hooks.Hook#attemptHelp(org.april.hebdobot.bot.Hebdobot, java.lang.String) + */ + @Override + public StringList attemptHelp(final String message) throws HebdobotException + { + return null; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/CancelPreviousInputHook.java b/src/org/april/hebdobot/bot/hooks/CancelPreviousInputHook.java index 71d3fdb..50a1b8f 100644 --- a/src/org/april/hebdobot/bot/hooks/CancelPreviousInputHook.java +++ b/src/org/april/hebdobot/bot/hooks/CancelPreviousInputHook.java @@ -18,11 +18,13 @@ */ package org.april.hebdobot.bot.hooks; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.review.Topic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringsUtils; /** @@ -32,6 +34,27 @@ public class CancelPreviousInputHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(CancelPreviousInputHook.class); + /* (non-Javadoc) + * @see org.april.hebdobot.bot.hooks.Hook#attemptHelp(org.april.hebdobot.bot.Hebdobot, java.lang.String) + */ + @Override + public StringList attemptHelp(final String token) throws HebdobotException + { + StringList result; + + if (StringsUtils.equalsAnyIgnoreCase(token, "cancelprevious", "oops", "oups")) + { + result = new StringList("!oups, !oops, !cancelprevious : annuler la dernière entrée dans un point de revue"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/ChronoHook.java b/src/org/april/hebdobot/bot/hooks/ChronoHook.java index 0437683..17f67e1 100644 --- a/src/org/april/hebdobot/bot/hooks/ChronoHook.java +++ b/src/org/april/hebdobot/bot/hooks/ChronoHook.java @@ -19,10 +19,14 @@ package org.april.hebdobot.bot.hooks; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class ChronoHook. */ @@ -30,6 +34,27 @@ public class ChronoHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(ChronoHook.class); + /* (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, "chrono")) + { + result = new StringList("!chrono : afficher la durée du point de revue en cours"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java b/src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java index d5e8fb5..5a80abf 100644 --- a/src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java +++ b/src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java @@ -19,11 +19,15 @@ package org.april.hebdobot.bot.hooks; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.review.CollectiveTopic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class CollectiveSubjectHook. */ @@ -31,6 +35,27 @@ public class CollectiveSubjectHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(CollectiveSubjectHook.class); + /* (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, "##")) + { + result = new StringList("## titre : démarrer un sujet collectif"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/CommentHook.java b/src/org/april/hebdobot/bot/hooks/CommentHook.java index eb20718..2694f6d 100644 --- a/src/org/april/hebdobot/bot/hooks/CommentHook.java +++ b/src/org/april/hebdobot/bot/hooks/CommentHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -18,10 +18,14 @@ */ package org.april.hebdobot.bot.hooks; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class CommentHook. */ @@ -29,6 +33,27 @@ public class CommentHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(CommentHook.class); + /* (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, "%")) + { + result = new StringList("% message : traiter le message comme un commentaire (ignoré dans la synthèse de la revue)"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/CurrentHook.java b/src/org/april/hebdobot/bot/hooks/CurrentHook.java index c18f4ec..dbb5a73 100644 --- a/src/org/april/hebdobot/bot/hooks/CurrentHook.java +++ b/src/org/april/hebdobot/bot/hooks/CurrentHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2019 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -19,6 +19,7 @@ package org.april.hebdobot.bot.hooks; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.review.CollectiveTopic; import org.april.hebdobot.bot.review.IndividualTopic; @@ -26,6 +27,9 @@ import org.april.hebdobot.bot.review.Topic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class CurrentHook. */ @@ -33,6 +37,27 @@ public class CurrentHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(CurrentHook.class); + /* (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, "courant")) + { + result = new StringList("!courant : afficher le sujet en cours"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/DateHook.java b/src/org/april/hebdobot/bot/hooks/DateHook.java index 30682a8..cabb2e4 100644 --- a/src/org/april/hebdobot/bot/hooks/DateHook.java +++ b/src/org/april/hebdobot/bot/hooks/DateHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -23,10 +23,14 @@ import java.time.format.DateTimeFormatter; import java.util.Locale; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class DateHook. */ @@ -34,6 +38,27 @@ public class DateHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(DateHook.class); + /* (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, "date", "time", "now")) + { + result = new StringList("!date, !time, !now : afficher la date et l'heure"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/DefaultHook.java b/src/org/april/hebdobot/bot/hooks/DefaultHook.java index 6ffaa78..c2bcfdd 100644 --- a/src/org/april/hebdobot/bot/hooks/DefaultHook.java +++ b/src/org/april/hebdobot/bot/hooks/DefaultHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -18,10 +18,13 @@ */ package org.april.hebdobot.bot.hooks; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; + /** * The Class DefaultHook. */ @@ -29,6 +32,20 @@ public class DefaultHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(DefaultHook.class); + /* (non-Javadoc) + * @see org.april.hebdobot.bot.hooks.Hook#attemptHelp(java.lang.String) + */ + @Override + public StringList attemptHelp(final String token) throws HebdobotException + { + StringList result; + + result = null; + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java b/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java index 499b083..b57c851 100644 --- a/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java +++ b/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java @@ -27,6 +27,7 @@ import java.time.format.DateTimeFormatter; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.review.ReviewReporter; import org.april.hebdobot.bot.stats.ReviewData; @@ -37,6 +38,9 @@ import org.april.hebdobot.privatebin.PrivatebinClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class FinishReviewHook. */ @@ -46,6 +50,27 @@ public class FinishReviewHook extends Hook public static String DEFAULT_SUFFIX = "-log-irc-revue-hebdomadaire.txt"; + /* (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, "fin")) + { + result = new StringList("!fin : terminer la revue en cours"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/HelloHook.java b/src/org/april/hebdobot/bot/hooks/HelloHook.java index 0bcd461..189871e 100644 --- a/src/org/april/hebdobot/bot/hooks/HelloHook.java +++ b/src/org/april/hebdobot/bot/hooks/HelloHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -19,10 +19,12 @@ package org.april.hebdobot.bot.hooks; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringsUtils; /** @@ -32,6 +34,27 @@ public class HelloHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(HelloHook.class); + /* (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, "salut", "bonjour", "hello")) + { + result = new StringList("!salut, !bonjour, !hello : dire bonjour"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/HelpByCommandHook.java b/src/org/april/hebdobot/bot/hooks/HelpByCommandHook.java deleted file mode 100644 index 497b11b..0000000 --- a/src/org/april/hebdobot/bot/hooks/HelpByCommandHook.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Copyright (C) 2018 Christian Pierre MOMON - * - * 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 - */ -package org.april.hebdobot.bot.hooks; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.lang3.StringUtils; -import org.april.hebdobot.bot.Hebdobot; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The Class HelpByCommandHook. - */ -public class HelpByCommandHook extends Hook -{ - private static final Logger logger = LoggerFactory.getLogger(HelpByCommandHook.class); - - private static final Pattern PATTERN = Pattern.compile("^!help\\s+(\\S+)$"); - - /* (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; - - Matcher matcher = PATTERN.matcher(message); - - if (matcher.find()) - { - String command = matcher.group(1); - - if (StringUtils.equals(command, "help")) - { - bot.sendMessage(sender + ": help display help commands"); - bot.sendMessage(sender + ": help command display help on specific command"); - } - else if (StringUtils.equals(command, "ignore")) - { - bot.sendMessage(sender + ": ignore host:service ignore a specific probe"); - bot.sendMessage(sender + ": ignore list ignore probes"); - } - else if (StringUtils.equals(command, "unignore")) - { - bot.sendMessage(sender + ": unignore host:service ignore a specific probe"); - } - else if (StringUtils.equals(command, "ack")) - { - bot.sendMessage(sender + ": ack unack an alert"); - } - else if (StringUtils.equals(command, "unack")) - { - bot.sendMessage(sender + ": unack unack an alert"); - } - else if (StringUtils.equalsAnyIgnoreCase(command, "!mute", "!tagueule", "!ta gueule", "!chut", "!sieste")) - { - bot.sendMessage(sender + ": mute|tagueule|chut|sieste mute alert display"); - } - else if (StringUtils.equalsAnyIgnoreCase(command, "!unmute")) - { - bot.sendMessage(sender + ": unmute mute alert display"); - } - else if (StringUtils.equals(command, "list")) - { - bot.sendMessage(sender + ": list display current alerts"); - } - else if (StringUtils.equals(command, "refresh")) - { - bot.sendMessage(sender + ": refresh update alert list"); - } - else if (StringUtils.equals(command, "recheck")) - { - bot.sendMessage(sender + ": recheck reschedule current alerts"); - } - else - { - bot.sendMessage(sender + ": no help available for this command"); - } - - result = true; - } - else - { - result = false; - } - - // - return result; - } -} diff --git a/src/org/april/hebdobot/bot/hooks/HelpHook.java b/src/org/april/hebdobot/bot/hooks/HelpHook.java index 790112c..e31dbae 100644 --- a/src/org/april/hebdobot/bot/hooks/HelpHook.java +++ b/src/org/april/hebdobot/bot/hooks/HelpHook.java @@ -18,24 +18,56 @@ */ package org.april.hebdobot.bot.hooks; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class HelpHook. */ public class HelpHook extends Hook { + private static final Pattern COMMAND_HELP_PATTERN = Pattern.compile("^!(aide|help)\\s+(?\\S+)$"); + private static final Logger logger = LoggerFactory.getLogger(HelpHook.class); + /* (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, "aide", "help")) + { + result = new StringList(); + result.append("!aide, !help : afficher l'aide générale"); + result.append("!aide foo, !help foo : afficher l'aide de la commande foo"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) + final String message) throws HebdobotException { boolean result; @@ -49,29 +81,77 @@ public class HelpHook extends Hook bot.sendMessage(sender, "Voici les commandes que je comprends :"); bot.sendMessage(sender, " "); bot.sendMessage(sender, " !aide,!help : afficher cette aide"); + bot.sendMessage(sender, " !aide foo : afficher l'aide de la comande foo"); bot.sendMessage(sender, " !début : commencer une nouvelle revue"); + bot.sendMessage(sender, " % message  : traiter comme un commentaire"); bot.sendMessage(sender, " # titre  : démarrer un sujet individuel"); bot.sendMessage(sender, " ## titre  : démarrer un sujet collectif"); - bot.sendMessage(sender, " % message  : traiter comme un commentaire"); + bot.sendMessage(sender, " !oups   : annuler la dernière entrée dans un point de revue"); bot.sendMessage(sender, " !courant : afficher le sujet en cours"); - bot.sendMessage(sender, " !manquants : afficher qui n'a pas participé sur le dernier sujet"); bot.sendMessage(sender, " !fin : terminer la revue en cours"); bot.sendMessage(sender, " !stop  : abandonner la revue en cours"); - bot.sendMessage(sender, " !licence   : afficher la licence du logiciel Hebdobot et le lien vers ses sources"); - bot.sendMessage(sender, " !record : affiche le record de participation à la revue"); - bot.sendMessage(sender, " !stats : statistiques sur les précédentes revues"); - bot.sendMessage(sender, " !version   : afficher la version d'Hebdobot"); bot.sendMessage(sender, " "); - bot.sendMessage(sender, "Autres commandes de dialogue : !bonjour, !date, !hello, !merci, !salut"); + bot.sendMessage(sender, "Autres commandes : !bonjour, !date, !hello, !licence, !manquants, !merci, !record, !salut, !stats, !version"); result = true; } else { - result = false; + String token = extractTargetHelp(message); + + if (token == null) + { + result = false; + } + else + { + StringList help = bot.getHelp(token); + if (help == null) + { + bot.sendMessage("aide indisponible pour la commande " + token); + } + else + { + for (String line : help) + { + bot.sendMessage(line); + } + } + + result = true; + } } // return result; } + + /** + * Extract target help. + * + * @return the string + */ + private String extractTargetHelp(final String message) + { + String result; + + Matcher matcher = COMMAND_HELP_PATTERN.matcher(message); + if (matcher.find()) + { + result = matcher.group("token"); + + if (StringUtils.startsWith(result, "!")) + { + result = result.substring(1); + } + } + else + { + result = null; + } + + // + return result; + } + } diff --git a/src/org/april/hebdobot/bot/hooks/Hook.java b/src/org/april/hebdobot/bot/hooks/Hook.java index adde590..45b6093 100644 --- a/src/org/april/hebdobot/bot/hooks/Hook.java +++ b/src/org/april/hebdobot/bot/hooks/Hook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -21,11 +21,25 @@ package org.april.hebdobot.bot.hooks; import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; +import fr.devinsy.strings.StringList; + /** * The Class Hook. */ public abstract class Hook { + /** + * Attempt help. + * + * @param bot + * the bot + * @param message + * the message + * @return true, if successful + * @throws HebdobotException + * the hebdobot exception + */ + public abstract StringList attemptHelp(final String string) throws HebdobotException; /** * Attempt process. diff --git a/src/org/april/hebdobot/bot/hooks/HookManager.java b/src/org/april/hebdobot/bot/hooks/Hooker.java similarity index 74% rename from src/org/april/hebdobot/bot/hooks/HookManager.java rename to src/org/april/hebdobot/bot/hooks/Hooker.java index 8103d77..dbe31b5 100644 --- a/src/org/april/hebdobot/bot/hooks/HookManager.java +++ b/src/org/april/hebdobot/bot/hooks/Hooker.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2019 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -29,18 +29,18 @@ import org.slf4j.LoggerFactory; import fr.devinsy.strings.StringList; /** - * The Interface MessageHook. + * The class Hooker, a hook manager. */ -public class HookManager +public class Hooker { - private static final Logger logger = LoggerFactory.getLogger(HookManager.class); + private static final Logger logger = LoggerFactory.getLogger(Hooker.class); private ArrayList hooks; /** * Instantiates a new hook manager. */ - public HookManager() + public Hooker() { this.hooks = new ArrayList<>(30); } @@ -59,6 +59,48 @@ public class HookManager } } + /** + * Attempt help. + * + * @param bot + * the bot + * @param message + * the message + * @return true, if successful + * @throws HebdobotException + * the hebdobot exception + */ + public StringList attemptHelp(final String message) throws HebdobotException + { + StringList result; + + boolean ended = false; + Iterator iterator = this.hooks.iterator(); + result = null; + while (!ended) + { + if (iterator.hasNext()) + { + Hook hook = iterator.next(); + StringList help = hook.attemptHelp(message); + + if (help != null) + { + ended = true; + result = help; + } + } + else + { + ended = true; + result = null; + } + } + + // + return result; + } + /** * Attempt process. * diff --git a/src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java b/src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java index 9ac95d7..42d9e05 100644 --- a/src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java +++ b/src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java @@ -19,11 +19,15 @@ package org.april.hebdobot.bot.hooks; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.review.IndividualTopic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class IndividualSubjectHook. */ @@ -31,6 +35,27 @@ public class IndividualSubjectHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(IndividualSubjectHook.class); + /* (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, "#")) + { + result = new StringList("# titre : démarrer un sujet individuel"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/InputReviewHook.java b/src/org/april/hebdobot/bot/hooks/InputReviewHook.java index 39d4991..cd0c344 100644 --- a/src/org/april/hebdobot/bot/hooks/InputReviewHook.java +++ b/src/org/april/hebdobot/bot/hooks/InputReviewHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -18,11 +18,14 @@ */ package org.april.hebdobot.bot.hooks; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.review.Message; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; + /** * The Class DefaultHook. */ @@ -30,6 +33,20 @@ public class InputReviewHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(InputReviewHook.class); + /* (non-Javadoc) + * @see org.april.hebdobot.bot.hooks.Hook#attemptHelp(java.lang.String) + */ + @Override + public StringList attemptHelp(final String token) throws HebdobotException + { + StringList result; + + result = null; + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/LicenseHook.java b/src/org/april/hebdobot/bot/hooks/LicenseHook.java index 82502c8..ecb0a21 100644 --- a/src/org/april/hebdobot/bot/hooks/LicenseHook.java +++ b/src/org/april/hebdobot/bot/hooks/LicenseHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -18,10 +18,12 @@ */ package org.april.hebdobot.bot.hooks; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringsUtils; /** @@ -31,6 +33,27 @@ public class LicenseHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(LicenseHook.class); + /* (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, "licence", "license")) + { + result = new StringList("!licence, !license : afficher la licence du logiciel Hebdobot et le lien vers ses sources"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/MissingHook.java b/src/org/april/hebdobot/bot/hooks/MissingHook.java index 558a061..bfba154 100644 --- a/src/org/april/hebdobot/bot/hooks/MissingHook.java +++ b/src/org/april/hebdobot/bot/hooks/MissingHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2019 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -22,12 +22,15 @@ import java.util.Collection; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.review.Topic; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringSet; +import fr.devinsy.strings.StringsUtils; /** * The Class MissingHook. @@ -36,6 +39,27 @@ public class MissingHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(MissingHook.class); + /* (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, "manquants")) + { + result = new StringList("!manquants : afficher les pseudos n'ayant pas participé au point en cours"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/RecordHook.java b/src/org/april/hebdobot/bot/hooks/RecordHook.java index 25476d2..a2e8a94 100644 --- a/src/org/april/hebdobot/bot/hooks/RecordHook.java +++ b/src/org/april/hebdobot/bot/hooks/RecordHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -20,6 +20,7 @@ package org.april.hebdobot.bot.hooks; import java.io.File; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.stats.ReviewDatas; import org.april.hebdobot.bot.stats.ReviewDatasFile; @@ -27,6 +28,9 @@ import org.april.hebdobot.bot.stats.ReviewStatsReporter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class RecordHook. */ @@ -34,6 +38,27 @@ public class RecordHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(RecordHook.class); + /* (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, "record")) + { + result = new StringList("!record : afficher le record de participation à la revue"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/StartReviewHook.java b/src/org/april/hebdobot/bot/hooks/StartReviewHook.java index 742afba..23d2289 100644 --- a/src/org/april/hebdobot/bot/hooks/StartReviewHook.java +++ b/src/org/april/hebdobot/bot/hooks/StartReviewHook.java @@ -21,12 +21,16 @@ package org.april.hebdobot.bot.hooks; import java.time.LocalTime; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; 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; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class StartReviewHook. */ @@ -34,6 +38,27 @@ public class StartReviewHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(StartReviewHook.class); + /* (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; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/StatsHook.java b/src/org/april/hebdobot/bot/hooks/StatsHook.java index 2c9f14c..19b9238 100644 --- a/src/org/april/hebdobot/bot/hooks/StatsHook.java +++ b/src/org/april/hebdobot/bot/hooks/StatsHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -20,6 +20,7 @@ package org.april.hebdobot.bot.hooks; import java.io.File; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.bot.stats.ReviewDatas; import org.april.hebdobot.bot.stats.ReviewDatasFile; @@ -27,6 +28,9 @@ import org.april.hebdobot.bot.stats.ReviewStatsReporter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class StatsHook. */ @@ -34,6 +38,27 @@ public class StatsHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(StatsHook.class); + /* (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, "stats")) + { + result = new StringList("!stats : statistiques sur les précédentes revues"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/StatusHook.java b/src/org/april/hebdobot/bot/hooks/StatusHook.java index 231654b..c3b851d 100644 --- a/src/org/april/hebdobot/bot/hooks/StatusHook.java +++ b/src/org/april/hebdobot/bot/hooks/StatusHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -19,10 +19,14 @@ package org.april.hebdobot.bot.hooks; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class StatusHook. */ @@ -30,6 +34,27 @@ public class StatusHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(StatusHook.class); + /* (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, "status", "statut")) + { + result = new StringList("!status, !statut : état et paramétrage d'Hebdobot"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/StopReviewHook.java b/src/org/april/hebdobot/bot/hooks/StopReviewHook.java index 6cba1db..0aca787 100644 --- a/src/org/april/hebdobot/bot/hooks/StopReviewHook.java +++ b/src/org/april/hebdobot/bot/hooks/StopReviewHook.java @@ -19,10 +19,14 @@ package org.april.hebdobot.bot.hooks; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class StopReviewHook. */ @@ -30,6 +34,27 @@ public class StopReviewHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(StopReviewHook.class); + /* (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, "stop")) + { + result = new StringList("!stop : abandonner la revue en cours"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/ThanksHook.java b/src/org/april/hebdobot/bot/hooks/ThanksHook.java index 51acc20..8f40b9a 100644 --- a/src/org/april/hebdobot/bot/hooks/ThanksHook.java +++ b/src/org/april/hebdobot/bot/hooks/ThanksHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -19,10 +19,12 @@ package org.april.hebdobot.bot.hooks; import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringsUtils; /** @@ -32,6 +34,27 @@ public class ThanksHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(ThanksHook.class); + /* (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, "merci")) + { + result = new StringList("!merci : dire que ça fait plaisir"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */ diff --git a/src/org/april/hebdobot/bot/hooks/VersionHook.java b/src/org/april/hebdobot/bot/hooks/VersionHook.java index 50154c6..3ee2816 100644 --- a/src/org/april/hebdobot/bot/hooks/VersionHook.java +++ b/src/org/april/hebdobot/bot/hooks/VersionHook.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018 Christian Pierre MOMON + * Copyright (C) 2018-2021 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * @@ -18,11 +18,15 @@ */ package org.april.hebdobot.bot.hooks; +import org.april.hebdobot.HebdobotException; import org.april.hebdobot.bot.Hebdobot; import org.april.hebdobot.util.BuildInformation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.strings.StringList; +import fr.devinsy.strings.StringsUtils; + /** * The Class VersionHook. */ @@ -30,6 +34,27 @@ public class VersionHook extends Hook { private static final Logger logger = LoggerFactory.getLogger(VersionHook.class); + /* (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, "version")) + { + result = new StringList("!version : afficher la version d'Hebdobot"); + } + else + { + result = null; + } + + // + return result; + } + /* (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) */