2017-12-24 11:21:44 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
2017-12-28 04:21:54 +01:00
|
|
|
import org.april.hebdobot.cron.CronSettings;
|
|
|
|
import org.april.hebdobot.cron.CronValue;
|
2017-12-24 11:21:44 +01:00
|
|
|
import org.april.hebdobot.util.HebdobotUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
import fr.devinsy.util.strings.StringSet;
|
|
|
|
|
2017-12-24 11:21:44 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2017-12-24 11:21:44 +01:00
|
|
|
/**
|
|
|
|
* Gets the identica api key.
|
|
|
|
*
|
|
|
|
* @return the identica api key
|
|
|
|
*/
|
|
|
|
public String getIdenticaApiKey()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("identica.apiKey");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the identica api secret.
|
|
|
|
*
|
|
|
|
* @return the identica api secret
|
|
|
|
*/
|
|
|
|
public String getIdenticaApiSecret()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("identica.apiSecret");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the irc channel.
|
|
|
|
*
|
|
|
|
* @return the irc channel
|
|
|
|
*/
|
|
|
|
public String getIrcChannel()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("irc.channel");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the irc host.
|
|
|
|
*
|
|
|
|
* @return the irc host
|
|
|
|
*/
|
|
|
|
public String getIrcHost()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("irc.host");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the name.
|
|
|
|
*
|
|
|
|
* @return the name
|
|
|
|
*/
|
|
|
|
public String getIrcName()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("irc.name");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the irc port.
|
|
|
|
*
|
|
|
|
* @return the irc port
|
|
|
|
*/
|
|
|
|
public Integer getIrcPort()
|
|
|
|
{
|
|
|
|
Integer result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = HebdobotUtils.toInteger(getProperty("irc.port"));
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-04 23:28:30 +01:00
|
|
|
* Gets the notify cron.
|
2017-12-28 04:21:54 +01:00
|
|
|
*
|
2018-01-04 23:28:30 +01:00
|
|
|
* @param notifyName
|
|
|
|
* the notify name
|
|
|
|
* @return the notify cron
|
2017-12-28 04:21:54 +01:00
|
|
|
*/
|
|
|
|
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");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the pastebin api key.
|
|
|
|
*
|
|
|
|
* @return the pastebin api key
|
|
|
|
*/
|
|
|
|
public String getPastebinApiKey()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("pastebin.apiKey");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-07 16:32:50 +01:00
|
|
|
/**
|
|
|
|
* Gets the review directory.
|
|
|
|
*
|
|
|
|
* @return the review directory
|
|
|
|
*/
|
|
|
|
public String getReviewDirectory()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
|
|
|
result = getProperty("review.directory");
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-12-24 11:21:44 +01:00
|
|
|
/**
|
|
|
|
* Gets the review file suffix.
|
|
|
|
*
|
|
|
|
* @return the review file suffix
|
|
|
|
*/
|
|
|
|
public String getReviewFileSuffix()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("review.file.suffix");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the twitter access token.
|
|
|
|
*
|
|
|
|
* @return the twitter access token
|
|
|
|
*/
|
|
|
|
public String getTwitterAccessToken()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("twitter.accessToken");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the twitter access token secret.
|
|
|
|
*
|
|
|
|
* @return the twitter access token secret
|
|
|
|
*/
|
|
|
|
public String getTwitterAccessTokenSecret()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("twitter.accessTokenSecret");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the twitter consumer key.
|
|
|
|
*
|
|
|
|
* @return the twitter consumer key
|
|
|
|
*/
|
|
|
|
public String getTwitterConsumerKey()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("twitter.consumerKey");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the twitter consumer secret.
|
|
|
|
*
|
|
|
|
* @return the twitter consumer secret
|
|
|
|
*/
|
|
|
|
public String getTwitterConsumerSecret()
|
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2017-12-28 04:21:54 +01:00
|
|
|
result = getProperty("twitter.consumerSecret");
|
2017-12-24 11:21:44 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is valid.
|
|
|
|
*
|
|
|
|
* @return true, if is valid
|
|
|
|
*/
|
|
|
|
public boolean isValid()
|
|
|
|
{
|
|
|
|
boolean result;
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|