Added time keeper feature.

This commit is contained in:
Christian P. MOMON 2021-01-30 23:48:08 +01:00
parent 12fe4ede50
commit c731c9413c
6 changed files with 146 additions and 2 deletions

View File

@ -47,6 +47,7 @@ import org.april.hebdobot.bot.hooks.StatsHook;
import org.april.hebdobot.bot.hooks.StatusHook; import org.april.hebdobot.bot.hooks.StatusHook;
import org.april.hebdobot.bot.hooks.StopReviewHook; import org.april.hebdobot.bot.hooks.StopReviewHook;
import org.april.hebdobot.bot.hooks.ThanksHook; 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.hooks.VersionHook;
import org.april.hebdobot.bot.review.Message; import org.april.hebdobot.bot.review.Message;
import org.april.hebdobot.bot.review.Review; 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.pastebin.PastebinSettings;
import org.april.hebdobot.twitter.TwitterClient; import org.april.hebdobot.twitter.TwitterClient;
import org.april.hebdobot.twitter.TwitterSettings; import org.april.hebdobot.twitter.TwitterSettings;
import org.april.hebdobot.util.Timekeeper;
import org.jibble.pircbot.IrcException; import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.NickAlreadyInUseException; import org.jibble.pircbot.NickAlreadyInUseException;
import org.jibble.pircbot.PircBot; import org.jibble.pircbot.PircBot;
@ -82,6 +84,7 @@ public class Hebdobot extends PircBot
private String reviewFileSuffix; private String reviewFileSuffix;
private LocalTime reviewWaitTime; private LocalTime reviewWaitTime;
private Review review; private Review review;
private Timekeeper timekeeper;
private IdenticaSettings identicaSettings; private IdenticaSettings identicaSettings;
private PastebinSettings pastebinSettings; private PastebinSettings pastebinSettings;
private TwitterSettings twitterSettings; private TwitterSettings twitterSettings;
@ -124,6 +127,7 @@ public class Hebdobot extends PircBot
this.reviewFileSuffix = null; this.reviewFileSuffix = null;
this.reviewWaitTime = null; this.reviewWaitTime = null;
this.review = null; this.review = null;
this.timekeeper = new Timekeeper();
this.identicaSettings = new IdenticaSettings(); this.identicaSettings = new IdenticaSettings();
this.pastebinSettings = new PastebinSettings(); this.pastebinSettings = new PastebinSettings();
@ -150,6 +154,7 @@ public class Hebdobot extends PircBot
this.hooker.add(new StatusHook()); this.hooker.add(new StatusHook());
this.hooker.add(new CancelPreviousInputHook()); this.hooker.add(new CancelPreviousInputHook());
this.hooker.add(new TimekeeperHook());
this.hooker.add(new DateHook()); this.hooker.add(new DateHook());
this.hooker.add(new HelloHook()); this.hooker.add(new HelloHook());
this.hooker.add(new LicenseHook()); this.hooker.add(new LicenseHook());
@ -245,6 +250,11 @@ public class Hebdobot extends PircBot
return this.reviewWaitTime; return this.reviewWaitTime;
} }
public Timekeeper getTimekeeper()
{
return this.timekeeper;
}
/** /**
* Gets the twitter settings. * Gets the twitter settings.
* *

View File

@ -53,13 +53,15 @@ public class CollectiveSubjectHook extends Hook
if (!bot.getReview().isEmpty()) if (!bot.getReview().isEmpty())
{ {
String participants = StringUtils.join(bot.getReview().getParticipants(), " "); 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.getReview().begin(topic);
bot.sendMessage("Sujet collectif : " + topic.getTitle()); bot.sendMessage("Sujet collectif : " + topic.getTitle());
bot.sendMessage("% 1 minute max"); bot.sendMessage("% 1 minute max");
bot.sendMessage("% si rien à signaler vous pouvez écrire % ras"); bot.sendMessage("% si rien à signaler vous pouvez écrire % ras");
bot.sendMessage("% quand vous avez fini vous le dites par % fini"); bot.sendMessage("% quand vous avez fini vous le dites par % fini");
bot.getTimekeeper().start();
} }
else else
{ {

View File

@ -83,6 +83,8 @@ public class FinishReviewHook extends Hook
// End the review. // End the review.
bot.getReview().endReview(); bot.getReview().endReview();
bot.sendMessage("%% +%01d:%02d", bot.getTimekeeper().format());
// Load and update review statistics. // Load and update review statistics.
ReviewDatas datas; ReviewDatas datas;
try try

View File

@ -53,12 +53,14 @@ public class IndividualSubjectHook extends Hook
if (!bot.getReview().isEmpty()) if (!bot.getReview().isEmpty())
{ {
String participants = StringUtils.join(bot.getReview().getParticipants(), " "); 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.getReview().begin(topic);
bot.sendMessage("Sujet individuel : " + topic.getTitle()); bot.sendMessage("Sujet individuel : " + topic.getTitle());
bot.sendMessage("% si rien à signaler vous pouvez écrire % ras"); bot.sendMessage("% si rien à signaler vous pouvez écrire % ras");
bot.sendMessage("% quand vous avez fini vous le dites par % fini"); bot.sendMessage("% quand vous avez fini vous le dites par % fini");
bot.getTimekeeper().start();
} }
else else
{ {

View File

@ -0,0 +1,57 @@
/**
* Copyright (C) 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.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;
}
}

View File

@ -0,0 +1,71 @@
/**
* Copyright (C) 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.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();
}
}