Improved !chrono feature.
This commit is contained in:
parent
c469fd5c7b
commit
47fd4b58e8
7 changed files with 98 additions and 32 deletions
|
@ -29,6 +29,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.april.hebdobot.HebdobotException;
|
||||
import org.april.hebdobot.bot.hooks.BadCommandHook;
|
||||
import org.april.hebdobot.bot.hooks.CancelPreviousInputHook;
|
||||
import org.april.hebdobot.bot.hooks.ChronoHook;
|
||||
import org.april.hebdobot.bot.hooks.CollectiveSubjectHook;
|
||||
import org.april.hebdobot.bot.hooks.CommentHook;
|
||||
import org.april.hebdobot.bot.hooks.CurrentHook;
|
||||
|
@ -48,7 +49,6 @@ 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;
|
||||
|
@ -58,7 +58,7 @@ import org.april.hebdobot.identica.IdenticaSettings;
|
|||
import org.april.hebdobot.privatebin.PrivatebinSettings;
|
||||
import org.april.hebdobot.twitter.TwitterClient;
|
||||
import org.april.hebdobot.twitter.TwitterSettings;
|
||||
import org.april.hebdobot.util.Timekeeper;
|
||||
import org.april.hebdobot.util.Chrono;
|
||||
import org.jibble.pircbot.IrcException;
|
||||
import org.jibble.pircbot.NickAlreadyInUseException;
|
||||
import org.jibble.pircbot.PircBot;
|
||||
|
@ -85,7 +85,7 @@ public class Hebdobot extends PircBot
|
|||
private String reviewFileSuffix;
|
||||
private LocalTime reviewWaitTime;
|
||||
private Review review;
|
||||
private Timekeeper timekeeper;
|
||||
private Chrono chrono;
|
||||
private IdenticaSettings identicaSettings;
|
||||
private PrivatebinSettings privatebinSettings;
|
||||
private TwitterSettings twitterSettings;
|
||||
|
@ -128,7 +128,7 @@ public class Hebdobot extends PircBot
|
|||
this.reviewFileSuffix = null;
|
||||
this.reviewWaitTime = null;
|
||||
this.review = null;
|
||||
this.timekeeper = new Timekeeper();
|
||||
this.chrono = new Chrono();
|
||||
|
||||
this.identicaSettings = new IdenticaSettings();
|
||||
this.privatebinSettings = new PrivatebinSettings();
|
||||
|
@ -155,7 +155,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 ChronoHook());
|
||||
this.hooker.add(new DateHook());
|
||||
this.hooker.add(new HelloHook());
|
||||
this.hooker.add(new LicenseHook());
|
||||
|
@ -197,6 +197,15 @@ public class Hebdobot extends PircBot
|
|||
this.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* End review.
|
||||
*/
|
||||
public void endReview()
|
||||
{
|
||||
this.review.endReview();
|
||||
this.chrono.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the aliases.
|
||||
*
|
||||
|
@ -207,6 +216,11 @@ public class Hebdobot extends PircBot
|
|||
return this.aliases;
|
||||
}
|
||||
|
||||
public Chrono getChrono()
|
||||
{
|
||||
return this.chrono;
|
||||
}
|
||||
|
||||
public CronManager getCronManager()
|
||||
{
|
||||
return this.cronManager;
|
||||
|
@ -272,11 +286,6 @@ public class Hebdobot extends PircBot
|
|||
return this.reviewWaitTime;
|
||||
}
|
||||
|
||||
public Timekeeper getTimekeeper()
|
||||
{
|
||||
return this.timekeeper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the twitter settings.
|
||||
*
|
||||
|
@ -486,6 +495,28 @@ public class Hebdobot extends PircBot
|
|||
logger.info("Bot ready.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Send chrono message.
|
||||
*/
|
||||
public void sendChronoMessage()
|
||||
{
|
||||
if (this.review == null)
|
||||
{
|
||||
sendMessage("%% durée du point ; pas de revue en cours.");
|
||||
}
|
||||
else if (this.review.isEmpty())
|
||||
{
|
||||
sendMessage("%% durée du point ; pas de point en cours.");
|
||||
}
|
||||
else
|
||||
{
|
||||
String topicTitle = this.review.getCurrentTopic().getTitle();
|
||||
String chronoValue = this.chrono.toString();
|
||||
|
||||
sendMessage(String.format("%% durée du point %s : %s", topicTitle, chronoValue));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message.
|
||||
*
|
||||
|
@ -532,4 +563,13 @@ public class Hebdobot extends PircBot
|
|||
{
|
||||
this.reviewWaitTime = reviewWaitTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop review.
|
||||
*/
|
||||
public void stopReview()
|
||||
{
|
||||
setReview(null);
|
||||
this.chrono.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,11 +24,11 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class TimekeeperHook.
|
||||
* The Class ChronoHook.
|
||||
*/
|
||||
public class TimekeeperHook extends Hook
|
||||
public class ChronoHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(TimekeeperHook.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(ChronoHook.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)
|
||||
|
@ -39,10 +39,11 @@ public class TimekeeperHook extends Hook
|
|||
{
|
||||
boolean result;
|
||||
|
||||
if (StringUtils.equalsAnyIgnoreCase(message, "!timekeeper", "!chrono"))
|
||||
if (StringUtils.equalsAnyIgnoreCase(message, "!chrono"))
|
||||
{
|
||||
logger.info("!chrono caught.");
|
||||
bot.sendMessage(bot.getTimekeeper().format());
|
||||
bot.sendChronoMessage();
|
||||
// bot.sendMessage(bot.getChrono().format());
|
||||
|
||||
result = true;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
* Copyright (C) 2018-2021 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* This file is part of (April) Hebdobot.
|
||||
*
|
||||
|
@ -52,16 +52,17 @@ public class CollectiveSubjectHook extends Hook
|
|||
CollectiveTopic topic = new CollectiveTopic(message.replaceFirst("##", "").trim());
|
||||
if (!bot.getReview().isEmpty())
|
||||
{
|
||||
bot.sendChronoMessage();
|
||||
|
||||
String participants = StringUtils.join(bot.getReview().getParticipants(), " ");
|
||||
bot.sendMessage(String.format("%% %s %s, on va passer à la suite : %s", bot.getTimekeeper().format(), participants,
|
||||
topic.getTitle()));
|
||||
bot.sendMessage(String.format("%% %s, on va passer à la suite : %s", 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();
|
||||
bot.getChrono().start();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -80,9 +80,8 @@ public class FinishReviewHook extends Hook
|
|||
else
|
||||
{
|
||||
// End the review.
|
||||
bot.getReview().endReview();
|
||||
|
||||
bot.sendMessage("%% +%01d:%02d", bot.getTimekeeper().format());
|
||||
bot.sendChronoMessage();
|
||||
bot.endReview();
|
||||
|
||||
// Load and update review statistics.
|
||||
ReviewDatas datas;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
* Copyright (C) 2018-2021 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* This file is part of (April) Hebdobot.
|
||||
*
|
||||
|
@ -52,15 +52,16 @@ public class IndividualSubjectHook extends Hook
|
|||
IndividualTopic topic = new IndividualTopic(message.replaceFirst("#", "").trim());
|
||||
if (!bot.getReview().isEmpty())
|
||||
{
|
||||
bot.sendChronoMessage();
|
||||
|
||||
String participants = StringUtils.join(bot.getReview().getParticipants(), " ");
|
||||
bot.sendMessage(String.format("%% %s %s, on va passer à la suite : %s", bot.getTimekeeper().format(), participants,
|
||||
topic.getTitle()));
|
||||
bot.sendMessage(String.format("%% %s, on va passer à la suite : %s", 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();
|
||||
bot.getChrono().start();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright (C) 2018-2019 Christian Pierre MOMON <cmomon@april.org>
|
||||
* Copyright (C) 2018-2021 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* This file is part of (April) Hebdobot.
|
||||
*
|
||||
|
@ -55,7 +55,7 @@ public class StopReviewHook extends Hook
|
|||
else
|
||||
{
|
||||
bot.sendMessage("Abandon de la revue en cours.");
|
||||
bot.setReview(null);
|
||||
bot.stopReview();
|
||||
}
|
||||
|
||||
result = true;
|
||||
|
|
|
@ -22,18 +22,18 @@ import java.time.Duration;
|
|||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* The Class TimeKeeper.
|
||||
* The Class Chrono.
|
||||
*/
|
||||
public class Timekeeper
|
||||
public class Chrono
|
||||
{
|
||||
private LocalDateTime start;
|
||||
|
||||
/**
|
||||
* Instantiates a new time keeper.
|
||||
*/
|
||||
public Timekeeper()
|
||||
public Chrono()
|
||||
{
|
||||
this.start = null;
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,6 +61,14 @@ public class Timekeeper
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
this.start = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start.
|
||||
*/
|
||||
|
@ -68,4 +76,20 @@ public class Timekeeper
|
|||
{
|
||||
this.start = LocalDateTime.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = format();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue