Refactored the notify management.
This commit is contained in:
parent
f3c62bbc70
commit
81cd7d8673
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
43
src/org/april/hebdobot/cron/CronFooJob.java
Normal file
43
src/org/april/hebdobot/cron/CronFooJob.java
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (C) 2011-2013,2017 Nicolas Vinot <aeris@imirhil.fr>
|
||||
* Copyright (C) 2017 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.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");
|
||||
}
|
||||
}
|
124
src/org/april/hebdobot/cron/CronListener.java
Normal file
124
src/org/april/hebdobot/cron/CronListener.java
Normal file
@ -0,0 +1,124 @@
|
||||
/**
|
||||
* Copyright (C) 2011-2013,2017 Nicolas Vinot <aeris@imirhil.fr>
|
||||
* Copyright (C) 2017 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.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;
|
||||
}
|
||||
}
|
104
src/org/april/hebdobot/cron/CronManager.java
Normal file
104
src/org/april/hebdobot/cron/CronManager.java
Normal file
@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright (C) 2011-2013,2017 Nicolas Vinot <aeris@imirhil.fr>
|
||||
* Copyright (C) 2017 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.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();
|
||||
}
|
||||
}
|
37
src/org/april/hebdobot/cron/CronSettings.java
Normal file
37
src/org/april/hebdobot/cron/CronSettings.java
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (C) 2017 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.cron;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The Class CronValues.
|
||||
*/
|
||||
public class CronSettings extends ArrayList<CronValue>
|
||||
{
|
||||
private static final long serialVersionUID = -6458988766218787076L;
|
||||
|
||||
/**
|
||||
* Instantiates a new cron values.
|
||||
*/
|
||||
public CronSettings()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
90
src/org/april/hebdobot/cron/CronValue.java
Normal file
90
src/org/april/hebdobot/cron/CronValue.java
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Copyright (C) 2017 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.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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,96 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2011-2013,2017 Nicolas Vinot <aeris@imirhil.fr>
|
||||
* Copyright (C) 2017 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.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;
|
||||
}
|
||||
}
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user