Fixed suffix in number display (#3541). Added record command.
This commit is contained in:
parent
680b2b56d8
commit
18bd91eec2
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
|
||||
* Copyright (C) 2011-2013,2017 Nicolas Vinot <aeris@imirhil.fr>
|
||||
*
|
||||
* This file is part of (April) Hebdobot.
|
||||
@ -40,6 +40,7 @@ import org.april.hebdobot.bot.hooks.IndividualSubjectHook;
|
||||
import org.april.hebdobot.bot.hooks.InputReviewHook;
|
||||
import org.april.hebdobot.bot.hooks.LicenseHook;
|
||||
import org.april.hebdobot.bot.hooks.MissingHook;
|
||||
import org.april.hebdobot.bot.hooks.RecordHook;
|
||||
import org.april.hebdobot.bot.hooks.StartReviewHook;
|
||||
import org.april.hebdobot.bot.hooks.StatsHook;
|
||||
import org.april.hebdobot.bot.hooks.StatusHook;
|
||||
@ -141,6 +142,7 @@ public class Hebdobot extends PircBot
|
||||
this.hooker.add(new HelpHook());
|
||||
this.hooker.add(new IndividualSubjectHook());
|
||||
this.hooker.add(new MissingHook());
|
||||
this.hooker.add(new RecordHook());
|
||||
this.hooker.add(new StartReviewHook());
|
||||
this.hooker.add(new StopReviewHook());
|
||||
this.hooker.add(new StatsHook());
|
||||
|
@ -58,8 +58,9 @@ public class HelpHook extends Hook
|
||||
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, " !record : affiche le record de participation à la revue");
|
||||
bot.sendMessage(sender, " !stats : statistiques sur les précédentes revues");
|
||||
bot.sendMessage(sender, " !version : afficher la version d'Hebdobot");
|
||||
bot.sendMessage(sender, " ");
|
||||
bot.sendMessage(sender, "Autres commandes de dialogue : !bonjour, !date, !hello, !merci, !salut");
|
||||
|
||||
|
83
src/org/april/hebdobot/bot/hooks/RecordHook.java
Normal file
83
src/org/april/hebdobot/bot/hooks/RecordHook.java
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* 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.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 RecordHook.
|
||||
*/
|
||||
public class RecordHook extends Hook
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(RecordHook.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("!record"))
|
||||
{
|
||||
logger.info("!record caught.");
|
||||
|
||||
// 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.reportUserCountRecord(datas));
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.warn("Statistic file not found [{}]", reviewDataFile.getAbsolutePath());
|
||||
bot.sendMessage("% Fichier de statistiques absent.");
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.warn("Exception during record work.", exception);
|
||||
bot.sendMessage("% Impossible d'afficher le record.");
|
||||
}
|
||||
|
||||
//
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (C) 2017-2018 Christian Pierre MOMON <cmomon@april.org>
|
||||
* Copyright (C) 2017-2019 Christian Pierre MOMON <cmomon@april.org>
|
||||
*
|
||||
* This file is part of (April) Hebdobot.
|
||||
*
|
||||
@ -39,6 +39,30 @@ public class ReviewStatsReporter
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Number suffix.
|
||||
*
|
||||
* @param number
|
||||
* the number
|
||||
* @return the string
|
||||
*/
|
||||
public static String numberSuffix(final long number)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (number == 1)
|
||||
{
|
||||
result = "ère";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = "è";
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percent.
|
||||
*
|
||||
@ -205,8 +229,10 @@ public class ReviewStatsReporter
|
||||
else
|
||||
{
|
||||
long currentYear = LocalDateTime.now().getYear();
|
||||
result = String.format("C'était la %dè revue hebdomadaire de l'April, la %dè de l'année %d.", datas.size(),
|
||||
datas.countByYear(currentYear), currentYear);
|
||||
long reviewYearCount = datas.countByYear(currentYear);
|
||||
|
||||
result = String.format("C'était la %d%s revue hebdomadaire de l'April, la %d%s de l'année %d.", datas.size(), numberSuffix(datas.size()),
|
||||
reviewYearCount, numberSuffix(reviewYearCount), currentYear);
|
||||
}
|
||||
|
||||
//
|
||||
@ -272,4 +298,32 @@ public class ReviewStatsReporter
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report max user count.
|
||||
*
|
||||
* @param datas
|
||||
* the datas
|
||||
* @param currentUserCount
|
||||
* the current user count
|
||||
* @return the string
|
||||
*/
|
||||
public static String reportUserCountRecord(final ReviewDatas datas)
|
||||
{
|
||||
String result;
|
||||
|
||||
if ((datas == null) || (datas.isEmpty()))
|
||||
{
|
||||
result = "Indisponibilité de statistiques sur la participation à la revue.";
|
||||
}
|
||||
else
|
||||
{
|
||||
ReviewData recordReview = datas.getLastByMaxUserCount();
|
||||
String recordDate = recordReview.getDate().format(DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy", Locale.FRENCH));
|
||||
result = String.format("Le record de participation est de %d personnes et remonte au %s.", recordReview.getUserCount(), recordDate);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user