diff --git a/.classpath b/.classpath index cd51b45..c094381 100644 --- a/.classpath +++ b/.classpath @@ -48,5 +48,8 @@ + + + diff --git a/lib/README b/lib/README index 561eab9..fdf46d1 100644 --- a/lib/README +++ b/lib/README @@ -1,5 +1,9 @@ +Twitter : +- jackson-* + + Spring: - aopalliance-1.0.jar diff --git a/lib/jackson-annotations-2.3.2.jar b/lib/jackson-annotations-2.3.2.jar new file mode 100644 index 0000000..7ea186f Binary files /dev/null and b/lib/jackson-annotations-2.3.2.jar differ diff --git a/lib/jackson-core-2.3.2.jar b/lib/jackson-core-2.3.2.jar new file mode 100644 index 0000000..0b000af Binary files /dev/null and b/lib/jackson-core-2.3.2.jar differ diff --git a/lib/jackson-databind-2.3.2.jar b/lib/jackson-databind-2.3.2.jar new file mode 100644 index 0000000..0449f39 Binary files /dev/null and b/lib/jackson-databind-2.3.2.jar differ diff --git a/resources/hedbobot-sample.conf b/resources/hedbobot-sample.conf index f833666..e664c53 100644 --- a/resources/hedbobot-sample.conf +++ b/resources/hedbobot-sample.conf @@ -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 ? * * diff --git a/resources/users-sample.conf b/resources/users-sample.conf index af89070..4cc77e8 100644 --- a/resources/users-sample.conf +++ b/resources/users-sample.conf @@ -2,4 +2,8 @@ # Sample Hebdobot user file # -Christian P. MOMON=cpm__,cpm_screen \ No newline at end of file +Christian P. MOMON=cpm__,cpm_screen +Frédéric Couchet=madix +Lionel Allorge=liot,liot_ +François Poulain=Polux[2] +Étienne Gonnu=lonugem diff --git a/src/org/april/hebdobot/cli/HebdobotCLI.java b/src/org/april/hebdobot/cli/HebdobotCLI.java index 6d011fe..f58e696 100644 --- a/src/org/april/hebdobot/cli/HebdobotCLI.java +++ b/src/org/april/hebdobot/cli/HebdobotCLI.java @@ -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()); diff --git a/src/org/april/hebdobot/model/Hebdobot.java b/src/org/april/hebdobot/model/Hebdobot.java index 0ef0d8c..62e3007 100644 --- a/src/org/april/hebdobot/model/Hebdobot.java +++ b/src/org/april/hebdobot/model/Hebdobot.java @@ -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,8 +156,17 @@ public class Hebdobot extends PircBot { if (this.twitterSettings.isValid()) { - TwitterClient twitter = new TwitterClient(this.twitterSettings.getConsumerKey(), this.twitterSettings.getConsumerSecret()); - twitter.tweet(message); + 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é."); + } } } @@ -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."); @@ -481,7 +498,7 @@ public class Hebdobot extends PircBot else { logger.info("Else caught."); - + // All the other. if (this.review != null) { diff --git a/src/org/april/hebdobot/twitter/TwitterClient.java b/src/org/april/hebdobot/twitter/TwitterClient.java index b7a2fe6..aafad6a 100644 --- a/src/org/april/hebdobot/twitter/TwitterClient.java +++ b/src/org/april/hebdobot/twitter/TwitterClient.java @@ -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; - } } diff --git a/src/org/april/hebdobot/twitter/TwitterSettings.java b/src/org/april/hebdobot/twitter/TwitterSettings.java index c8b7a8c..bf5f61e 100644 --- a/src/org/april/hebdobot/twitter/TwitterSettings.java +++ b/src/org/april/hebdobot/twitter/TwitterSettings.java @@ -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; + } } diff --git a/test/hebdobot-test.conf b/test/hebdobot-test.conf index 63e4956..a1541b1 100644 --- a/test/hebdobot-test.conf +++ b/test/hebdobot-test.conf @@ -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 diff --git a/test/users.conf b/test/users.conf index 7ab8635..4cc77e8 100644 --- a/test/users.conf +++ b/test/users.conf @@ -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