/** * Copyright (C) 2018 Christian Pierre MOMON * * This file is part of (April) Hebdobot. * * Hebdobot is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Hebdobot is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Hebdobot. If not, see */ package org.april.hebdobot.bot.hooks; import 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("!stats")) { 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.reportReviewCount(datas)); 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; } }