Refactored pacakges (separated launcher and CLI). Completed

configuration file management.
This commit is contained in:
Christian P. MOMON 2017-12-24 11:21:44 +01:00
parent 17809f476e
commit 10189f547b
18 changed files with 1154 additions and 774 deletions

157
pom.xml
View File

@ -1,157 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.april</groupId>
<artifactId>hebdobot</artifactId>
<version>1.2.3-SNAPSHOT</version>
<scm>
<connection>scm:hg:file://${basedir}</connection>
</scm>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
<slf4j.version>1.7.12</slf4j.version>
<spring.version>4.1.7.RELEASE</spring.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/org/april/hebdobot</schemaDirectory>
<bindingDirectory>${basedir}/src/main/resources/org/april/hebdobot</bindingDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/jaxb</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<localCheckout>true</localCheckout>
<pushChanges>false</pushChanges>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>pircbot</groupId>
<artifactId>pircbot</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.12</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-twitter</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
</dependencies>
</project>

View File

@ -1,84 +0,0 @@
/**
* Copyright (C) 2011-2013 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;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
/**
* The Class Context.
*/
@Component
public final class Context implements ApplicationContextAware
{
private static ApplicationContext CONTEXT;
/* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@Override
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException
{
CONTEXT = applicationContext;
}
/**
* Close.
*/
public static void close()
{
if (CONTEXT instanceof ConfigurableApplicationContext)
{
((ConfigurableApplicationContext) CONTEXT).close();
}
}
/**
* Gets the bean.
*
* @param <T>
* the generic type
* @param clazz
* the clazz
* @return the bean
*/
public static <T> T getBean(final Class<T> clazz)
{
return CONTEXT.getBean(clazz);
}
/**
* Gets the bean.
*
* @param <T>
* the generic type
* @param name
* the name
* @return the bean
*/
public static <T> T getBean(final String name)
{
return (T) CONTEXT.getBean(name);
}
}

View File

@ -1,148 +0,0 @@
/**
* 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;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class Launcher.
*/
public class HebdobotConfigFile
{
private static final Logger logger = LoggerFactory.getLogger(HebdobotConfigFile.class);
/**
* Instantiates a new launcher.
*/
private HebdobotConfigFile()
{
}
/**
* Load.
*
* @param source
* the source
* @return the hebdobot config
* @throws HebdobotException
*/
public static HebdobotSettings load(final File source) throws HebdobotException
{
HebdobotSettings result;
//
Properties config = loadProperties(source);
//
String name = config.getProperty("hebdobot.irc.name");
String host = config.getProperty("hebdobot.irc.host");
Integer port = toInteger(config.getProperty("hebdobot.irc.port"));
String channel = config.getProperty("hebdobot.irc.channel");
String reviewFileSuffix = config.getProperty("hebdobot.review.file.suffix");
result = new HebdobotSettings(name, host, port, channel, reviewFileSuffix);
//
result.getPastebin().setApiKey(config.getProperty("hebdobot.pastebin.apiKey"));
//
result.getIdentica().setApiKey(config.getProperty("hebdobot.identica.apiKey"));
result.getIdentica().setApiSecret(config.getProperty("hebdobot.identica.apiSecret"));
//
result.getTwitter().setConsumerKey(config.getProperty("hebdobot.twitter.consumerKey"));
result.getTwitter().setConsumerKey(config.getProperty("hebdobot.twitter.consumerSecret"));
result.getTwitter().setConsumerKey(config.getProperty("hebdobot.twitter.accessToken"));
result.getTwitter().setConsumerKey(config.getProperty("hebdobot.twitter.accessTokenSecret"));
//
return result;
}
/**
* Load properties.
*
* @param source
* the source
* @return the properties
* @throws HebdobotException
* the hebdobot exception
*/
private static Properties loadProperties(final File source) throws HebdobotException
{
Properties result;
System.setProperty("file.encoding", "UTF-8");
result = new Properties();
FileReader reader = null;
try
{
reader = new FileReader(source);
result.load(reader);
}
catch (FileNotFoundException exception)
{
throw new HebdobotException("File not found.", exception);
}
catch (IOException exception)
{
throw new HebdobotException("IO error.", exception);
}
finally
{
IOUtils.closeQuietly(reader);
}
//
return result;
}
/**
* To integer.
*
* @param value
* the value
* @return the integer
*/
private static Integer toInteger(final String value)
{
Integer result;
if ((value == null) || (!NumberUtils.isDigits(value)))
{
result = null;
}
else
{
result = Integer.parseInt(value);
}
//
return result;
}
}

View File

@ -21,18 +21,12 @@ package org.april.hebdobot;
import java.io.File;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;
import org.april.hebdobot.cli.HebdobotCLI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.strings.StringList;
/**
* The Class Launcher.
*/
@ -40,9 +34,6 @@ public class HebdobotLauncher
{
private static final Logger logger = LoggerFactory.getLogger(HebdobotLauncher.class);
public static final String HEBDOBOT_VERSION = "v2.0";
private static final String DEFAULT_CONFIG_FILE = "hebdobot.conf";
/**
* Instantiates a new hebdobot launcher.
*/
@ -50,21 +41,6 @@ public class HebdobotLauncher
{
}
/**
* Help.
*/
public static void help()
{
StringList message = new StringList();
message.append("Hebdobot version ").appendln(HEBDOBOT_VERSION);
message.appendln("Usage:");
message.appendln(" hebdobot [ -h | -help | --help ]");
message.appendln(" hebdobot [ -c configuration-file ]");
System.out.println(message.toString());
}
/**
* The main method.
*
@ -73,83 +49,25 @@ public class HebdobotLauncher
*/
public static void main(final String[] args)
{
try
// Configure log.
File loggerConfig = new File("log4j.properties");
if (loggerConfig.exists())
{
setDefaultException();
Options options = new Options();
options.addOption("h", "help", false, "Help option");
options.addOption("c", true, "Config file");
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
if (commandLine.hasOption("h"))
{
logger.debug("Help requires.");
help();
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("hebdobot", options);
}
else
{
// Find the configuration file.
File configFile;
if (commandLine.hasOption("c"))
{
logger.debug("'-c' option detected with value [{}].", commandLine.getOptionValue("c"));
// Check configuration file.
String value = commandLine.getOptionValue("c");
if (StringUtils.isBlank(value))
{
throw new HebdobotException("Missing config file value.");
}
else
{
configFile = new File(commandLine.getOptionValue("c"));
}
}
else
{
logger.debug("'-c' option NOT detected.");
// Try to load default configuration file in current work
// directory.
configFile = new File(DEFAULT_CONFIG_FILE);
}
// Load configuration file.
HebdobotSettings settings = HebdobotConfigFile.load(configFile);
if (HebdobotSettings.isValid(settings))
{
Hebdobot bot = new Hebdobot(settings.getHost(), settings.getPort(), settings.getName(), settings.getChannel(),
settings.getReviewFileSuffix());
bot.setIdenticaSettings(settings.getIdentica());
bot.setPastebinSettings(settings.getPastebin());
bot.setTwitterSettings(settings.getTwitter());
bot.run();
}
else
{
throw new HebdobotException("Invalid config file [" + configFile.getPath() + "]");
}
}
PropertyConfigurator.configure(loggerConfig.getAbsolutePath());
logger.info("Dedicated log configuration done.");
logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile());
}
catch (ParseException exception)
else
{
System.out.print("Parse error: ");
System.out.println(exception.getMessage());
}
catch (HebdobotException exception)
{
System.err.println("HebdobotException = " + exception.getMessage());
logger.error(exception.getMessage(), exception);
help();
BasicConfigurator.configure();
logger.info("Basic log configuration done.");
logger.info("Configuration file was not found in [{}].", loggerConfig.getAbsoluteFile());
}
//
setDefaultException();
HebdobotCLI.run(args);
}
/**
@ -175,9 +93,9 @@ public class HebdobotLauncher
message = String.format("An error occured: %1s(%2s)", exception.getClass(), exception.getMessage());
}
HebdobotLauncher.logger.error("uncaughtException ", exception);
HebdobotLauncher.logger.error(message);
HebdobotLauncher.logger.info("Unexpected error.");
logger.error("uncaughtException ", exception);
logger.error(message);
logger.info("Unexpected error.");
}
});
}

View File

@ -1,139 +0,0 @@
/**
* 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;
import org.april.hebdobot.identica.IdenticaSettings;
import org.april.hebdobot.pastebin.PastebinSettings;
import org.april.hebdobot.twitter.TwitterSettings;
/**
* The Class IdenticaSettings.
*/
public class HebdobotSettings
{
private String name;
private String host;
private int port;
private String channel;
private String reviewFileSuffix;
private IdenticaSettings identica;
private PastebinSettings pastebin;
private TwitterSettings twitter;
/**
* Instantiates a new hebdobot settings.
*/
public HebdobotSettings(final String name, final String host, final int port, final String channel, final String reviewFileSuffix)
{
this.name = name;
this.host = host;
this.port = port;
this.channel = channel;
this.reviewFileSuffix = reviewFileSuffix;
this.identica = new IdenticaSettings();
this.pastebin = new PastebinSettings();
this.twitter = new TwitterSettings();
}
public String getChannel()
{
return this.channel;
}
public String getHost()
{
return this.host;
}
public IdenticaSettings getIdentica()
{
return this.identica;
}
public String getName()
{
return this.name;
}
public PastebinSettings getPastebin()
{
return this.pastebin;
}
public int getPort()
{
return this.port;
}
public String getReviewFileSuffix()
{
return this.reviewFileSuffix;
}
public TwitterSettings getTwitter()
{
return this.twitter;
}
public void setChannel(final String channel)
{
this.channel = channel;
}
public void setHost(final String host)
{
this.host = host;
}
public void setName(final String name)
{
this.name = name;
}
public void setPort(final int port)
{
this.port = port;
}
/**
* Checks if is valid.
*
* @param source
* the source
* @return true, if is valid
*/
public static boolean isValid(final HebdobotSettings source)
{
boolean result;
if (source == null)
{
result = false;
}
else
{
result = true;
}
//
return result;
}
}

View File

@ -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;
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;
}
}

View File

@ -0,0 +1,166 @@
/**
* Copyright (C) 2011-2013 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.cli;
import java.io.File;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.april.hebdobot.HebdobotException;
import org.april.hebdobot.model.Hebdobot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.util.strings.StringList;
/**
* The Class Launcher.
*/
public class HebdobotCLI
{
private static final Logger logger = LoggerFactory.getLogger(HebdobotCLI.class);
public static final String HEBDOBOT_VERSION = "v2.0";
private static final String DEFAULT_CONFIG_FILE = "hebdobot.conf";
/**
* Instantiates a new hebdobot launcher.
*/
private HebdobotCLI()
{
}
/**
* Help.
*/
public static void help()
{
StringList message = new StringList();
message.append("Hebdobot version ").appendln(HEBDOBOT_VERSION);
message.appendln("Usage:");
message.appendln(" hebdobot [ -h | -help | --help ]");
message.appendln(" hebdobot [ -c configuration-file ]");
System.out.println(message.toString());
}
/**
* The main method.
*
* @param args
* the arguments
*/
public static void run(final String[] args)
{
try
{
//
Options options = new Options();
options.addOption("h", "help", false, "Help option");
options.addOption("c", true, "Config file");
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
if (commandLine.hasOption("h"))
{
logger.debug("Help requires.");
help();
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("hebdobot", options);
}
else
{
// Find the configuration file.
File configFile;
if (commandLine.hasOption("c"))
{
logger.debug("'-c' option detected with value [{}].", commandLine.getOptionValue("c"));
// Check configuration file.
String value = commandLine.getOptionValue("c");
if (StringUtils.isBlank(value))
{
throw new HebdobotException("Missing config file value.");
}
else
{
configFile = new File(commandLine.getOptionValue("c"));
}
}
else
{
logger.debug("'-c' option NOT detected.");
// Try to load default configuration file in current work
// directory.
File currentDirectory = new File(System.getProperty("user.dir"));
configFile = new File(currentDirectory, DEFAULT_CONFIG_FILE);
}
if (configFile.exists())
{
// Load configuration file.
HebdobotConfigFile config = new HebdobotConfigFile(configFile);
if (config.isValid())
{
Hebdobot bot = new Hebdobot(config.getIrcHost(), config.getIrcPort(), config.getIrcName(), config.getIrcChannel(),
config.getReviewFileSuffix());
bot.getPastebinSettings().setApiKey(config.getPastebinApiKey());
bot.getIdenticaSettings().setApiKey(config.getIdenticaApiKey());
bot.getIdenticaSettings().setApiSecret(config.getIdenticaApiSecret());
bot.getTwitterSettings().setConsumerKey(config.getTwitterConsumerKey());
bot.getTwitterSettings().setConsumerSecret(config.getTwitterConsumerSecret());
bot.run();
}
else
{
throw new HebdobotException("Invalid config file [" + configFile.getAbsolutePath() + "]");
}
}
else
{
throw new HebdobotException("Missing config file [" + configFile.getAbsolutePath() + "]");
}
}
}
catch (ParseException exception)
{
logger.error(exception.getMessage(), exception);
System.err.print("Parse error: " + exception.getMessage());
}
catch (HebdobotException exception)
{
logger.error(exception.getMessage(), exception);
System.err.println(exception.getMessage());
help();
}
}
}

View File

@ -0,0 +1,264 @@
/**
* 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.cli;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.april.hebdobot.HebdobotException;
import org.april.hebdobot.util.HebdobotUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class Launcher.
*/
public class HebdobotConfigFile extends Properties
{
private static final long serialVersionUID = 5954809202666104536L;
private static final Logger logger = LoggerFactory.getLogger(HebdobotConfigFile.class);
/**
* Instantiates a new launcher.
*
* @param source
* the source
* @throws HebdobotException
* the hebdobot exception
*/
public HebdobotConfigFile(final File source) throws HebdobotException
{
super();
try
{
Properties config = HebdobotUtils.loadProperties(source);
for (String key : config.stringPropertyNames())
{
put(key, config.getProperty(key));
}
}
catch (FileNotFoundException exception)
{
throw new HebdobotException("File not found.", exception);
}
catch (IOException exception)
{
throw new HebdobotException("IO error.", exception);
}
}
/**
* Gets the identica api key.
*
* @return the identica api key
*/
public String getIdenticaApiKey()
{
String result;
result = getProperty("hebdobot.identica.apiKey");
//
return result;
}
/**
* Gets the identica api secret.
*
* @return the identica api secret
*/
public String getIdenticaApiSecret()
{
String result;
result = getProperty("hebdobot.identica.apiSecret");
//
return result;
}
/**
* Gets the irc channel.
*
* @return the irc channel
*/
public String getIrcChannel()
{
String result;
result = getProperty("hebdobot.irc.channel");
//
return result;
}
/**
* Gets the irc host.
*
* @return the irc host
*/
public String getIrcHost()
{
String result;
result = getProperty("hebdobot.irc.host");
//
return result;
}
/**
* Gets the name.
*
* @return the name
*/
public String getIrcName()
{
String result;
result = getProperty("hebdobot.irc.name");
//
return result;
}
/**
* Gets the irc port.
*
* @return the irc port
*/
public Integer getIrcPort()
{
Integer result;
result = HebdobotUtils.toInteger(getProperty("hebdobot.irc.port"));
//
return result;
}
/**
* Gets the pastebin api key.
*
* @return the pastebin api key
*/
public String getPastebinApiKey()
{
String result;
result = getProperty("hebdobot.pastebin.apiKey");
//
return result;
}
/**
* Gets the review file suffix.
*
* @return the review file suffix
*/
public String getReviewFileSuffix()
{
String result;
result = getProperty("hebdobot.review.file.suffix");
//
return result;
}
/**
* Gets the twitter access token.
*
* @return the twitter access token
*/
public String getTwitterAccessToken()
{
String result;
result = getProperty("hebdobot.twitter.accessToken");
//
return result;
}
/**
* Gets the twitter access token secret.
*
* @return the twitter access token secret
*/
public String getTwitterAccessTokenSecret()
{
String result;
result = getProperty("hebdobot.twitter.accessTokenSecret");
//
return result;
}
/**
* Gets the twitter consumer key.
*
* @return the twitter consumer key
*/
public String getTwitterConsumerKey()
{
String result;
result = getProperty("hebdobot.twitter.consumerKey");
//
return result;
}
/**
* Gets the twitter consumer secret.
*
* @return the twitter consumer secret
*/
public String getTwitterConsumerSecret()
{
String result;
result = getProperty("hebdobot.twitter.consumerSecret");
//
return result;
}
/**
* Checks if is valid.
*
* @return true, if is valid
*/
public boolean isValid()
{
boolean result;
result = true;
//
return result;
}
}

View File

@ -0,0 +1,69 @@
/**
* Copyright (C) 2011-2013 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.identica;
import org.scribe.builder.api.DefaultApi10a;
import org.scribe.model.Token;
/**
* The Class IdentiCaApi.
*/
public class IdentiCaApi extends DefaultApi10a
{
private static final String IDENTI_CA_OAUTH_API_URL = "https://identi.ca/api/oauth";
private static final String IDENTI_CA_OAUTH_API_REQUEST_TOKEN_URL = IDENTI_CA_OAUTH_API_URL + "/request_token";
private static final String IDENTI_CA_OAUTH_API_ACCESS_TOKEN_URL = IDENTI_CA_OAUTH_API_URL + "/access_token";
private static final String IDENTI_CA_OAUTH_API_AUTHORIZE_URL = IDENTI_CA_OAUTH_API_URL + "/authorize?oauth_token=%s";
/**
* Gets the access token endpoint.
*
* @return the access token endpoint
*/
@Override
public String getAccessTokenEndpoint()
{
return IDENTI_CA_OAUTH_API_ACCESS_TOKEN_URL;
}
/**
* Gets the authorization url.
*
* @param requestToken
* the request token
* @return the authorization url
*/
@Override
public String getAuthorizationUrl(final Token requestToken)
{
return String.format(IDENTI_CA_OAUTH_API_AUTHORIZE_URL, requestToken.getToken());
}
/**
* Gets the request token endpoint.
*
* @return the request token endpoint
*/
@Override
public String getRequestTokenEndpoint()
{
return IDENTI_CA_OAUTH_API_REQUEST_TOKEN_URL;
}
}

View File

@ -0,0 +1,68 @@
/**
* Copyright (C) 2011-2013 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.identica;
/**
* The Class IdentiCaClient.
*/
public class IdentiCaClient extends StatusNetClient
{
private static final Class<IdentiCaApi> API_CLASS = IdentiCaApi.class;
private static final String IDENTICA_API_URL = "https://identi.ca/api";
/**
* Instantiates a new identi ca client.
*
* @param apiKey
* the api key
* @param apiSecret
* the api secret
* @param tokenKey
* the token key
* @param tokenSecret
* the token secret
*/
public IdentiCaClient(final String apiKey, final String apiSecret, final String tokenKey, final String tokenSecret)
{
super(API_CLASS, apiKey, apiSecret, tokenKey, tokenSecret);
}
/**
* Register.
*
* @param apiKey
* the api key
* @param apiSecret
* the api secret
*/
public static void register(final String apiKey, final String apiSecret)
{
StatusNetClient.register(API_CLASS, apiKey, apiSecret);
}
/* (non-Javadoc)
* @see org.april.hebdobot.statusnet.StatusNetClient#getApiUrl()
*/
@Override
protected String getApiUrl()
{
return IDENTICA_API_URL;
}
}

View File

@ -0,0 +1,49 @@
/**
* Copyright (C) 2011-2013 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.identica;
/**
* The Class IdenticaSettings.
*/
public class IdenticaSettings
{
private String apiKey;
private String apiSecret;
public String getApiKey()
{
return this.apiKey;
}
public String getApiSecret()
{
return this.apiSecret;
}
public void setApiKey(final String apiKey)
{
this.apiKey = apiKey;
}
public void setApiSecret(final String apiSecret)
{
this.apiSecret = apiSecret;
}
}

View File

@ -0,0 +1,131 @@
/**
* Copyright (C) 2011-2013 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.identica;
import java.util.Scanner;
import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.Api;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;
/**
* The Class StatusNetClient.
*/
public abstract class StatusNetClient
{
private final OAuthService service;
private final Token token;
/**
* Instantiates a new status net client.
*
* @param apiClass
* the api class
* @param apiKey
* the api key
* @param apiSecret
* the api secret
* @param tokenKey
* the token key
* @param tokenSecret
* the token secret
*/
public StatusNetClient(final Class<? extends Api> apiClass, final String apiKey, final String apiSecret, final String tokenKey,
final String tokenSecret)
{
this.service = getService(apiClass, apiKey, apiSecret);
this.token = new Token(tokenKey, tokenSecret);
}
/**
* Gets the api url.
*
* @return the api url
*/
protected abstract String getApiUrl();
/**
* Post.
*
* @param message
* the message
*/
public void post(final String message)
{
final OAuthRequest request = new OAuthRequest(Verb.POST, this.getApiUrl() + "/statuses/update.json");
request.addBodyParameter("status", message);
this.service.signRequest(this.token, request);
request.send();
}
/**
* Gets the service.
*
* @param apiClass
* the api class
* @param apiKey
* the api key
* @param apiSecret
* the api secret
* @return the service
*/
private static OAuthService getService(final Class<? extends Api> apiClass, final String apiKey, final String apiSecret)
{
OAuthService result;
result = new ServiceBuilder().provider(apiClass).apiKey(apiKey).apiSecret(apiSecret).build();
//
return result;
}
/**
* Register.
*
* @param apiClass
* the api class
* @param apiKey
* the api key
* @param apiSecret
* the api secret
*/
public static void register(final Class<? extends Api> apiClass, final String apiKey, final String apiSecret)
{
final OAuthService service = getService(apiClass, apiKey, apiSecret);
final Token requestToken = service.getRequestToken();
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.print(">>");
final Scanner scanner = new Scanner(System.in);
try
{
final Verifier verifier = new Verifier(scanner.nextLine());
final Token token = service.getAccessToken(requestToken, verifier);
System.out.println(token);
}
finally
{
scanner.close();
}
}
}

View File

@ -17,7 +17,7 @@
* 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;
package org.april.hebdobot.model;
import java.io.File;
import java.io.IOException;
@ -26,6 +26,7 @@ import java.util.Collection;
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.identica.IdenticaSettings;
import org.april.hebdobot.pastebin.PastebinClient;
import org.april.hebdobot.pastebin.PastebinSettings;
@ -35,6 +36,7 @@ import org.april.hebdobot.review.IndividualTopic;
import org.april.hebdobot.review.Message;
import org.april.hebdobot.review.Review;
import org.april.hebdobot.review.Topic;
import org.april.hebdobot.twitter.TwitterClient;
import org.april.hebdobot.twitter.TwitterSettings;
import org.jibble.pircbot.IrcException;
import org.jibble.pircbot.NickAlreadyInUseException;
@ -43,10 +45,9 @@ import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.social.twitter.api.impl.TwitterTemplate;
/**
* The Class Bot.
* The Class Hebdobot.
*/
public class Hebdobot extends PircBot
{
@ -81,6 +82,10 @@ public class Hebdobot extends PircBot
this.setName(name);
this.reviewFileSuffix = reviewFileSuffix;
this.review = null;
this.identicaSettings = new IdenticaSettings();
this.pastebinSettings = new PastebinSettings();
this.twitterSettings = new TwitterSettings();
}
/**
@ -92,6 +97,21 @@ public class Hebdobot extends PircBot
this.dispose();
}
public IdenticaSettings getIdenticaSettings()
{
return this.identicaSettings;
}
public PastebinSettings getPastebinSettings()
{
return this.pastebinSettings;
}
public TwitterSettings getTwitterSettings()
{
return this.twitterSettings;
}
/**
* Notify.
*
@ -108,8 +128,9 @@ public class Hebdobot extends PircBot
if (this.twitterSettings != null)
{
String message = String.format("Revue hebdomadaire !april dans %dmin sur irc://irc.freenode.org/april ou http://apr1.org/8l", minutes);
TwitterTemplate twitterClient = new TwitterTemplate(this.twitterSettings.getConsumerKey(), this.twitterSettings.getConsumerSecret());
twitterClient.timelineOperations().updateStatus(message);
TwitterClient twitter = new TwitterClient(this.twitterSettings.getConsumerKey(), this.twitterSettings.getConsumerSecret());
twitter.tweet(message);
}
}
@ -120,10 +141,12 @@ public class Hebdobot extends PircBot
protected void onMessage(final String channel, final String sender, final String login, final String hostname, final String message)
{
logger.debug("Message received - channel : {}, sender : {}, message : {}", channel, sender, message);
if (channel.equalsIgnoreCase(this.channel))
{
String text = message.trim();
logger.debug(message + " " + text + " " + StringUtils.equalsIgnoreCase(text, "!help"));
if (StringUtils.equalsIgnoreCase(text, "!help"))
{
// Help.
@ -144,7 +167,8 @@ public class Hebdobot extends PircBot
// Die.
if (this.review == null)
{
Context.close();
// TODO
// Context.close();
}
else
{
@ -338,7 +362,7 @@ public class Hebdobot extends PircBot
* Inits the.
*
* the exception
*
*
* @throws HebdobotException
*/
public void run() throws HebdobotException
@ -373,44 +397,4 @@ public class Hebdobot extends PircBot
logger.debug("Send message : {}", message);
this.sendMessage(this.channel, message);
}
/**
* Sets the identica settings.
*
* @param settings
* the new identica settings
*/
public void setIdenticaSettings(final IdenticaSettings settings)
{
this.identicaSettings = new IdenticaSettings();
this.identicaSettings.setApiKey(settings.getApiKey());
this.identicaSettings.setApiSecret(settings.getApiSecret());
}
/**
* Sets the pastebin settings.
*
* @param settings
* the new pastebin settings
*/
public void setPastebinSettings(final PastebinSettings settings)
{
this.pastebinSettings = new PastebinSettings();
this.pastebinSettings.setApiKey(settings.getApiKey());
}
/**
* Sets the twitter settings.
*
* @param settings
* the new twitter settings
*/
public void setTwitterSettings(final TwitterSettings settings)
{
this.twitterSettings = new TwitterSettings();
this.twitterSettings.setAccessToken(settings.getAccessToken());
this.twitterSettings.setAccessTokenSecret(settings.getAccessTokenSecret());
this.twitterSettings.setConsumerKey(settings.getConsumerKey());
this.twitterSettings.setConsumerSecret(settings.getConsumerSecret());
}
}

View File

@ -0,0 +1,56 @@
/**
* 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.pastebin;
/**
* The Class IdenticaSettings.
*/
public class PastebinSettings
{
private String apiKey;
/**
* Instantiates a new pastebin settings.
*/
public PastebinSettings()
{
this.apiKey = null;
}
/**
* Instantiates a new pastebin settings.
*
* @param apiKey
* the api key
*/
public PastebinSettings(final String apiKey)
{
this.apiKey = apiKey;
}
public String getApiKey()
{
return this.apiKey;
}
public void setApiKey(final String apiKey)
{
this.apiKey = apiKey;
}
}

View File

@ -0,0 +1,88 @@
/**
* 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.twitter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.social.twitter.api.impl.TwitterTemplate;
/**
* The Class TwitterClient.
*/
public class TwitterClient
{
private String consumerKey;
private String consumerSecret;
/**
* Instantiates a new twitter client.
*
* @param consumerKey
* the consumer key
* @param consumerSecret
* the consumer secret
*/
public TwitterClient(final String consumerKey, final String consumerSecret)
{
if (StringUtils.isBlank(consumerKey))
{
throw new IllegalArgumentException("Invalid blank consumer key");
}
else if (StringUtils.isBlank(consumerSecret))
{
throw new IllegalArgumentException("Invalid blank consumer secret");
}
else
{
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
}
}
public String getConsumerKey()
{
return this.consumerKey;
}
public String getConsumerSecret()
{
return this.consumerSecret;
}
/**
* Send tweet.
*
* @param message
* the message
*/
public void tweet(final String message)
{
TwitterTemplate twitterClient = new TwitterTemplate(this.consumerKey, this.consumerSecret);
twitterClient.timelineOperations().updateStatus(message);
}
public void setConsumerKey(final String consumerKey)
{
this.consumerKey = consumerKey;
}
public void setConsumerSecret(final String consumerSecret)
{
this.consumerSecret = consumerSecret;
}
}

View File

@ -0,0 +1,84 @@
/**
* 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.twitter;
/**
* The Class TwitterSettings.
*/
public class TwitterSettings
{
private String consumerKey;
private String consumerSecret;
private String accessToken;
private String accessTokenSecret;
/**
* Instantiates a new pastebin settings.
*
* @param apiKey
* the api key
*/
public TwitterSettings()
{
this.consumerKey = null;
this.consumerSecret = null;
this.accessToken = null;
this.accessTokenSecret = null;
}
public String getAccessToken()
{
return this.accessToken;
}
public String getAccessTokenSecret()
{
return this.accessTokenSecret;
}
public String getConsumerKey()
{
return this.consumerKey;
}
public String getConsumerSecret()
{
return this.consumerSecret;
}
public void setAccessToken(final String accessToken)
{
this.accessToken = accessToken;
}
public void setAccessTokenSecret(final String accessTokenSecret)
{
this.accessTokenSecret = accessTokenSecret;
}
public void setConsumerKey(final String consumerKey)
{
this.consumerKey = consumerKey;
}
public void setConsumerSecret(final String consumerSecret)
{
this.consumerSecret = consumerSecret;
}
}

View File

@ -0,0 +1,100 @@
/**
* 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.util;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.april.hebdobot.HebdobotException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class Launcher.
*/
public class HebdobotUtils
{
private static final Logger logger = LoggerFactory.getLogger(HebdobotUtils.class);
/**
* Constructor restriction.
*/
private HebdobotUtils()
{
}
/**
* Load properties.
*
* @param source
* the source
* @return the properties
* @throws HebdobotException
* the hebdobot exception
* @throws IOException
*/
public static Properties loadProperties(final File source) throws HebdobotException, IOException
{
Properties result;
System.setProperty("file.encoding", "UTF-8");
result = new Properties();
FileReader reader = null;
try
{
reader = new FileReader(source);
result.load(reader);
}
finally
{
IOUtils.closeQuietly(reader);
}
//
return result;
}
/**
* To integer.
*
* @param value
* the value
* @return the integer
*/
public static Integer toInteger(final String value)
{
Integer result;
if ((value == null) || (!NumberUtils.isDigits(value)))
{
result = null;
}
else
{
result = Integer.parseInt(value);
}
//
return result;
}
}

27
test/hebdobot-test.conf Normal file
View File

@ -0,0 +1,27 @@
#
# Sample Hebdobot config file
#
# Revue settings.
hebdobot.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
# Pastebin settings.
hebdobot.pastebin.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Ident.ca settings.
hebdobot.identica.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
hebdobot.identica.apiSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
hebdobot.identica.tokenKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
hebdobot.identica.tokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Twitter settings.
hebdobot.twitter.consumerKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
hebdobot.twitter.consumerSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
hebdobot.twitter.accessToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
hebdobot.twitter.accessTokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX