Refactored onMessage code with hook management.
This commit is contained in:
parent
6640dc9853
commit
f2f9bceae5
@ -21,36 +21,35 @@ package org.april.hebdobot.bot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.april.hebdobot.HebdobotException;
|
||||
import org.april.hebdobot.bot.review.CollectiveTopic;
|
||||
import org.april.hebdobot.bot.review.IndividualTopic;
|
||||
import org.april.hebdobot.bot.hooks.CollectiveSubjectHook;
|
||||
import org.april.hebdobot.bot.hooks.CommentHook;
|
||||
import org.april.hebdobot.bot.hooks.CurrentHook;
|
||||
import org.april.hebdobot.bot.hooks.DateHook;
|
||||
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.IndividualSubjectHook;
|
||||
import org.april.hebdobot.bot.hooks.LicenseHook;
|
||||
import org.april.hebdobot.bot.hooks.MissingHook;
|
||||
import org.april.hebdobot.bot.hooks.StartReviewHook;
|
||||
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.VersionHook;
|
||||
import org.april.hebdobot.bot.review.Message;
|
||||
import org.april.hebdobot.bot.review.Review;
|
||||
import org.april.hebdobot.bot.review.Topic;
|
||||
import org.april.hebdobot.bot.stats.ReviewData;
|
||||
import org.april.hebdobot.bot.stats.ReviewDatas;
|
||||
import org.april.hebdobot.bot.stats.ReviewDatasFile;
|
||||
import org.april.hebdobot.bot.stats.ReviewStatsReporter;
|
||||
import org.april.hebdobot.cron.CronManager;
|
||||
import org.april.hebdobot.cron.CronSettings;
|
||||
import org.april.hebdobot.identica.IdenticaSettings;
|
||||
import org.april.hebdobot.pastebin.PastebinClient;
|
||||
import org.april.hebdobot.pastebin.PastebinSettings;
|
||||
import org.april.hebdobot.pastebin.Private;
|
||||
import org.april.hebdobot.twitter.TwitterClient;
|
||||
import org.april.hebdobot.twitter.TwitterSettings;
|
||||
import org.april.hebdobot.util.BuildInformation;
|
||||
import org.jibble.pircbot.IrcException;
|
||||
import org.jibble.pircbot.NickAlreadyInUseException;
|
||||
import org.jibble.pircbot.PircBot;
|
||||
@ -58,8 +57,6 @@ import org.quartz.SchedulerException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.strings.StringList;
|
||||
import fr.devinsy.strings.StringsUtils;
|
||||
import twitter4j.TwitterException;
|
||||
|
||||
/**
|
||||
@ -69,8 +66,6 @@ public class Hebdobot extends PircBot
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Hebdobot.class);
|
||||
|
||||
private static String DEFAULT_SUFFIX = "-log-irc-revue-hebdomadaire.txt";
|
||||
|
||||
private File homeDirectory;
|
||||
private String host;
|
||||
private int port;
|
||||
@ -85,6 +80,7 @@ public class Hebdobot extends PircBot
|
||||
private CronSettings cronSettings;
|
||||
private UserAliases aliases;
|
||||
private CronManager cronManager;
|
||||
private HookManager hooker;
|
||||
|
||||
/**
|
||||
* Instantiates a new hebdobot.
|
||||
@ -122,6 +118,26 @@ public class Hebdobot extends PircBot
|
||||
this.aliases = new UserAliases();
|
||||
|
||||
this.cronManager = null;
|
||||
|
||||
//
|
||||
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());
|
||||
this.hooker.add(new MissingHook());
|
||||
this.hooker.add(new StartReviewHook());
|
||||
this.hooker.add(new StopReviewHook());
|
||||
this.hooker.add(new StatusHook());
|
||||
|
||||
this.hooker.add(new LicenseHook());
|
||||
this.hooker.add(new VersionHook());
|
||||
this.hooker.add(new HelloHook());
|
||||
this.hooker.add(new ThanksHook());
|
||||
this.hooker.add(new DefaultHook());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,6 +159,11 @@ public class Hebdobot extends PircBot
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
public CronManager getCronManager()
|
||||
{
|
||||
return this.cronManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cron settings.
|
||||
*
|
||||
@ -183,6 +204,11 @@ public class Hebdobot extends PircBot
|
||||
return this.pastebinSettings;
|
||||
}
|
||||
|
||||
public Review getReview()
|
||||
{
|
||||
return this.review;
|
||||
}
|
||||
|
||||
public File getReviewDirectory()
|
||||
{
|
||||
return this.reviewDirectory;
|
||||
@ -274,449 +300,16 @@ public class Hebdobot extends PircBot
|
||||
this.review.addRaw(new Message(sender, text));
|
||||
}
|
||||
|
||||
if ((StringUtils.equalsIgnoreCase(text, "!aide")) || (StringUtils.equalsIgnoreCase(text, "!help")))
|
||||
{
|
||||
logger.info("!help caught.");
|
||||
text = message.replaceAll("^" + getName().replace("[", "\\[").replaceAll("]", "\\]") + "[,:]\\s*", "!");
|
||||
|
||||
// Help.
|
||||
sendMessage(sender, "Bienvenue " + sender);
|
||||
sendMessage(sender, "Je suis " + getName() + ", le robot de gestion des revues hebdomadaires de l'APRIL.");
|
||||
sendMessage(sender, "Voici les commandes que je comprends :");
|
||||
sendMessage(sender, " ");
|
||||
sendMessage(sender, " !aide,!help : afficher cette aide");
|
||||
sendMessage(sender, " !debut : commencer une nouvelle revue");
|
||||
sendMessage(sender, " # titre : démarrer un sujet individuel");
|
||||
sendMessage(sender, " ## titre : démarrer un sujet collectif");
|
||||
sendMessage(sender, " % message : traiter comme un commentaire");
|
||||
sendMessage(sender, " !courant : afficher le sujet en cours");
|
||||
sendMessage(sender, " !manquants : afficher qui n'a pas participé sur le dernier sujet");
|
||||
sendMessage(sender, " !fin : terminer la revue en cours");
|
||||
sendMessage(sender, " !stop : abandonner la revue en cours");
|
||||
sendMessage(sender, " !licence : afficher la licence du logiciel Hebdobot et le lien vers ses sources");
|
||||
sendMessage(sender, " !version : afficher la version d'Hebdobot");
|
||||
sendMessage(sender, " !stats : statistiques sur les précédentes revues");
|
||||
sendMessage(sender, " ");
|
||||
sendMessage(sender, "Autres commandes de dialogue : !bonjour, !date, !hello, !merci, !salut");
|
||||
}
|
||||
else if (StringUtils.equalsIgnoreCase(text, "!stop"))
|
||||
{
|
||||
logger.info("!stop caught.");
|
||||
|
||||
// Stop.
|
||||
if (this.review == null)
|
||||
{
|
||||
sendMessage("Aucune revue en cours, abandon impossible.");
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage("Abandon de la revue en cours.");
|
||||
this.review = null;
|
||||
}
|
||||
}
|
||||
else if (StringsUtils.equalsAnyIgnoreCase(text, "!debut", "!début"))
|
||||
{
|
||||
logger.info("!debut caught.");
|
||||
|
||||
if ((this.reviewWaitTime != null) && (LocalTime.now().isBefore(this.reviewWaitTime)))
|
||||
{
|
||||
sendMessage(sender + ", ce n'est pas encore l'heure.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Start.
|
||||
if (this.cronManager != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.cronManager.shutdown();
|
||||
this.hooker.attemptProcess(this, channel, sender, login, hostname, text);
|
||||
}
|
||||
catch (SchedulerException exception)
|
||||
catch (HebdobotException exception)
|
||||
{
|
||||
logger.warn("Scheduler shutdown failed.", exception);
|
||||
}
|
||||
}
|
||||
this.review = new Review(sender, this.aliases);
|
||||
sendMessage(sender, "Bonjour " + sender + ", vous êtes le conducteur de réunion.");
|
||||
sendMessage(sender, "Pour terminer la réunion, tapez \"!fin\"");
|
||||
sendMessage("% Début de la réunion hebdomadaire");
|
||||
sendMessage(
|
||||
"% rappel : toute ligne commençant par % sera considérée comme un commentaire et non prise en compte dans la synthèse");
|
||||
sendMessage("% pour connaître le point courant, taper !courant");
|
||||
}
|
||||
}
|
||||
else if (StringUtils.equalsIgnoreCase(text, "!fin"))
|
||||
{
|
||||
logger.info("!fin caught.");
|
||||
|
||||
// End.
|
||||
if (this.review == null)
|
||||
{
|
||||
sendMessage(sender + ", pas de revue en cours.");
|
||||
}
|
||||
else if (!this.review.isOwner(sender))
|
||||
{
|
||||
sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
|
||||
}
|
||||
else if (this.review.getParticipants().size() == 0)
|
||||
{
|
||||
sendMessage("Participation nulle détecté. La revue est ignorée.");
|
||||
this.review = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
String date = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
||||
String textReview = this.review.toString();
|
||||
|
||||
// Display statistics. This feature has to not break
|
||||
// Hebdobot.
|
||||
|
||||
String newMaxUserCountReport;
|
||||
String userCountReport;
|
||||
String durationReport;
|
||||
try
|
||||
{
|
||||
File reviewDataFile = new File(this.reviewDirectory, "reviewstats.csv");
|
||||
if (reviewDataFile.exists())
|
||||
{
|
||||
ReviewDatas datas = ReviewDatasFile.load(reviewDataFile);
|
||||
datas.clean();
|
||||
|
||||
newMaxUserCountReport = ReviewStatsReporter.reportNewMaxUserCount(datas, this.review.getParticipants().size());
|
||||
ReviewData currentReview = new ReviewData(LocalDateTime.now(), this.review.getParticipants().size(),
|
||||
(int) this.review.getDurationInMinutes());
|
||||
datas.add(currentReview);
|
||||
userCountReport = ReviewStatsReporter.reportUserCount(datas, currentReview.getUserCount());
|
||||
durationReport = ReviewStatsReporter.reportDuration(datas, currentReview.getDuration());
|
||||
|
||||
if (this.review.getParticipants().size() > 1)
|
||||
{
|
||||
ReviewDatasFile.append(reviewDataFile, currentReview);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Statistic file not found [{}]", reviewDataFile.getAbsolutePath());
|
||||
sendMessage("% Fichier de statistiques absent.");
|
||||
newMaxUserCountReport = null;
|
||||
userCountReport = null;
|
||||
durationReport = null;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.warn("Exception during statistics work.", exception);
|
||||
newMaxUserCountReport = null;
|
||||
userCountReport = null;
|
||||
durationReport = null;
|
||||
}
|
||||
|
||||
textReview = new StringList(textReview).appendln(newMaxUserCountReport, "\n", userCountReport, "\n", durationReport).toString();
|
||||
|
||||
//
|
||||
if (this.pastebinSettings.isValid())
|
||||
{
|
||||
logger.info("Pastebin the review.");
|
||||
try
|
||||
{
|
||||
PastebinClient pastebinClient = new PastebinClient(this.pastebinSettings.getApiKey());
|
||||
|
||||
String pastebinUrl = pastebinClient.paste(textReview, "Revue APRIL " + date, Private.UNLISTED);
|
||||
|
||||
sendMessage("% Compte-rendu de la revue : " + pastebinUrl);
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
logger.error("Error during Pastebin submit.", exception);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
logger.info("Write review file.");
|
||||
File reviewFile = new File(this.reviewDirectory, date + StringUtils.defaultString(this.reviewFileSuffix, DEFAULT_SUFFIX));
|
||||
if (reviewFile.exists())
|
||||
{
|
||||
LocalTime now = LocalTime.now();
|
||||
String newSuffix = String.format("-%02dh%02d.txt", now.getHour(), now.getMinute());
|
||||
reviewFile = new File(reviewFile.getAbsolutePath().replace(".txt", newSuffix));
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!this.reviewDirectory.exists())
|
||||
{
|
||||
logger.info("Create review directory: " + this.reviewDirectory.getAbsolutePath());
|
||||
this.reviewDirectory.mkdirs();
|
||||
}
|
||||
FileUtils.writeStringToFile(reviewFile, textReview, StandardCharsets.UTF_8);
|
||||
logger.info("File review saved in: [{}]", reviewFile.getAbsolutePath());
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
logger.error("Error during file writing", exception);
|
||||
}
|
||||
|
||||
sendMessage("% Durée de la revue : " + this.review.getDurationInMinutes() + " minutes");
|
||||
sendMessage("% Nombre de personnes participantes : " + this.review.getParticipants().size());
|
||||
|
||||
// Display statistics.
|
||||
if (newMaxUserCountReport != null)
|
||||
{
|
||||
sendMessage("% " + newMaxUserCountReport);
|
||||
}
|
||||
|
||||
if (userCountReport != null)
|
||||
{
|
||||
sendMessage(this.review.getOwner(), userCountReport);
|
||||
}
|
||||
|
||||
if (durationReport != null)
|
||||
{
|
||||
sendMessage(this.review.getOwner(), durationReport);
|
||||
}
|
||||
|
||||
String participants = StringUtils.join(this.review.getParticipants(), " ");
|
||||
sendMessage("% " + participants + ", pensez à noter votre bénévalo : http://www.april.org/my?action=benevalo");
|
||||
|
||||
String reminderMessage = String.format(
|
||||
"%% %s, ne pas oublier d'ajouter le compte-rendu de la revue sur https://agir.april.org/issues/135 en utilisant comme nom de fichier %s",
|
||||
this.review.getOwner(), reviewFile.getName());
|
||||
logger.info("reminderMessage=[{}]", reminderMessage);
|
||||
sendMessage(reminderMessage);
|
||||
|
||||
// Finalize review.
|
||||
sendMessage("% Fin de la revue hebdomadaire");
|
||||
sendMessage(this.review.getOwner(), "Revue finie.");
|
||||
|
||||
this.review = null;
|
||||
}
|
||||
}
|
||||
else if (text.matches("\\s*##.*"))
|
||||
{
|
||||
logger.info("\\s*##.* caught.");
|
||||
|
||||
// Collective topic, must be before individual topic.
|
||||
if (this.review != null)
|
||||
{
|
||||
if (this.review.isOwner(sender))
|
||||
{
|
||||
CollectiveTopic topic = new CollectiveTopic(text.replaceFirst("##", "").trim());
|
||||
if (!this.review.isEmpty())
|
||||
{
|
||||
String participants = StringUtils.join(this.review.getParticipants(), " ");
|
||||
sendMessage(String.format("%% %s, on va passer à la suite : %s", participants, topic.getTitle()));
|
||||
}
|
||||
this.review.begin(topic);
|
||||
sendMessage("Sujet collectif : " + topic.getTitle());
|
||||
sendMessage("% 1 minute max");
|
||||
sendMessage("% si rien à signaler vous pouvez écrire % ras");
|
||||
sendMessage("% quand vous avez fini vous le dites par % fini");
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (text.matches("\\s*#[^#].*"))
|
||||
{
|
||||
logger.info("\\s*#[^#].* caught.");
|
||||
|
||||
// Individual topic.
|
||||
if (this.review != null)
|
||||
{
|
||||
if (this.review.isOwner(sender))
|
||||
{
|
||||
IndividualTopic topic = new IndividualTopic(text.replaceFirst("#", "").trim());
|
||||
if (!this.review.isEmpty())
|
||||
{
|
||||
String participants = StringUtils.join(this.review.getParticipants(), " ");
|
||||
sendMessage(String.format("%% %s, on va passer à la suite : %s", participants, topic.getTitle()));
|
||||
}
|
||||
this.review.begin(topic);
|
||||
sendMessage("Sujet individuel : " + topic.getTitle());
|
||||
sendMessage("% si rien à signaler vous pouvez écrire % ras");
|
||||
sendMessage("% quand vous avez fini vous le dites par % fini");
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (StringUtils.equalsIgnoreCase(text, "!manquants"))
|
||||
{
|
||||
logger.info("!manquants caught.");
|
||||
|
||||
// Missing.
|
||||
if (this.review == null)
|
||||
{
|
||||
sendMessage("Pas de revue en cours.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Topic topic = this.review.getCurrentTopic();
|
||||
if (topic == null)
|
||||
{
|
||||
sendMessage("Aucun sujet traité");
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<String> participants = this.review.getParticipants();
|
||||
Collection<String> currentParticipants = topic.getParticipants();
|
||||
|
||||
Collection<String> missing = CollectionUtils.subtract(participants, currentParticipants);
|
||||
if (missing.isEmpty())
|
||||
{
|
||||
sendMessage("Aucun participant manquant \\o/");
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(
|
||||
String.format("Les personnes participantes suivantes sont manquantes : %1s", StringUtils.join(missing, ", ")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (StringUtils.equalsIgnoreCase(text, "!courant"))
|
||||
{
|
||||
logger.info("!courant caught.");
|
||||
|
||||
// Current.
|
||||
if (this.review == null)
|
||||
{
|
||||
sendMessage("Pas de revue en cours.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Topic current = this.review.getCurrentTopic();
|
||||
if (current == null)
|
||||
{
|
||||
sendMessage("% Pas de sujet en cours");
|
||||
}
|
||||
else if (current instanceof IndividualTopic)
|
||||
{
|
||||
sendMessage("% Sujet individuel en cours : " + current.getTitle());
|
||||
}
|
||||
else if (current instanceof CollectiveTopic)
|
||||
{
|
||||
sendMessage("% Sujet collectif en cours : " + current.getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (StringUtils.equalsIgnoreCase(text, "!statut"))
|
||||
{
|
||||
logger.info("!status caught.");
|
||||
|
||||
sendMessage(sender, sender + ", voici l'état d'Hebdobot :");
|
||||
sendMessage(sender, " revue en cours : " + (this.review != null));
|
||||
if (this.review == null)
|
||||
{
|
||||
sendMessage(sender, " animateur revue : none");
|
||||
}
|
||||
else
|
||||
{
|
||||
sendMessage(sender, " animateur revue : " + this.review.getOwner());
|
||||
}
|
||||
sendMessage(sender, " Alias settings : " + (this.aliases.size()));
|
||||
sendMessage(sender, " Identica settings : " + (this.identicaSettings.isValid()));
|
||||
sendMessage(sender, " Pastebin settings : " + (this.pastebinSettings.isValid()));
|
||||
sendMessage(sender, " Twitter settings : " + (this.twitterSettings.isValid()));
|
||||
sendMessage(sender, " Cron settings : " + (this.cronSettings.size()));
|
||||
sendMessage(sender, " Review Wait Time : " + (this.reviewWaitTime));
|
||||
}
|
||||
else if (StringsUtils.equalsAnyIgnoreCase(text, "!licence", "!license"))
|
||||
{
|
||||
logger.info("!licence caught.");
|
||||
|
||||
sendMessage(sender
|
||||
+ ", Hebdobot est un logiciel libre de l'April sous licence GNU AGPL (sources : https://agir.april.org/projects/hebdobot/repository).");
|
||||
}
|
||||
else if (StringsUtils.equalsAnyIgnoreCase(text, "!version"))
|
||||
{
|
||||
logger.info("!version caught.");
|
||||
sendMessage(new BuildInformation().toString());
|
||||
}
|
||||
else if (text.startsWith("%"))
|
||||
{
|
||||
logger.info("% caught.");
|
||||
|
||||
// Ignore.
|
||||
}
|
||||
else if (StringsUtils.equalsAnyIgnoreCase(text, "!salut", "!bonjour", "!hello"))
|
||||
{
|
||||
logger.info("!salut caught.");
|
||||
|
||||
// Salutation command.
|
||||
sendMessage(sender + ", bonjour \\o/");
|
||||
}
|
||||
else if (StringsUtils.equalsAnyIgnoreCase(text, "!merci"))
|
||||
{
|
||||
logger.info("!merci caught.");
|
||||
|
||||
// Salutation command.
|
||||
sendMessage(sender + ", de rien \\o/");
|
||||
}
|
||||
else if (StringsUtils.equalsAnyIgnoreCase(text, "!date", "!time"))
|
||||
{
|
||||
logger.info("!date caught.");
|
||||
|
||||
// Date command.
|
||||
sendMessage(LocalDateTime.now().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy HH'h'mm", Locale.FRENCH)));
|
||||
}
|
||||
else if (StringsUtils.equalsAnyIgnoreCase(text, "!stats"))
|
||||
{
|
||||
logger.info("!stats caught.");
|
||||
|
||||
// Display statistics. This feature has to not break
|
||||
// Hebdobot.
|
||||
try
|
||||
{
|
||||
File reviewDataFile = new File(this.reviewDirectory, "reviewstats.csv");
|
||||
if (reviewDataFile.exists())
|
||||
{
|
||||
ReviewDatas datas = ReviewDatasFile.load(reviewDataFile);
|
||||
datas.clean();
|
||||
sendMessage("% " + ReviewStatsReporter.reportUserCountBoard(datas));
|
||||
sendMessage("% " + ReviewStatsReporter.reportDurationBoard(datas));
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Statistic file not found [{}]", reviewDataFile.getAbsolutePath());
|
||||
sendMessage("% Fichier de statistiques absent.");
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.warn("Exception during statistics work.", exception);
|
||||
sendMessage("% Impossible d'afficher des statistiques.");
|
||||
}
|
||||
}
|
||||
else if (text.startsWith("!"))
|
||||
{
|
||||
logger.info("!??? caught.");
|
||||
|
||||
// Command unknown.
|
||||
// Do not answer because it can be a command to another bot.
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info("All the other caught.");
|
||||
|
||||
// Topic message.
|
||||
if (this.review == null)
|
||||
{
|
||||
if ((StringsUtils.containsAnyIgnoreCase(text, "bonjour", "salut", "hello")) && (StringUtils.containsIgnoreCase(text, "hebdobot")))
|
||||
{
|
||||
sendMessage(sender + ", bonjour \\o/");
|
||||
}
|
||||
else if ((StringsUtils.containsAnyIgnoreCase(text, "merci")) && (StringUtils.containsIgnoreCase(text, "hebdobot")))
|
||||
{
|
||||
sendMessage(sender + ", de rien \\o/");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.review.add(new Message(sender, text));
|
||||
}
|
||||
logger.error("Error managing post.", exception);
|
||||
sendMessage("/me a choppé un bug : ", exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -838,6 +431,16 @@ public class Hebdobot extends PircBot
|
||||
this.homeDirectory = homeDirectory;
|
||||
}
|
||||
|
||||
public void setReview(final Review review)
|
||||
{
|
||||
this.review = review;
|
||||
}
|
||||
|
||||
public void setReviewDirectory(final File reviewDirectory)
|
||||
{
|
||||
this.reviewDirectory = reviewDirectory;
|
||||
}
|
||||
|
||||
public void setReviewFileSuffix(final String reviewFileSuffix)
|
||||
{
|
||||
this.reviewFileSuffix = reviewFileSuffix;
|
||||
|
80
src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java
Normal file
80
src/org/april/hebdobot/bot/hooks/CollectiveSubjectHook.java
Normal file
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <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.april.hebdobot.bot.review.CollectiveTopic;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class CollectiveSubjectHook.
|
||||
*/
|
||||
public class CollectiveSubjectHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(CollectiveSubjectHook.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("\\s*##.*"))
|
||||
{
|
||||
logger.info("\\s*##.* caught.");
|
||||
|
||||
// Collective topic, must be before individual topic.
|
||||
if (bot.getReview() != null)
|
||||
{
|
||||
if (bot.getReview().isOwner(sender))
|
||||
{
|
||||
CollectiveTopic topic = new CollectiveTopic(message.replaceFirst("##", "").trim());
|
||||
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.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");
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
57
src/org/april/hebdobot/bot/hooks/CommentHook.java
Normal file
57
src/org/april/hebdobot/bot/hooks/CommentHook.java
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import org.april.hebdobot.bot.Hebdobot;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class CommentHook.
|
||||
*/
|
||||
public class CommentHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(CommentHook.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.startsWith("%"))
|
||||
{
|
||||
logger.info("% caught.");
|
||||
|
||||
// Ignore.
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
81
src/org/april/hebdobot/bot/hooks/CurrentHook.java
Normal file
81
src/org/april/hebdobot/bot/hooks/CurrentHook.java
Normal file
@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <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.april.hebdobot.bot.review.CollectiveTopic;
|
||||
import org.april.hebdobot.bot.review.IndividualTopic;
|
||||
import org.april.hebdobot.bot.review.Topic;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class CurrentHook.
|
||||
*/
|
||||
public class CurrentHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(CurrentHook.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.equalsIgnoreCase(message, "!manquants"))
|
||||
{
|
||||
logger.info("!courant caught.");
|
||||
|
||||
// Current.
|
||||
if (bot.getReview() == null)
|
||||
{
|
||||
bot.sendMessage("Pas de revue en cours.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Topic current = bot.getReview().getCurrentTopic();
|
||||
if (current == null)
|
||||
{
|
||||
bot.sendMessage("% Pas de sujet en cours");
|
||||
}
|
||||
else if (current instanceof IndividualTopic)
|
||||
{
|
||||
bot.sendMessage("% Sujet individuel en cours : " + current.getTitle());
|
||||
}
|
||||
else if (current instanceof CollectiveTopic)
|
||||
{
|
||||
bot.sendMessage("% Sujet collectif en cours : " + current.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
62
src/org/april/hebdobot/bot/hooks/DateHook.java
Normal file
62
src/org/april/hebdobot/bot/hooks/DateHook.java
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (C) 2018 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 java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.april.hebdobot.bot.Hebdobot;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class DateHook.
|
||||
*/
|
||||
public class DateHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(DateHook.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, "!date", "!time", "!now"))
|
||||
{
|
||||
logger.info("!date caught.");
|
||||
// Date command.
|
||||
bot.sendMessage(LocalDateTime.now().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy HH'h'mm", Locale.FRENCH)));
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
56
src/org/april/hebdobot/bot/hooks/DefaultHook.java
Normal file
56
src/org/april/hebdobot/bot/hooks/DefaultHook.java
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
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 DefaultHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(DefaultHook.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 !");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.info("All the other caught.");
|
||||
}
|
||||
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
215
src/org/april/hebdobot/bot/hooks/FinishReviewHook.java
Normal file
215
src/org/april/hebdobot/bot/hooks/FinishReviewHook.java
Normal file
@ -0,0 +1,215 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.april.hebdobot.bot.Hebdobot;
|
||||
import org.april.hebdobot.bot.stats.ReviewData;
|
||||
import org.april.hebdobot.bot.stats.ReviewDatas;
|
||||
import org.april.hebdobot.bot.stats.ReviewDatasFile;
|
||||
import org.april.hebdobot.bot.stats.ReviewStatsReporter;
|
||||
import org.april.hebdobot.pastebin.PastebinClient;
|
||||
import org.april.hebdobot.pastebin.Private;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.strings.StringList;
|
||||
|
||||
/**
|
||||
* The Class FinishReviewHook.
|
||||
*/
|
||||
public class FinishReviewHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(FinishReviewHook.class);
|
||||
|
||||
public static String DEFAULT_SUFFIX = "-log-irc-revue-hebdomadaire.txt";
|
||||
|
||||
/* (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, "!fin"))
|
||||
{
|
||||
logger.info("!fin caught.");
|
||||
|
||||
// End.
|
||||
if (bot.getReview() == null)
|
||||
{
|
||||
bot.sendMessage(sender + ", pas de revue en cours.");
|
||||
}
|
||||
else if (!bot.getReview().isOwner(sender))
|
||||
{
|
||||
bot.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
|
||||
}
|
||||
else if (bot.getReview().getParticipants().size() == 0)
|
||||
{
|
||||
bot.sendMessage("Participation nulle détecté. La revue est ignorée.");
|
||||
bot.setReview(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
String date = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
||||
String textReview = bot.getReview().toString();
|
||||
|
||||
// Display statistics. This feature has to not break
|
||||
// Hebdobot.
|
||||
|
||||
String newMaxUserCountReport;
|
||||
String userCountReport;
|
||||
String durationReport;
|
||||
try
|
||||
{
|
||||
File reviewDataFile = new File(bot.getReviewDirectory(), "reviewstats.csv");
|
||||
if (reviewDataFile.exists())
|
||||
{
|
||||
ReviewDatas datas = ReviewDatasFile.load(reviewDataFile);
|
||||
datas.clean();
|
||||
|
||||
newMaxUserCountReport = ReviewStatsReporter.reportNewMaxUserCount(datas, bot.getReview().getParticipants().size());
|
||||
ReviewData currentReview = new ReviewData(LocalDateTime.now(), bot.getReview().getParticipants().size(),
|
||||
(int) bot.getReview().getDurationInMinutes());
|
||||
datas.add(currentReview);
|
||||
userCountReport = ReviewStatsReporter.reportUserCount(datas, currentReview.getUserCount());
|
||||
durationReport = ReviewStatsReporter.reportDuration(datas, currentReview.getDuration());
|
||||
|
||||
if (bot.getReview().getParticipants().size() > 1)
|
||||
{
|
||||
ReviewDatasFile.append(reviewDataFile, currentReview);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Statistic file not found [{}]", reviewDataFile.getAbsolutePath());
|
||||
bot.sendMessage("% Fichier de statistiques absent.");
|
||||
newMaxUserCountReport = null;
|
||||
userCountReport = null;
|
||||
durationReport = null;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.warn("Exception during statistics work.", exception);
|
||||
newMaxUserCountReport = null;
|
||||
userCountReport = null;
|
||||
durationReport = null;
|
||||
}
|
||||
|
||||
textReview = new StringList(textReview).appendln(newMaxUserCountReport, "\n", userCountReport, "\n", durationReport).toString();
|
||||
|
||||
//
|
||||
if (bot.getPastebinSettings().isValid())
|
||||
{
|
||||
logger.info("Pastebin the review.");
|
||||
try
|
||||
{
|
||||
PastebinClient pastebinClient = new PastebinClient(bot.getPastebinSettings().getApiKey());
|
||||
|
||||
String pastebinUrl = pastebinClient.paste(textReview, "Revue APRIL " + date, Private.UNLISTED);
|
||||
|
||||
bot.sendMessage("% Compte-rendu de la revue : " + pastebinUrl);
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
logger.error("Error during Pastebin submit.", exception);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
logger.info("Write review file.");
|
||||
File reviewFile = new File(bot.getReviewDirectory(), date + StringUtils.defaultString(bot.getReviewFileSuffix(), DEFAULT_SUFFIX));
|
||||
if (reviewFile.exists())
|
||||
{
|
||||
LocalTime now = LocalTime.now();
|
||||
String newSuffix = String.format("-%02dh%02d.txt", now.getHour(), now.getMinute());
|
||||
reviewFile = new File(reviewFile.getAbsolutePath().replace(".txt", newSuffix));
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!bot.getReviewDirectory().exists())
|
||||
{
|
||||
logger.info("Create review directory: " + bot.getReviewDirectory().getAbsolutePath());
|
||||
bot.getReviewDirectory().mkdirs();
|
||||
}
|
||||
FileUtils.writeStringToFile(reviewFile, textReview, StandardCharsets.UTF_8);
|
||||
logger.info("File review saved in: [{}]", reviewFile.getAbsolutePath());
|
||||
}
|
||||
catch (final Exception exception)
|
||||
{
|
||||
logger.error("Error during file writing", exception);
|
||||
}
|
||||
|
||||
bot.sendMessage("% Durée de la revue : " + bot.getReview().getDurationInMinutes() + " minutes");
|
||||
bot.sendMessage("% Nombre de personnes participantes : " + bot.getReview().getParticipants().size());
|
||||
|
||||
// Display statistics.
|
||||
if (newMaxUserCountReport != null)
|
||||
{
|
||||
bot.sendMessage("% " + newMaxUserCountReport);
|
||||
}
|
||||
|
||||
if (userCountReport != null)
|
||||
{
|
||||
bot.sendMessage(bot.getReview().getOwner(), userCountReport);
|
||||
}
|
||||
|
||||
if (durationReport != null)
|
||||
{
|
||||
bot.sendMessage(bot.getReview().getOwner(), durationReport);
|
||||
}
|
||||
|
||||
String participants = StringUtils.join(bot.getReview().getParticipants(), " ");
|
||||
bot.sendMessage("% " + participants + ", pensez à noter votre bénévalo : http://www.april.org/my?action=benevalo");
|
||||
|
||||
String reminderMessage = String.format(
|
||||
"%% %s, ne pas oublier d'ajouter le compte-rendu de la revue sur https://agir.april.org/issues/135 en utilisant comme nom de fichier %s",
|
||||
bot.getReview().getOwner(), reviewFile.getName());
|
||||
logger.info("reminderMessage=[{}]", reminderMessage);
|
||||
bot.sendMessage(reminderMessage);
|
||||
|
||||
// Finalize review.
|
||||
bot.sendMessage("% Fin de la revue hebdomadaire");
|
||||
bot.sendMessage(bot.getReview().getOwner(), "Revue finie.");
|
||||
|
||||
bot.setReview(null);
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
68
src/org/april/hebdobot/bot/hooks/HelloHook.java
Normal file
68
src/org/april/hebdobot/bot/hooks/HelloHook.java
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <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;
|
||||
|
||||
import fr.devinsy.strings.StringsUtils;
|
||||
|
||||
/**
|
||||
* The Class HelloHook.
|
||||
*/
|
||||
public class HelloHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(HelloHook.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, "!salut", "!bonjour", "!hello"))
|
||||
{
|
||||
logger.info("!salut caught.");
|
||||
|
||||
// Salutation command.
|
||||
bot.sendMessage(sender + ", bonjour \\o/");
|
||||
|
||||
result = true;
|
||||
}
|
||||
else if ((StringsUtils.containsAnyIgnoreCase(message, "bonjour", "salut", "hello", "yo", "hey", "hi"))
|
||||
&& (StringUtils.containsIgnoreCase(message, bot.getName())))
|
||||
{
|
||||
bot.sendMessage(sender + ", bonjour \\o/");
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
110
src/org/april/hebdobot/bot/hooks/HelpByCommandHook.java
Normal file
110
src/org/april/hebdobot/bot/hooks/HelpByCommandHook.java
Normal file
@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
76
src/org/april/hebdobot/bot/hooks/HelpHook.java
Normal file
76
src/org/april/hebdobot/bot/hooks/HelpHook.java
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <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 HelpHook.
|
||||
*/
|
||||
public class HelpHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(HelpHook.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, "!aide", "!help"))
|
||||
{
|
||||
logger.info("!help caught.");
|
||||
|
||||
// Help.
|
||||
bot.sendMessage(sender, "Bienvenue " + sender);
|
||||
bot.sendMessage(sender, "Je suis " + bot.getName() + ", le robot de gestion des revues hebdomadaires de l'APRIL.");
|
||||
bot.sendMessage(sender, "Voici les commandes que je comprends :");
|
||||
bot.sendMessage(sender, " ");
|
||||
bot.sendMessage(sender, " !aide,!help : afficher cette aide");
|
||||
bot.sendMessage(sender, " !debut : commencer une nouvelle revue");
|
||||
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, " !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, " !version : afficher la version d'Hebdobot");
|
||||
bot.sendMessage(sender, " !stats : statistiques sur les précédentes revues");
|
||||
bot.sendMessage(sender, " ");
|
||||
bot.sendMessage(sender, "Autres commandes de dialogue : !bonjour, !date, !hello, !merci, !salut");
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
65
src/org/april/hebdobot/bot/hooks/Hook.java
Normal file
65
src/org/april/hebdobot/bot/hooks/Hook.java
Normal file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import org.april.hebdobot.HebdobotException;
|
||||
import org.april.hebdobot.bot.Hebdobot;
|
||||
|
||||
/**
|
||||
* The Class Hook.
|
||||
*/
|
||||
public abstract class Hook
|
||||
{
|
||||
/**
|
||||
* Attempt process.
|
||||
*
|
||||
* @param bot
|
||||
* the bot
|
||||
* @param channel
|
||||
* the channel
|
||||
* @param sender
|
||||
* the sender
|
||||
* @param login
|
||||
* the login
|
||||
* @param hostname
|
||||
* the hostname
|
||||
* @param message
|
||||
* the message
|
||||
* @return true, if successful
|
||||
* @throws HebdobotException
|
||||
* the ememem exception
|
||||
*/
|
||||
public abstract boolean attemptProcess(Hebdobot bot, final String channel, final String sender, final String login, final String hostname,
|
||||
final String message) throws HebdobotException;
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.getClass().getName().replace("Hook", "");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
149
src/org/april/hebdobot/bot/hooks/HookManager.java
Normal file
149
src/org/april/hebdobot/bot/hooks/HookManager.java
Normal file
@ -0,0 +1,149 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
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 Interface MessageHook.
|
||||
*/
|
||||
public class HookManager
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(HookManager.class);
|
||||
|
||||
private ArrayList<Hook> hooks;
|
||||
|
||||
/**
|
||||
* Instantiates a new hook manager.
|
||||
*/
|
||||
public HookManager()
|
||||
{
|
||||
this.hooks = new ArrayList<>(30);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param hook
|
||||
* the hook
|
||||
*/
|
||||
public void add(final Hook hook)
|
||||
{
|
||||
if (hook != null)
|
||||
{
|
||||
this.hooks.add(hook);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt process.
|
||||
*
|
||||
* @param bot
|
||||
* the bot
|
||||
* @param channel
|
||||
* the channel
|
||||
* @param sender
|
||||
* the sender
|
||||
* @param login
|
||||
* the login
|
||||
* @param hostname
|
||||
* the hostname
|
||||
* @param text
|
||||
* the text
|
||||
* @return true, if successful
|
||||
* @throws HebdobotException
|
||||
*/
|
||||
public boolean attemptProcess(final Hebdobot bot, final String channel, final String sender, final String login, final String hostname,
|
||||
final String message) throws HebdobotException
|
||||
{
|
||||
boolean result;
|
||||
|
||||
boolean ended = false;
|
||||
Iterator<Hook> iterator = this.hooks.iterator();
|
||||
result = false;
|
||||
while (!ended)
|
||||
{
|
||||
if (iterator.hasNext())
|
||||
{
|
||||
Hook hook = iterator.next();
|
||||
boolean hookResult = hook.attemptProcess(bot, channel, sender, login, hostname, message);
|
||||
|
||||
if (hookResult)
|
||||
{
|
||||
ended = true;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear.
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
this.hooks.clear();
|
||||
}
|
||||
|
||||
public StringList getHookNames()
|
||||
{
|
||||
StringList result;
|
||||
|
||||
result = new StringList(this.hooks.size());
|
||||
|
||||
for (Hook hook : this.hooks)
|
||||
{
|
||||
result.add(hook.getName());
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Size.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
public int size()
|
||||
{
|
||||
int result;
|
||||
|
||||
result = this.hooks.size();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
79
src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java
Normal file
79
src/org/april/hebdobot/bot/hooks/IndividualSubjectHook.java
Normal file
@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <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.april.hebdobot.bot.review.IndividualTopic;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class IndividualSubjectHook.
|
||||
*/
|
||||
public class IndividualSubjectHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(IndividualSubjectHook.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("\\s*#[^#].*"))
|
||||
{
|
||||
logger.info("\\s*#[^#].* caught.");
|
||||
|
||||
// Individual topic.
|
||||
if (bot.getReview() != null)
|
||||
{
|
||||
if (bot.getReview().isOwner(sender))
|
||||
{
|
||||
IndividualTopic topic = new IndividualTopic(message.replaceFirst("#", "").trim());
|
||||
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.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");
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
60
src/org/april/hebdobot/bot/hooks/LicenseHook.java
Normal file
60
src/org/april/hebdobot/bot/hooks/LicenseHook.java
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import org.april.hebdobot.bot.Hebdobot;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.strings.StringsUtils;
|
||||
|
||||
/**
|
||||
* The Class LicenseHook.
|
||||
*/
|
||||
public class LicenseHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(LicenseHook.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 (StringsUtils.equalsAnyIgnoreCase(message, "!licence", "!license"))
|
||||
{
|
||||
logger.info("!licence caught.");
|
||||
|
||||
bot.sendMessage(sender
|
||||
+ ", Hebdobot est un logiciel libre de l'April sous licence GNU AGPL (sources : https://agir.april.org/projects/hebdobot/repository).");
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
90
src/org/april/hebdobot/bot/hooks/MissingHook.java
Normal file
90
src/org/april/hebdobot/bot/hooks/MissingHook.java
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.april.hebdobot.bot.Hebdobot;
|
||||
import org.april.hebdobot.bot.review.Topic;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class MissingHook.
|
||||
*/
|
||||
public class MissingHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(MissingHook.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.equalsIgnoreCase(message, "!manquants"))
|
||||
{
|
||||
logger.info("!manquants caught.");
|
||||
|
||||
// Missing.
|
||||
if (bot.getReview() == null)
|
||||
{
|
||||
bot.sendMessage("Pas de revue en cours.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Topic topic = bot.getReview().getCurrentTopic();
|
||||
if (topic == null)
|
||||
{
|
||||
bot.sendMessage("Aucun sujet traité");
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<String> participants = bot.getReview().getParticipants();
|
||||
Collection<String> currentParticipants = topic.getParticipants();
|
||||
|
||||
Collection<String> missing = CollectionUtils.subtract(participants, currentParticipants);
|
||||
if (missing.isEmpty())
|
||||
{
|
||||
bot.sendMessage("Aucun participant manquant \\o/");
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.sendMessage(
|
||||
String.format("Les personnes participantes suivantes sont manquantes : %1s", StringUtils.join(missing, ", ")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
87
src/org/april/hebdobot/bot/hooks/StartReviewHook.java
Normal file
87
src/org/april/hebdobot/bot/hooks/StartReviewHook.java
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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;
|
||||
|
||||
/**
|
||||
* The Class StartReviewHook.
|
||||
*/
|
||||
public class StartReviewHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(StartReviewHook.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, "!debut", "!début"))
|
||||
{
|
||||
logger.info("!debut caught.");
|
||||
|
||||
if ((bot.getReviewWaitTime() != null) && (LocalTime.now().isBefore(bot.getReviewWaitTime())))
|
||||
{
|
||||
bot.sendMessage(sender + ", ce n'est pas encore l'heure.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Start.
|
||||
if (bot.getCronManager() != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
bot.getCronManager().shutdown();
|
||||
}
|
||||
catch (SchedulerException exception)
|
||||
{
|
||||
logger.warn("Scheduler shutdown failed.", exception);
|
||||
}
|
||||
}
|
||||
bot.setReview(new Review(sender, bot.getAliases()));
|
||||
bot.sendMessage(sender, "Bonjour " + sender + ", vous êtes le conducteur de réunion.");
|
||||
bot.sendMessage(sender, "Pour terminer la réunion, tapez \"!fin\"");
|
||||
bot.sendMessage("% Début de la réunion hebdomadaire");
|
||||
bot.sendMessage(
|
||||
"% rappel : toute ligne commençant par % sera considérée comme un commentaire et non prise en compte dans la synthèse");
|
||||
bot.sendMessage("% pour connaître le point courant, taper !courant");
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
84
src/org/april/hebdobot/bot/hooks/StatsHook.java
Normal file
84
src/org/april/hebdobot/bot/hooks/StatsHook.java
Normal file
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.april.hebdobot.bot.Hebdobot;
|
||||
import org.april.hebdobot.bot.stats.ReviewDatas;
|
||||
import org.april.hebdobot.bot.stats.ReviewDatasFile;
|
||||
import org.april.hebdobot.bot.stats.ReviewStatsReporter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class StatsHook.
|
||||
*/
|
||||
public class StatsHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(StatsHook.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.equals("!statut"))
|
||||
{
|
||||
logger.info("!stats caught.");
|
||||
|
||||
// Display statistics. This feature has to not break
|
||||
// Hebdobot.
|
||||
try
|
||||
{
|
||||
File reviewDataFile = new File(bot.getReviewDirectory(), "reviewstats.csv");
|
||||
if (reviewDataFile.exists())
|
||||
{
|
||||
ReviewDatas datas = ReviewDatasFile.load(reviewDataFile);
|
||||
datas.clean();
|
||||
bot.sendMessage("% " + ReviewStatsReporter.reportUserCountBoard(datas));
|
||||
bot.sendMessage("% " + ReviewStatsReporter.reportDurationBoard(datas));
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Statistic file not found [{}]", reviewDataFile.getAbsolutePath());
|
||||
bot.sendMessage("% Fichier de statistiques absent.");
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.warn("Exception during statistics work.", exception);
|
||||
bot.sendMessage("% Impossible d'afficher des statistiques.");
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
72
src/org/april/hebdobot/bot/hooks/StatusHook.java
Normal file
72
src/org/april/hebdobot/bot/hooks/StatusHook.java
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import org.april.hebdobot.bot.Hebdobot;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class StatusHook.
|
||||
*/
|
||||
public class StatusHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(StatusHook.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.equals("!statut"))
|
||||
{
|
||||
logger.info("!status caught.");
|
||||
|
||||
bot.sendMessage(sender, sender + ", voici l'état d'Hebdobot :");
|
||||
bot.sendMessage(sender, " revue en cours : " + (bot.getReview() != null));
|
||||
if (bot.getReview() == null)
|
||||
{
|
||||
bot.sendMessage(sender, " animateur revue : none");
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.sendMessage(sender, " animateur revue : " + bot.getReview().getOwner());
|
||||
}
|
||||
bot.sendMessage(sender, " Alias settings : " + (bot.getAliases().size()));
|
||||
bot.sendMessage(sender, " Identica settings : " + (bot.getIdenticaSettings().isValid()));
|
||||
bot.sendMessage(sender, " Pastebin settings : " + (bot.getPastebinSettings().isValid()));
|
||||
bot.sendMessage(sender, " Twitter settings : " + (bot.getTwitterSettings().isValid()));
|
||||
bot.sendMessage(sender, " Cron settings : " + (bot.getCronSettings().size()));
|
||||
bot.sendMessage(sender, " Review Wait Time : " + (bot.getReviewWaitTime()));
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
67
src/org/april/hebdobot/bot/hooks/StopReviewHook.java
Normal file
67
src/org/april/hebdobot/bot/hooks/StopReviewHook.java
Normal file
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright (C) 2018 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 StopReviewHook.
|
||||
*/
|
||||
public class StopReviewHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(StopReviewHook.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, "!stop"))
|
||||
{
|
||||
logger.info("!stop caught.");
|
||||
|
||||
// Stop.
|
||||
if (bot.getReview() == null)
|
||||
{
|
||||
bot.sendMessage("Aucune revue en cours, abandon impossible.");
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.sendMessage("Abandon de la revue en cours.");
|
||||
bot.setReview(null);
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
65
src/org/april/hebdobot/bot/hooks/ThanksHook.java
Normal file
65
src/org/april/hebdobot/bot/hooks/ThanksHook.java
Normal file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <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;
|
||||
|
||||
import fr.devinsy.strings.StringsUtils;
|
||||
|
||||
/**
|
||||
* The Class ThanksHook.
|
||||
*/
|
||||
public class ThanksHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(ThanksHook.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 (StringsUtils.equalsAnyIgnoreCase(message, "!merci"))
|
||||
{
|
||||
logger.info("!merci caught.");
|
||||
bot.sendMessage(sender + ", de rien \\o/");
|
||||
|
||||
result = true;
|
||||
}
|
||||
else if ((StringsUtils.containsAnyIgnoreCase(message, "merci")) && (StringUtils.containsIgnoreCase(message, bot.getName())))
|
||||
{
|
||||
bot.sendMessage(sender + ", de rien \\o/");
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
57
src/org/april/hebdobot/bot/hooks/VersionHook.java
Normal file
57
src/org/april/hebdobot/bot/hooks/VersionHook.java
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package org.april.hebdobot.bot.hooks;
|
||||
|
||||
import org.april.hebdobot.bot.Hebdobot;
|
||||
import org.april.hebdobot.util.BuildInformation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class VersionHook.
|
||||
*/
|
||||
public class VersionHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(VersionHook.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.equals("!version"))
|
||||
{
|
||||
logger.info("!version caught.");
|
||||
bot.sendMessage(new BuildInformation().toString());
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user