diff --git a/src/org/april/hebdobot/bot/Hebdobot.java b/src/org/april/hebdobot/bot/Hebdobot.java index 93c2bd0..ab5071f 100644 --- a/src/org/april/hebdobot/bot/Hebdobot.java +++ b/src/org/april/hebdobot/bot/Hebdobot.java @@ -47,6 +47,7 @@ import org.april.hebdobot.bot.hooks.StatsHook; import org.april.hebdobot.bot.hooks.StatusHook; import org.april.hebdobot.bot.hooks.StopReviewHook; import org.april.hebdobot.bot.hooks.ThanksHook; +import org.april.hebdobot.bot.hooks.TimekeeperHook; import org.april.hebdobot.bot.hooks.VersionHook; import org.april.hebdobot.bot.review.Message; import org.april.hebdobot.bot.review.Review; @@ -56,6 +57,7 @@ import org.april.hebdobot.identica.IdenticaSettings; import org.april.hebdobot.pastebin.PastebinSettings; import org.april.hebdobot.twitter.TwitterClient; import org.april.hebdobot.twitter.TwitterSettings; +import org.april.hebdobot.util.Timekeeper; import org.jibble.pircbot.IrcException; import org.jibble.pircbot.NickAlreadyInUseException; import org.jibble.pircbot.PircBot; @@ -82,6 +84,7 @@ public class Hebdobot extends PircBot private String reviewFileSuffix; private LocalTime reviewWaitTime; private Review review; + private Timekeeper timekeeper; private IdenticaSettings identicaSettings; private PastebinSettings pastebinSettings; private TwitterSettings twitterSettings; @@ -124,6 +127,7 @@ public class Hebdobot extends PircBot this.reviewFileSuffix = null; this.reviewWaitTime = null; this.review = null; + this.timekeeper = new Timekeeper(); this.identicaSettings = new IdenticaSettings(); this.pastebinSettings = new PastebinSettings(); @@ -150,6 +154,7 @@ public class Hebdobot extends PircBot this.hooker.add(new StatusHook()); this.hooker.add(new CancelPreviousInputHook()); + this.hooker.add(new TimekeeperHook()); this.hooker.add(new DateHook()); this.hooker.add(new HelloHook()); this.hooker.add(new LicenseHook()); @@ -245,6 +250,11 @@ public class Hebdobot extends PircBot return this.reviewWaitTime; } + public Timekeeper getTimekeeper() + { + return this.timekeeper; + } + /** * Gets the twitter settings. * diff --git a/src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java b/src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java index 5435ded..1eb31f0 100644 --- a/src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java +++ b/src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java @@ -53,13 +53,15 @@ public class CollectiveSubjectHook extends Hook if (!bot.getReview().isEmpty()) { String participants = StringUtils.join(bot.getReview().getParticipants(), " "); - bot.sendMessage(String.format("%% %s, on va passer à la suite : %s", participants, topic.getTitle())); + bot.sendMessage(String.format("%% +%s %s, on va passer à la suite : %s", bot.getTimekeeper().format(), participants, + topic.getTitle())); } bot.getReview().begin(topic); bot.sendMessage("Sujet collectif : " + topic.getTitle()); bot.sendMessage("% 1 minute max"); bot.sendMessage("% si rien à signaler vous pouvez écrire % ras"); bot.sendMessage("% quand vous avez fini vous le dites par % fini"); + bot.getTimekeeper().start(); } else { diff --git a/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java b/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java index 10cbfc0..bb31d7b 100644 --- a/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java +++ b/src/org/april/hebdobot/bot/hooks/FinishReviewHook.java @@ -83,6 +83,8 @@ public class FinishReviewHook extends Hook // End the review. bot.getReview().endReview(); + bot.sendMessage("%% +%01d:%02d", bot.getTimekeeper().format()); + // Load and update review statistics. ReviewDatas datas; try diff --git a/src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java b/src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java index 31f474d..af8adfb 100644 --- a/src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java +++ b/src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java @@ -53,12 +53,14 @@ public class IndividualSubjectHook extends Hook if (!bot.getReview().isEmpty()) { String participants = StringUtils.join(bot.getReview().getParticipants(), " "); - bot.sendMessage(String.format("%% %s, on va passer à la suite : %s", participants, topic.getTitle())); + bot.sendMessage(String.format("%% +%s %s, on va passer à la suite : %s", bot.getTimekeeper().format(), participants, + topic.getTitle())); } bot.getReview().begin(topic); bot.sendMessage("Sujet individuel : " + topic.getTitle()); bot.sendMessage("% si rien à signaler vous pouvez écrire % ras"); bot.sendMessage("% quand vous avez fini vous le dites par % fini"); + bot.getTimekeeper().start(); } else { diff --git a/src/org/april/hebdobot/bot/hooks/TimekeeperHook.java b/src/org/april/hebdobot/bot/hooks/TimekeeperHook.java new file mode 100644 index 0000000..6bde950 --- /dev/null +++ b/src/org/april/hebdobot/bot/hooks/TimekeeperHook.java @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2021 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 org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.bot.Hebdobot; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class TimekeeperHook. + */ +public class TimekeeperHook extends Hook +{ + private static final Logger logger = LoggerFactory.getLogger(TimekeeperHook.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.equalsAnyIgnoreCase(message, "!timekeeper", "!chrono")) + { + logger.info("!chrono caught."); + bot.sendMessage(bot.getTimekeeper().format()); + + result = true; + } + else + { + result = false; + } + + // + return result; + } +} diff --git a/src/org/april/hebdobot/util/Timekeeper.java b/src/org/april/hebdobot/util/Timekeeper.java new file mode 100644 index 0000000..5194ebc --- /dev/null +++ b/src/org/april/hebdobot/util/Timekeeper.java @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2021 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.util; + +import java.time.Duration; +import java.time.LocalDateTime; + +/** + * The Class TimeKeeper. + */ +public class Timekeeper +{ + private LocalDateTime start; + + /** + * Instantiates a new time keeper. + */ + public Timekeeper() + { + this.start = null; + } + + /** + * Format. + * + * @return the string + */ + public String format() + { + String result; + + if (this.start == null) + { + result = "n/a"; + } + else + { + LocalDateTime end = LocalDateTime.now(); + Duration duration = Duration.between(this.start, end); + + result = String.format("%1d:%02d", duration.getSeconds() / 60, duration.getSeconds() % 60); + } + + // + return result; + } + + /** + * Start. + */ + public void start() + { + this.start = LocalDateTime.now(); + } +}