Completed Twitter features. Fixed bot commands.

This commit is contained in:
Christian P. MOMON 2017-12-31 03:48:51 +01:00
parent ca28c68007
commit 2e41143a42
13 changed files with 91 additions and 41 deletions

View File

@ -48,5 +48,8 @@
<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/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"/>
</classpath>

View File

@ -1,5 +1,9 @@
Twitter :
- jackson-*
Spring:
- aopalliance-1.0.jar

Binary file not shown.

BIN
lib/jackson-core-2.3.2.jar Normal file

Binary file not shown.

Binary file not shown.

View File

@ -12,19 +12,19 @@ hebdobot.irc.name=Hebdobot
hebdobot.irc.channel=#april-test
# Pastebin settings.
#hebdobot.pastebin.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.pastebin.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Ident.ca settings.
#hebdobot.identica.apiKey=ef8ad74a5ab4a92138ff397763776a14
#hebdobot.identica.apiSecret=70400fa3b7c1aebba6d72b46399f45c7
#hebdobot.identica.tokenKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.identica.tokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.identica.apiKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.identica.apiSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.identica.tokenKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.identica.tokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# Twitter settings.
#hebdobot.twitter.consumerKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.twitter.consumerSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.twitter.consumerSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.twitter.accessToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.twitter.accessTokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#hebdobot.twitter.accessTokenSecret=XXXXXXXXXXXXXXXXXXXXXXXXXX
# Notifications
#notify.at5.cron=0 55 11 ? * *

View File

@ -3,3 +3,7 @@
#
Christian P. MOMON=cpm__,cpm_screen
Frédéric Couchet=madix
Lionel Allorge=liot,liot_
François Poulain=Polux[2]
Étienne Gonnu=lonugem

View File

@ -150,6 +150,8 @@ public class HebdobotCLI
bot.getIdenticaSettings().setApiSecret(config.getIdenticaApiSecret());
bot.getTwitterSettings().setConsumerKey(config.getTwitterConsumerKey());
bot.getTwitterSettings().setConsumerSecret(config.getTwitterConsumerSecret());
bot.getTwitterSettings().setAccessToken(config.getTwitterAccessToken());
bot.getTwitterSettings().setAccessTokenSecret(config.getTwitterAccessTokenSecret());
bot.getAliases().putAll(aliases);
bot.getCronSettings().addAll(config.getCronSettings());

View File

@ -48,6 +48,7 @@ import org.joda.time.format.ISODateTimeFormat;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.social.ApiException;
import fr.devinsy.util.strings.StringsUtils;
@ -155,9 +156,18 @@ public class Hebdobot extends PircBot
{
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);
}
catch (ApiException exception)
{
logger.error("Error in tweet", exception);
sendMessage("Pour information, le tweet de notifiation a échoué.");
}
}
}
/* (non-Javadoc)
@ -425,7 +435,7 @@ public class Hebdobot extends PircBot
logger.info("!status caught.");
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)
{
sendMessage(sender, " animateur revue : none");
@ -453,6 +463,13 @@ public class Hebdobot extends PircBot
// Ignore.
}
else if (StringsUtils.equalsAnyIgnoreCase(text, "!salut", "!bonjour", "!hello"))
{
logger.info("!salut caught.");
// Command unknown.
sendMessage(sender + ", bonjour \\o/");
}
else if (text.startsWith("!"))
{
logger.info("!??? caught.");

View File

@ -28,6 +28,8 @@ public class TwitterClient
{
private String consumerKey;
private String consumerSecret;
private String accessToken;
private String accessTokenSecret;
/**
* Instantiates a new twitter client.
@ -36,34 +38,38 @@ public class TwitterClient
* the consumer key
* @param consumerSecret
* 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))
{
throw new IllegalArgumentException("Invalid blank consumer key");
throw new IllegalArgumentException("Invalid blank consumer key.");
}
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
{
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.accessToken = accessToken;
this.accessTokenSecret = accessTokenSecret;
}
}
public String getConsumerKey()
{
return this.consumerKey;
}
public String getConsumerSecret()
{
return this.consumerSecret;
}
/**
* Send tweet.
*
@ -72,17 +78,7 @@ public class TwitterClient
*/
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);
}
public void setConsumerKey(final String consumerKey)
{
this.consumerKey = consumerKey;
}
public void setConsumerSecret(final String consumerSecret)
{
this.consumerSecret = consumerSecret;
}
}

View File

@ -73,14 +73,13 @@ public class TwitterSettings
{
boolean result;
if ((StringUtils.isBlank(this.consumerKey)) || (StringUtils.isBlank(this.consumerSecret)) || (StringUtils.containsOnly(this.consumerKey, 'X'))
|| (StringUtils.containsOnly(this.consumerSecret, 'X')))
if ((isValid(this.consumerKey)) && (isValid(this.consumerSecret)) && (isValid(this.accessToken)) && (isValid(this.accessTokenSecret)))
{
result = false;
result = true;
}
else
{
result = true;
result = false;
}
//
@ -106,4 +105,28 @@ public class TwitterSettings
{
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;
}
}

View File

@ -1,6 +1,7 @@
#
# Sample Hebdobot config file
#
# Note: move this file outside the git directory in case of Pastebin or Twitter test.
# Revue settings.
review.file.suffix=revue.txt

View File

@ -3,7 +3,7 @@
#
Christian P. MOMON=cpm__,cpm_screen
Lionel Allorge=liot,liot_
Frédéric Couchet=madix
Lionel Allorge=liot,liot_
François Poulain=Polux[2]
Étienne Gonnu=lonugem