From 81cd7d86733eee7975e7e010768f383a6891eb8b Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 28 Dec 2017 04:21:54 +0100 Subject: [PATCH] Refactored the notify management. --- resources/hedbobot-sample.conf | 13 ++ resources/log4j.properties | 2 + src/org/april/hebdobot/cli/HebdobotCLI.java | 2 + .../hebdobot/cli/HebdobotConfigFile.java | 131 ++++++++++++++++-- src/org/april/hebdobot/cron/CronFooJob.java | 43 ++++++ src/org/april/hebdobot/cron/CronListener.java | 124 +++++++++++++++++ src/org/april/hebdobot/cron/CronManager.java | 104 ++++++++++++++ src/org/april/hebdobot/cron/CronSettings.java | 37 +++++ src/org/april/hebdobot/cron/CronValue.java | 90 ++++++++++++ src/org/april/hebdobot/model/Hebdobot.java | 55 +++++++- src/org/april/hebdobot/model/Job.java | 96 ------------- test/hebdobot-test.conf | 46 ++++-- 12 files changed, 614 insertions(+), 129 deletions(-) create mode 100644 src/org/april/hebdobot/cron/CronFooJob.java create mode 100644 src/org/april/hebdobot/cron/CronListener.java create mode 100644 src/org/april/hebdobot/cron/CronManager.java create mode 100644 src/org/april/hebdobot/cron/CronSettings.java create mode 100644 src/org/april/hebdobot/cron/CronValue.java delete mode 100644 src/org/april/hebdobot/model/Job.java diff --git a/resources/hedbobot-sample.conf b/resources/hedbobot-sample.conf index aae182c..f833666 100644 --- a/resources/hedbobot-sample.conf +++ b/resources/hedbobot-sample.conf @@ -25,3 +25,16 @@ hebdobot.irc.channel=#april-test #hebdobot.twitter.consumerSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #hebdobot.twitter.accessToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #hebdobot.twitter.accessTokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + +# Notifications +#notify.at5.cron=0 55 11 ? * * +#notify.at5.irc=Revue hebdomadaire dans 5 minutes +#notify.at5.twitter=Revue hebdomadaire !april dans 5 minutes sur irc://irc.freenode.org/april ou http://apr1.org/8l + +notify.at15.cron=0 45 11 ? * * +notify.at15.irc=Revue hebdomadaire dans 15 minutes +notify.at15.twitter=Revue hebdomadaire !april dans 15 minutes sur irc://irc.freenode.org/april ou http://apr1.org/8l + +#notify.at30.cron=0 30 11 ? * * +#notify.at30.irc=Revue hebdomadaire dans 30 minutes +#notify.at30.twitter=Revue hebdomadaire !april dans 30 minutes sur irc://irc.freenode.org/april ou http://apr1.org/8l diff --git a/resources/log4j.properties b/resources/log4j.properties index 1dae77d..c330438 100644 --- a/resources/log4j.properties +++ b/resources/log4j.properties @@ -5,3 +5,5 @@ log4j.logger.org.april.hebdobot = info log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %d %-5p %c - %m%n +#log4j.appender.CONSOLE.layout.ConversionPattern = %d{ISO8601} - Hebdobot [%-5p] %34.34c.%25M - %m%n + diff --git a/src/org/april/hebdobot/cli/HebdobotCLI.java b/src/org/april/hebdobot/cli/HebdobotCLI.java index bee6072..6d011fe 100644 --- a/src/org/april/hebdobot/cli/HebdobotCLI.java +++ b/src/org/april/hebdobot/cli/HebdobotCLI.java @@ -151,6 +151,8 @@ public class HebdobotCLI bot.getTwitterSettings().setConsumerKey(config.getTwitterConsumerKey()); bot.getTwitterSettings().setConsumerSecret(config.getTwitterConsumerSecret()); bot.getAliases().putAll(aliases); + bot.getCronSettings().addAll(config.getCronSettings()); + logger.info("Bot configured."); bot.run(); diff --git a/src/org/april/hebdobot/cli/HebdobotConfigFile.java b/src/org/april/hebdobot/cli/HebdobotConfigFile.java index 20dc77c..7894161 100644 --- a/src/org/april/hebdobot/cli/HebdobotConfigFile.java +++ b/src/org/april/hebdobot/cli/HebdobotConfigFile.java @@ -24,10 +24,14 @@ import java.io.IOException; import java.util.Properties; import org.april.hebdobot.HebdobotException; +import org.april.hebdobot.cron.CronSettings; +import org.april.hebdobot.cron.CronValue; import org.april.hebdobot.util.HebdobotUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.util.strings.StringSet; + /** * The Class Launcher. */ @@ -67,6 +71,34 @@ public class HebdobotConfigFile extends Properties } } + /** + * Gets the cron settings. + * + * @return the cron settings + */ + public CronSettings getCronSettings() + { + CronSettings result; + + result = new CronSettings(); + + for (String notifyName : getNotifyNames()) + { + String notifyCron = getNotifyCron(notifyName); + String notifyIrcMessage = getNotifyIrcMessage(notifyName); + String notifyTwitterMessage = getNotifyTwitterMessage(notifyName); + + CronValue cronValue = new CronValue(notifyName, notifyCron, notifyIrcMessage, notifyTwitterMessage); + + result.add(cronValue); + } + + logger.debug("Cron settings count=" + result.size()); + + // + return result; + } + /** * Gets the identica api key. * @@ -76,7 +108,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.identica.apiKey"); + result = getProperty("identica.apiKey"); // return result; @@ -91,7 +123,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.identica.apiSecret"); + result = getProperty("identica.apiSecret"); // return result; @@ -106,7 +138,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.irc.channel"); + result = getProperty("irc.channel"); // return result; @@ -121,7 +153,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.irc.host"); + result = getProperty("irc.host"); // return result; @@ -136,7 +168,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.irc.name"); + result = getProperty("irc.name"); // return result; @@ -151,7 +183,82 @@ public class HebdobotConfigFile extends Properties { Integer result; - result = HebdobotUtils.toInteger(getProperty("hebdobot.irc.port")); + result = HebdobotUtils.toInteger(getProperty("irc.port")); + + // + return result; + } + + /** + * Gets the notification names. + * + * @return the notification names + */ + public String getNotifyCron(final String notifyName) + { + String result; + + result = getProperty("notify." + notifyName + ".cron"); + + // + return result; + } + + /** + * Gets the notify irc message. + * + * @param notifyName + * the notify name + * @return the notify irc message + */ + public String getNotifyIrcMessage(final String notifyName) + { + String result; + + result = getProperty("notify." + notifyName + ".irc"); + + // + return result; + } + + /** + * Gets the notification names. + * + * @return the notification names + */ + public StringSet getNotifyNames() + { + StringSet result; + + result = new StringSet(); + + for (Object key : this.keySet()) + { + String propertyName = (String) key; + + if (propertyName.startsWith("notify.")) + { + String notifyName = propertyName.split("\\.")[1]; + result.add(notifyName); + } + } + + // + return result; + } + + /** + * Gets the notify twitter message. + * + * @param notifyName + * the notify name + * @return the notify twitter message + */ + public String getNotifyTwitterMessage(final String notifyName) + { + String result; + + result = getProperty("notify." + notifyName + ".twitter"); // return result; @@ -166,7 +273,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.pastebin.apiKey"); + result = getProperty("pastebin.apiKey"); // return result; @@ -181,7 +288,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.review.file.suffix"); + result = getProperty("review.file.suffix"); // return result; @@ -196,7 +303,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.twitter.accessToken"); + result = getProperty("twitter.accessToken"); // return result; @@ -211,7 +318,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.twitter.accessTokenSecret"); + result = getProperty("twitter.accessTokenSecret"); // return result; @@ -226,7 +333,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.twitter.consumerKey"); + result = getProperty("twitter.consumerKey"); // return result; @@ -241,7 +348,7 @@ public class HebdobotConfigFile extends Properties { String result; - result = getProperty("hebdobot.twitter.consumerSecret"); + result = getProperty("twitter.consumerSecret"); // return result; diff --git a/src/org/april/hebdobot/cron/CronFooJob.java b/src/org/april/hebdobot/cron/CronFooJob.java new file mode 100644 index 0000000..3dc0a6e --- /dev/null +++ b/src/org/april/hebdobot/cron/CronFooJob.java @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2011-2013,2017 Nicolas Vinot + * Copyright (C) 2017 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.cron; + +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class Job. + */ +public class CronFooJob implements Job +{ + private static final Logger logger = LoggerFactory.getLogger(CronFooJob.class); + + /* (non-Javadoc) + * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) + */ + @Override + public void execute(final JobExecutionContext context) throws JobExecutionException + { + logger.debug("CRON JOB"); + } +} diff --git a/src/org/april/hebdobot/cron/CronListener.java b/src/org/april/hebdobot/cron/CronListener.java new file mode 100644 index 0000000..9626183 --- /dev/null +++ b/src/org/april/hebdobot/cron/CronListener.java @@ -0,0 +1,124 @@ +/** + * Copyright (C) 2011-2013,2017 Nicolas Vinot + * Copyright (C) 2017 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.cron; + +import org.apache.commons.lang3.StringUtils; +import org.april.hebdobot.model.Hebdobot; +import org.quartz.JobExecutionContext; +import org.quartz.Trigger; +import org.quartz.Trigger.CompletedExecutionInstruction; +import org.quartz.TriggerListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class Job. + */ +public class CronListener implements TriggerListener +{ + private static final Logger logger = LoggerFactory.getLogger(CronListener.class); + + private CronValue cron; + private Hebdobot bot; + + /** + * Instantiates a new cron listener. + * + * @param name + * the name + */ + public CronListener(final Hebdobot bot, final CronValue cron) + { + if (cron == null) + { + throw new IllegalArgumentException("Null parameter cron."); + } + else if (bot == null) + { + throw new IllegalArgumentException("Null parameter bot."); + } + else + { + this.bot = bot; + this.cron = cron; + } + } + + /* (non-Javadoc) + * @see org.quartz.TriggerListener#getName() + */ + @Override + public String getName() + { + return this.cron.getName(); + } + + /* (non-Javadoc) + * @see org.quartz.TriggerListener#triggerComplete(org.quartz.Trigger, org.quartz.JobExecutionContext, org.quartz.Trigger.CompletedExecutionInstruction) + */ + @Override + public void triggerComplete(final Trigger trigger, final JobExecutionContext context, final CompletedExecutionInstruction triggerInstructionCode) + { + } + + /* (non-Javadoc) + * @see org.quartz.TriggerListener#triggerFired(org.quartz.Trigger, org.quartz.JobExecutionContext) + */ + @Override + public void triggerFired(final Trigger trigger, final JobExecutionContext context) + { + logger.info("CRON FIRE " + context.getTrigger().getDescription()); + + if (StringUtils.isBlank(this.cron.getIrcMessage())) + { + logger.info("No IRC message so no notify."); + } + else + { + this.bot.notifyIrc(this.cron.getIrcMessage()); + } + + if (StringUtils.isBlank(this.cron.getTwitterMessage())) + { + logger.info("No Twitter message so no notify."); + } + else + { + this.bot.notifyTwitter(this.cron.getTwitterMessage()); + } + } + + /* (non-Javadoc) + * @see org.quartz.TriggerListener#triggerMisfired(org.quartz.Trigger) + */ + @Override + public void triggerMisfired(final Trigger trigger) + { + } + + /* (non-Javadoc) + * @see org.quartz.TriggerListener#vetoJobExecution(org.quartz.Trigger, org.quartz.JobExecutionContext) + */ + @Override + public boolean vetoJobExecution(final Trigger trigger, final JobExecutionContext context) + { + return false; + } +} diff --git a/src/org/april/hebdobot/cron/CronManager.java b/src/org/april/hebdobot/cron/CronManager.java new file mode 100644 index 0000000..5d96781 --- /dev/null +++ b/src/org/april/hebdobot/cron/CronManager.java @@ -0,0 +1,104 @@ +/** + * Copyright (C) 2011-2013,2017 Nicolas Vinot + * Copyright (C) 2017 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.cron; + +import org.april.hebdobot.model.Hebdobot; +import org.quartz.CronScheduleBuilder; +import org.quartz.JobBuilder; +import org.quartz.JobDetail; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.Trigger; +import org.quartz.TriggerBuilder; +import org.quartz.TriggerKey; +import org.quartz.TriggerListener; +import org.quartz.impl.StdSchedulerFactory; +import org.quartz.impl.matchers.KeyMatcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class CronManager. + */ +public class CronManager +{ + private static final Logger logger = LoggerFactory.getLogger(CronManager.class); + + private CronSettings crons; + private Scheduler scheduler; + private Hebdobot bot; + + /** + * Instantiates a new cron manager. + * + * @param bot + * the bot + * @throws SchedulerException + */ + public CronManager(final Hebdobot bot, final CronSettings crons) throws SchedulerException + { + this.bot = bot; + this.crons = crons; + this.scheduler = new StdSchedulerFactory().getScheduler(); + + for (CronValue cron : crons) + { + addCron(cron); + } + } + + /** + * Adds the cron. + * + * @throws SchedulerException + */ + public void addCron(final CronValue cron) throws SchedulerException + { + Trigger trigger = TriggerBuilder.newTrigger().withDescription(cron.getName()).withIdentity(cron.getName()) + .withSchedule(CronScheduleBuilder.cronSchedule(cron.getCron())).build(); + JobDetail job = JobBuilder.newJob(CronFooJob.class).withIdentity(cron.getName()).build(); + this.scheduler.scheduleJob(job, trigger); + + TriggerListener listener = new CronListener(this.bot, cron); + this.scheduler.getListenerManager().addTriggerListener(listener, KeyMatcher.keyEquals(new TriggerKey(cron.getName()))); + } + + /** + * Shutdown. + * + * @throws SchedulerException + * the scheduler exception + */ + public void shutdown() throws SchedulerException + { + this.scheduler.shutdown(); + } + + /** + * Start. + * + * @throws SchedulerException + * the scheduler exception + */ + public void start() throws SchedulerException + { + this.scheduler.start(); + } +} diff --git a/src/org/april/hebdobot/cron/CronSettings.java b/src/org/april/hebdobot/cron/CronSettings.java new file mode 100644 index 0000000..30b1aeb --- /dev/null +++ b/src/org/april/hebdobot/cron/CronSettings.java @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2017 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.cron; + +import java.util.ArrayList; + +/** + * The Class CronValues. + */ +public class CronSettings extends ArrayList +{ + private static final long serialVersionUID = -6458988766218787076L; + + /** + * Instantiates a new cron values. + */ + public CronSettings() + { + super(); + } +} diff --git a/src/org/april/hebdobot/cron/CronValue.java b/src/org/april/hebdobot/cron/CronValue.java new file mode 100644 index 0000000..2522fe0 --- /dev/null +++ b/src/org/april/hebdobot/cron/CronValue.java @@ -0,0 +1,90 @@ +/** + * Copyright (C) 2017 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.cron; + +/** + * The Class CronValue. + */ +public class CronValue +{ + private String name; + private String cron; + private String ircMessage; + private String twitterMessage; + + /** + * Instantiates a new cron value. + * + * @param name + * the name + * @param cron + * the value + * @param ircMessage + * the irc message + * @param twitterMessage + * the twitter message + */ + public CronValue(final String name, final String cron, final String ircMessage, final String twitterMessage) + { + this.name = name; + this.cron = cron; + this.ircMessage = ircMessage; + this.twitterMessage = twitterMessage; + } + + public String getCron() + { + return this.cron; + } + + public String getIrcMessage() + { + return this.ircMessage; + } + + public String getName() + { + return this.name; + } + + public String getTwitterMessage() + { + return this.twitterMessage; + } + + public void setCron(final String value) + { + this.cron = value; + } + + public void setIrcMessage(final String ircMessage) + { + this.ircMessage = ircMessage; + } + + public void setName(final String name) + { + this.name = name; + } + + public void setTwitterMessage(final String twitterMessage) + { + this.twitterMessage = twitterMessage; + } +} diff --git a/src/org/april/hebdobot/model/Hebdobot.java b/src/org/april/hebdobot/model/Hebdobot.java index 47cb426..0e32c13 100644 --- a/src/org/april/hebdobot/model/Hebdobot.java +++ b/src/org/april/hebdobot/model/Hebdobot.java @@ -27,6 +27,8 @@ 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.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; @@ -43,6 +45,7 @@ import org.jibble.pircbot.NickAlreadyInUseException; import org.jibble.pircbot.PircBot; import org.joda.time.DateTime; import org.joda.time.format.ISODateTimeFormat; +import org.quartz.SchedulerException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +66,9 @@ public class Hebdobot extends PircBot private IdenticaSettings identicaSettings; private PastebinSettings pastebinSettings; private TwitterSettings twitterSettings; + private CronSettings cronSettings; private UserAliases aliases; + private CronManager cronManager; /** * Instantiates a new bot. @@ -89,7 +94,10 @@ public class Hebdobot extends PircBot this.identicaSettings = new IdenticaSettings(); this.pastebinSettings = new PastebinSettings(); this.twitterSettings = new TwitterSettings(); + this.cronSettings = new CronSettings(); this.aliases = new UserAliases(); + + this.cronManager = null; } /** @@ -106,6 +114,11 @@ public class Hebdobot extends PircBot return this.aliases; } + public CronSettings getCronSettings() + { + return this.cronSettings; + } + public IdenticaSettings getIdenticaSettings() { return this.identicaSettings; @@ -127,17 +140,21 @@ public class Hebdobot extends PircBot * @param minutes * the minutes */ - public void notify(final int minutes) + public void notifyIrc(final String message) { - { - String message = String.format("Revue hebdomadaire dans %dmin", minutes); - sendMessage(message); - } + sendMessage(message); + } + /** + * Notify twitter. + * + * @param message + * the message + */ + public void notifyTwitter(final String message) + { if (this.twitterSettings.isValid()) { - String message = String.format("Revue hebdomadaire !april dans %dmin sur irc://irc.freenode.org/april ou http://apr1.org/8l", minutes); - TwitterClient twitter = new TwitterClient(this.twitterSettings.getConsumerKey(), this.twitterSettings.getConsumerSecret()); twitter.tweet(message); } @@ -218,6 +235,17 @@ public class Hebdobot extends PircBot logger.info("!debut caught."); // Start. + if (this.cronManager != null) + { + try + { + this.cronManager.shutdown(); + } + catch (SchedulerException exception) + { + logger.warn("Scheduler shutdown failed.", exception); + } + } this.review = new Review(sender, this.aliases); sendMessage(sender, "Vous êtes le conducteur de réunion"); sendMessage(sender, "Pour terminer la réunion, tapez \"!fin\""); @@ -447,8 +475,17 @@ public class Hebdobot extends PircBot { try { + logger.info("Cron initializing."); + { + this.cronManager = new CronManager(this, this.cronSettings); + this.cronManager.start(); + } + logger.info("Cron initialized."); + logger.info("Bot connection."); this.connect(this.host, this.port); + logger.info("Bot connected."); + logger.info("Bot joining channel ({}).", this.channel); this.joinChannel(this.channel); logger.info("Bot ready."); @@ -465,6 +502,10 @@ public class Hebdobot extends PircBot { throw new HebdobotException(exception); } + catch (SchedulerException exception) + { + throw new HebdobotException("Error in cron settings.", exception); + } } /** diff --git a/src/org/april/hebdobot/model/Job.java b/src/org/april/hebdobot/model/Job.java deleted file mode 100644 index cb89408..0000000 --- a/src/org/april/hebdobot/model/Job.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright (C) 2011-2013,2017 Nicolas Vinot - * Copyright (C) 2017 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.model; - -import javax.annotation.Resource; - -import org.springframework.social.twitter.api.impl.TwitterTemplate; - -/** - * The Class Job. - */ -public class Job -{ - @Resource - private Hebdobot bot; - @Resource - private TwitterTemplate twitterClient; - private String tweet; - private String irc; - - /** - * At 30. - */ - public void at30() - { - this.notify(30); - } - - /** - * At 45. - */ - public void at45() - { - this.notify(15); - } - - /** - * At 55. - */ - public void at55() - { - this.notify(5); - } - - /** - * Notify. - * - * @param min - * the min - */ - private void notify(final int min) - { - this.bot.sendMessage(String.format(this.irc, min)); - final String tweet = String.format(this.tweet, min); - this.twitterClient.timelineOperations().updateStatus(tweet); - } - - /** - * Sets the irc. - * - * @param message - * the new irc - */ - public void setIrc(final String message) - { - this.irc = message; - } - - /** - * Sets the tweet. - * - * @param message - * the new tweet - */ - public void setTweet(final String message) - { - this.tweet = message; - } -} diff --git a/test/hebdobot-test.conf b/test/hebdobot-test.conf index 0133531..63e4956 100644 --- a/test/hebdobot-test.conf +++ b/test/hebdobot-test.conf @@ -3,25 +3,43 @@ # # Revue settings. -hebdobot.review.file.suffix=revue.txt +review.file.suffix=revue.txt # IRC settings. -hebdobot.irc.host=irc.freenode.org -hebdobot.irc.port=6667 -hebdobot.irc.name=Hebdobot -hebdobot.irc.channel=#april-test +irc.host=irc.freenode.org +irc.port=6667 +irc.name=Hebdobot +irc.channel=#april-test # Pastebin settings. -hebdobot.pastebin.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +pastebin.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # Ident.ca settings. -hebdobot.identica.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -hebdobot.identica.apiSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -hebdobot.identica.tokenKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -hebdobot.identica.tokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +identica.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +identica.apiSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +identica.tokenKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +identica.tokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # Twitter settings. -hebdobot.twitter.consumerKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -hebdobot.twitter.consumerSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -hebdobot.twitter.accessToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -hebdobot.twitter.accessTokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +twitter.consumerKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +twitter.consumerSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +twitter.accessToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +twitter.accessTokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + +# Notifications +notify.at5.cron=0 * * ? * * +notify.at5.irc=Revue hebdomadaire dans 1 minutes +notify.at5.twitter=Revue hebdomadaire !april dans 5 minutes sur irc://irc.freenode.org/april ou http://apr1.org/8l + +#notify.at5.cron=0 55 11 ? * * +#notify.at5.irc=Revue hebdomadaire dans 5 minutes +#notify.at5.twitter=Revue hebdomadaire !april dans 5 minutes sur irc://irc.freenode.org/april ou http://apr1.org/8l + +#notify.at15.cron=0 45 11 ? * * +#notify.at15.irc=Revue hebdomadaire dans 15 minutes +#notify.at15.twitter=Revue hebdomadaire !april dans 15 minutes sur irc://irc.freenode.org/april ou http://apr1.org/8l + +#notify.at30.cron=0 30 11 ? * * +#notify.at30.irc=Revue hebdomadaire dans 30 minutes +#notify.at30.twitter=Revue hebdomadaire !april dans 30 minutes sur irc://irc.freenode.org/april ou http://apr1.org/8l +