Completed Twitter features. Fixed bot commands.
This commit is contained in:
parent
ca28c68007
commit
2e41143a42
13 changed files with 91 additions and 41 deletions
|
@ -48,5 +48,8 @@
|
||||||
<classpathentry kind="lib" path="lib/scribe-1.3.7.jar"/>
|
<classpathentry kind="lib" path="lib/scribe-1.3.7.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/quartz-2.2.3.jar" sourcepath="lib/quartz-2.2.3-source.zip"/>
|
<classpathentry kind="lib" path="lib/quartz-2.2.3.jar" sourcepath="lib/quartz-2.2.3-source.zip"/>
|
||||||
<classpathentry kind="lib" path="lib/devinsy-strings-0.4.4.jar" sourcepath="lib/devinsy-strings-0.4.4-sources.zip"/>
|
<classpathentry kind="lib" path="lib/devinsy-strings-0.4.4.jar" sourcepath="lib/devinsy-strings-0.4.4-sources.zip"/>
|
||||||
|
<classpathentry kind="lib" path="lib/jackson-annotations-2.3.2.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/jackson-core-2.3.2.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/jackson-databind-2.3.2.jar"/>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
|
|
||||||
|
|
||||||
|
Twitter :
|
||||||
|
- jackson-*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Spring:
|
Spring:
|
||||||
- aopalliance-1.0.jar
|
- aopalliance-1.0.jar
|
||||||
|
|
BIN
lib/jackson-annotations-2.3.2.jar
Normal file
BIN
lib/jackson-annotations-2.3.2.jar
Normal file
Binary file not shown.
BIN
lib/jackson-core-2.3.2.jar
Normal file
BIN
lib/jackson-core-2.3.2.jar
Normal file
Binary file not shown.
BIN
lib/jackson-databind-2.3.2.jar
Normal file
BIN
lib/jackson-databind-2.3.2.jar
Normal file
Binary file not shown.
|
@ -12,19 +12,19 @@ hebdobot.irc.name=Hebdobot
|
||||||
hebdobot.irc.channel=#april-test
|
hebdobot.irc.channel=#april-test
|
||||||
|
|
||||||
# Pastebin settings.
|
# Pastebin settings.
|
||||||
#hebdobot.pastebin.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
#hebdobot.pastebin.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
|
|
||||||
# Ident.ca settings.
|
# Ident.ca settings.
|
||||||
#hebdobot.identica.apiKey=ef8ad74a5ab4a92138ff397763776a14
|
#hebdobot.identica.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
#hebdobot.identica.apiSecret=70400fa3b7c1aebba6d72b46399f45c7
|
#hebdobot.identica.apiSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
#hebdobot.identica.tokenKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
#hebdobot.identica.tokenKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
#hebdobot.identica.tokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
#hebdobot.identica.tokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
|
|
||||||
# Twitter settings.
|
# Twitter settings.
|
||||||
#hebdobot.twitter.consumerKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
#hebdobot.twitter.consumerKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
#hebdobot.twitter.consumerSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
#hebdobot.twitter.consumerSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
#hebdobot.twitter.accessToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
#hebdobot.twitter.accessToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
#hebdobot.twitter.accessTokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
#hebdobot.twitter.accessTokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
|
|
||||||
# Notifications
|
# Notifications
|
||||||
#notify.at5.cron=0 55 11 ? * *
|
#notify.at5.cron=0 55 11 ? * *
|
||||||
|
|
|
@ -3,3 +3,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
Christian P. MOMON=cpm__,cpm_screen
|
Christian P. MOMON=cpm__,cpm_screen
|
||||||
|
Frédéric Couchet=madix
|
||||||
|
Lionel Allorge=liot,liot_
|
||||||
|
François Poulain=Polux[2]
|
||||||
|
Étienne Gonnu=lonugem
|
||||||
|
|
|
@ -150,6 +150,8 @@ public class HebdobotCLI
|
||||||
bot.getIdenticaSettings().setApiSecret(config.getIdenticaApiSecret());
|
bot.getIdenticaSettings().setApiSecret(config.getIdenticaApiSecret());
|
||||||
bot.getTwitterSettings().setConsumerKey(config.getTwitterConsumerKey());
|
bot.getTwitterSettings().setConsumerKey(config.getTwitterConsumerKey());
|
||||||
bot.getTwitterSettings().setConsumerSecret(config.getTwitterConsumerSecret());
|
bot.getTwitterSettings().setConsumerSecret(config.getTwitterConsumerSecret());
|
||||||
|
bot.getTwitterSettings().setAccessToken(config.getTwitterAccessToken());
|
||||||
|
bot.getTwitterSettings().setAccessTokenSecret(config.getTwitterAccessTokenSecret());
|
||||||
bot.getAliases().putAll(aliases);
|
bot.getAliases().putAll(aliases);
|
||||||
bot.getCronSettings().addAll(config.getCronSettings());
|
bot.getCronSettings().addAll(config.getCronSettings());
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ import org.joda.time.format.ISODateTimeFormat;
|
||||||
import org.quartz.SchedulerException;
|
import org.quartz.SchedulerException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.social.ApiException;
|
||||||
|
|
||||||
import fr.devinsy.util.strings.StringsUtils;
|
import fr.devinsy.util.strings.StringsUtils;
|
||||||
|
|
||||||
|
@ -155,9 +156,18 @@ public class Hebdobot extends PircBot
|
||||||
{
|
{
|
||||||
if (this.twitterSettings.isValid())
|
if (this.twitterSettings.isValid())
|
||||||
{
|
{
|
||||||
TwitterClient twitter = new TwitterClient(this.twitterSettings.getConsumerKey(), this.twitterSettings.getConsumerSecret());
|
try
|
||||||
|
{
|
||||||
|
TwitterClient twitter = new TwitterClient(this.twitterSettings.getConsumerKey(), this.twitterSettings.getConsumerSecret(),
|
||||||
|
this.twitterSettings.getAccessToken(), this.twitterSettings.getAccessTokenSecret());
|
||||||
twitter.tweet(message);
|
twitter.tweet(message);
|
||||||
}
|
}
|
||||||
|
catch (ApiException exception)
|
||||||
|
{
|
||||||
|
logger.error("Error in tweet", exception);
|
||||||
|
sendMessage("Pour information, le tweet de notifiation a échoué.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -425,7 +435,7 @@ public class Hebdobot extends PircBot
|
||||||
logger.info("!status caught.");
|
logger.info("!status caught.");
|
||||||
|
|
||||||
sendMessage(sender, sender + ", voici l'état d'Hebdobot :");
|
sendMessage(sender, sender + ", voici l'état d'Hebdobot :");
|
||||||
sendMessage(sender, " revue en cours : " + (this.review == null));
|
sendMessage(sender, " revue en cours : " + (this.review != null));
|
||||||
if (this.review == null)
|
if (this.review == null)
|
||||||
{
|
{
|
||||||
sendMessage(sender, " animateur revue : none");
|
sendMessage(sender, " animateur revue : none");
|
||||||
|
@ -453,6 +463,13 @@ public class Hebdobot extends PircBot
|
||||||
|
|
||||||
// Ignore.
|
// Ignore.
|
||||||
}
|
}
|
||||||
|
else if (StringsUtils.equalsAnyIgnoreCase(text, "!salut", "!bonjour", "!hello"))
|
||||||
|
{
|
||||||
|
logger.info("!salut caught.");
|
||||||
|
|
||||||
|
// Command unknown.
|
||||||
|
sendMessage(sender + ", bonjour \\o/");
|
||||||
|
}
|
||||||
else if (text.startsWith("!"))
|
else if (text.startsWith("!"))
|
||||||
{
|
{
|
||||||
logger.info("!??? caught.");
|
logger.info("!??? caught.");
|
||||||
|
|
|
@ -28,6 +28,8 @@ public class TwitterClient
|
||||||
{
|
{
|
||||||
private String consumerKey;
|
private String consumerKey;
|
||||||
private String consumerSecret;
|
private String consumerSecret;
|
||||||
|
private String accessToken;
|
||||||
|
private String accessTokenSecret;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new twitter client.
|
* Instantiates a new twitter client.
|
||||||
|
@ -36,34 +38,38 @@ public class TwitterClient
|
||||||
* the consumer key
|
* the consumer key
|
||||||
* @param consumerSecret
|
* @param consumerSecret
|
||||||
* the consumer secret
|
* the consumer secret
|
||||||
|
* @param accessToken
|
||||||
|
* the access token
|
||||||
|
* @param accessTokenSecret
|
||||||
|
* the access token secret
|
||||||
*/
|
*/
|
||||||
public TwitterClient(final String consumerKey, final String consumerSecret)
|
public TwitterClient(final String consumerKey, final String consumerSecret, final String accessToken, final String accessTokenSecret)
|
||||||
{
|
{
|
||||||
if (StringUtils.isBlank(consumerKey))
|
if (StringUtils.isBlank(consumerKey))
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Invalid blank consumer key");
|
throw new IllegalArgumentException("Invalid blank consumer key.");
|
||||||
}
|
}
|
||||||
else if (StringUtils.isBlank(consumerSecret))
|
else if (StringUtils.isBlank(consumerSecret))
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Invalid blank consumer secret");
|
throw new IllegalArgumentException("Invalid blank consumer secret.");
|
||||||
|
}
|
||||||
|
else if (StringUtils.isBlank(accessToken))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Invalid blank access token.");
|
||||||
|
}
|
||||||
|
else if (StringUtils.isBlank(accessTokenSecret))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Invalid blank access token secret.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.consumerKey = consumerKey;
|
this.consumerKey = consumerKey;
|
||||||
this.consumerSecret = consumerSecret;
|
this.consumerSecret = consumerSecret;
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
this.accessTokenSecret = accessTokenSecret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getConsumerKey()
|
|
||||||
{
|
|
||||||
return this.consumerKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConsumerSecret()
|
|
||||||
{
|
|
||||||
return this.consumerSecret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send tweet.
|
* Send tweet.
|
||||||
*
|
*
|
||||||
|
@ -72,17 +78,7 @@ public class TwitterClient
|
||||||
*/
|
*/
|
||||||
public void tweet(final String message)
|
public void tweet(final String message)
|
||||||
{
|
{
|
||||||
TwitterTemplate twitterClient = new TwitterTemplate(this.consumerKey, this.consumerSecret);
|
TwitterTemplate twitterClient = new TwitterTemplate(this.consumerKey, this.consumerSecret, this.accessToken, this.accessTokenSecret);
|
||||||
twitterClient.timelineOperations().updateStatus(message);
|
twitterClient.timelineOperations().updateStatus(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConsumerKey(final String consumerKey)
|
|
||||||
{
|
|
||||||
this.consumerKey = consumerKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConsumerSecret(final String consumerSecret)
|
|
||||||
{
|
|
||||||
this.consumerSecret = consumerSecret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,14 +73,13 @@ public class TwitterSettings
|
||||||
{
|
{
|
||||||
boolean result;
|
boolean result;
|
||||||
|
|
||||||
if ((StringUtils.isBlank(this.consumerKey)) || (StringUtils.isBlank(this.consumerSecret)) || (StringUtils.containsOnly(this.consumerKey, 'X'))
|
if ((isValid(this.consumerKey)) && (isValid(this.consumerSecret)) && (isValid(this.accessToken)) && (isValid(this.accessTokenSecret)))
|
||||||
|| (StringUtils.containsOnly(this.consumerSecret, 'X')))
|
|
||||||
{
|
{
|
||||||
result = false;
|
result = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = true;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -106,4 +105,28 @@ public class TwitterSettings
|
||||||
{
|
{
|
||||||
this.consumerSecret = consumerSecret;
|
this.consumerSecret = consumerSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if is valid.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
|
* @return true, if is valid
|
||||||
|
*/
|
||||||
|
private static boolean isValid(final String value)
|
||||||
|
{
|
||||||
|
boolean result;
|
||||||
|
|
||||||
|
if ((StringUtils.isBlank(value)) || (StringUtils.containsOnly(value, 'X')))
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#
|
#
|
||||||
# Sample Hebdobot config file
|
# Sample Hebdobot config file
|
||||||
#
|
#
|
||||||
|
# Note: move this file outside the git directory in case of Pastebin or Twitter test.
|
||||||
|
|
||||||
# Revue settings.
|
# Revue settings.
|
||||||
review.file.suffix=revue.txt
|
review.file.suffix=revue.txt
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
Christian P. MOMON=cpm__,cpm_screen
|
Christian P. MOMON=cpm__,cpm_screen
|
||||||
Lionel Allorge=liot,liot_
|
|
||||||
Frédéric Couchet=madix
|
Frédéric Couchet=madix
|
||||||
|
Lionel Allorge=liot,liot_
|
||||||
François Poulain=Polux[2]
|
François Poulain=Polux[2]
|
||||||
Étienne Gonnu=lonugem
|
Étienne Gonnu=lonugem
|
||||||
|
|
Loading…
Reference in a new issue