From 366f35d7a46da72a38909899efa38dcc2a7246e0 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sun, 24 Dec 2017 11:22:31 +0100 Subject: [PATCH] Cleaned ressources. --- CHANGES | 13 +++ resources/hebdobot.cron | 4 + resources/hebdobot.initd | 34 ++++++ resources/hedbobot-sample.conf | 27 +++++ resources/notes | 3 + resources/pom.xml | 157 ++++++++++++++++++++++++++ src/org/april/hebdobot/model/Job.java | 96 ++++++++++++++++ test/org/april/hebdobot/BotMock.java | 48 ++++++++ test/org/april/hebdobot/BotTest.java | 1 + 9 files changed, 383 insertions(+) create mode 100644 CHANGES create mode 100644 resources/hebdobot.cron create mode 100755 resources/hebdobot.initd create mode 100644 resources/hedbobot-sample.conf create mode 100644 resources/notes create mode 100644 resources/pom.xml create mode 100644 src/org/april/hebdobot/model/Job.java create mode 100644 test/org/april/hebdobot/BotMock.java diff --git a/CHANGES b/CHANGES new file mode 100644 index 0000000..364aabc --- /dev/null +++ b/CHANGES @@ -0,0 +1,13 @@ + + +* Changed license from GNU GPL v3 to GNU AGPL v3. +* Added copyright file headers. +* Set formatter and save actions settings and applied it. +* Made a code review. +* Place internal classes in their own file. + +* anonymized Twitter API key + +* renamed package from fr.imirhil.april to org.april +* replaced Maven with Ant +* no more code injection \ No newline at end of file diff --git a/resources/hebdobot.cron b/resources/hebdobot.cron new file mode 100644 index 0000000..9f12132 --- /dev/null +++ b/resources/hebdobot.cron @@ -0,0 +1,4 @@ +LANGUAGE=fr_FR.UTF8 +LC_ALL=fr_FR.UTF-8 +00 11 * * 5 root /etc/init.d/hebdobot start > /dev/null +00 14 * * 5 root /etc/init.d/hebdobot stop > /dev/null diff --git a/resources/hebdobot.initd b/resources/hebdobot.initd new file mode 100755 index 0000000..72ef3a0 --- /dev/null +++ b/resources/hebdobot.initd @@ -0,0 +1,34 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Required-Start: $remote_fs $syslog $local_fs $network +# Required-Stop: $remote_fs $syslog $local_fs $network +# Default-Start: +# Default-Stop: +# Provides: Hebdobot +# Short-Description: Bot de revue hebdo April +# Description: hebdobot est un bot irc écrit en java +### END INIT INFO + + +NAME=hebdobot +BASE_DIR=/srv/$NAME +PID_FILE=$BASE_DIR/$NAME.pid +DAEMON=$(which java) +DAEMON_ARGS="-cp *:lib/* fr.imirhil.april.hebdobot.Application" + +CMD="/sbin/start-stop-daemon --chdir $BASE_DIR --quiet --make-pidfile --pidfile $PID_FILE --exec $DAEMON" +case "$1" in + start) + echo "Starting $NAME" + $CMD --start --test || exit 1 + $CMD --start --background -- $DAEMON_ARGS || exit 2 + echo "$NAME started" + ;; + stop) + echo "Stopping $NAME" + $CMD --stop || exit 3 + rm -f $PID_FILE + echo "$NAME stopped" + ;; +esac diff --git a/resources/hedbobot-sample.conf b/resources/hedbobot-sample.conf new file mode 100644 index 0000000..aae182c --- /dev/null +++ b/resources/hedbobot-sample.conf @@ -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=ef8ad74a5ab4a92138ff397763776a14 +#hebdobot.identica.apiSecret=70400fa3b7c1aebba6d72b46399f45c7 +#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 diff --git a/resources/notes b/resources/notes new file mode 100644 index 0000000..61368fb --- /dev/null +++ b/resources/notes @@ -0,0 +1,3 @@ +root@bots:/srv/hebdobot# find / -name "hebdobot*" +/etc/cron.d/hebdobot +/etc/init.d/hebdobot diff --git a/resources/pom.xml b/resources/pom.xml new file mode 100644 index 0000000..c95165f --- /dev/null +++ b/resources/pom.xml @@ -0,0 +1,157 @@ + + 4.0.0 + org.april + hebdobot + 1.2.3-SNAPSHOT + + scm:hg:file://${basedir} + + + 1.7 + ${maven.compiler.source} + UTF8 + 1.7.12 + 4.1.7.RELEASE + + + + + org.codehaus.mojo + jaxb2-maven-plugin + 1.3 + + + + xjc + + + + + ${basedir}/src/main/resources/org/april/hebdobot + ${basedir}/src/main/resources/org/april/hebdobot + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.7 + + + add-source + generate-sources + + add-source + + + + ${project.build.directory}/generated-sources/jaxb + + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.2.1 + + true + false + + + + + + + pircbot + pircbot + 1.5.0 + + + joda-time + joda-time + 2.8.1 + + + commons-io + commons-io + 2.4 + + + commons-lang + commons-lang + 2.6 + + + javax.xml.bind + jaxb-api + 2.2.12 + + + org.quartz-scheduler + quartz + 2.2.1 + + + org.apache.httpcomponents + httpclient + 4.5 + + + junit + junit + 4.12 + test + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + runtime + + + org.scribe + scribe + 1.3.7 + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-test + ${spring.version} + test + + + org.springframework + spring-context-support + ${spring.version} + runtime + + + commons-collections + commons-collections + 3.2.1 + + + org.springframework + spring-tx + ${spring.version} + runtime + + + org.springframework.social + spring-social-twitter + 1.1.0.RELEASE + + + diff --git a/src/org/april/hebdobot/model/Job.java b/src/org/april/hebdobot/model/Job.java new file mode 100644 index 0000000..cb89408 --- /dev/null +++ b/src/org/april/hebdobot/model/Job.java @@ -0,0 +1,96 @@ +/** + * Copyright (C) 2011-2013,2017 Nicolas Vinot + * Copyright (C) 2017 Christian Pierre MOMON + * + * 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 + */ +package org.april.hebdobot.model; + +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; + } +} diff --git a/test/org/april/hebdobot/BotMock.java b/test/org/april/hebdobot/BotMock.java new file mode 100644 index 0000000..f6ea321 --- /dev/null +++ b/test/org/april/hebdobot/BotMock.java @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2011-2013,2017 Nicolas Vinot + * Copyright (C) 2017 Christian Pierre MOMON + * + * 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 + */ +package org.april.hebdobot; + +import org.april.hebdobot.model.Hebdobot; + +/** + * The Class BotMock. + */ +public class BotMock extends Hebdobot +{ + /** + * Instantiates a new bot mock. + * + * @throws Exception + * the exception + */ + public BotMock() throws Exception + { + super("", 0, "bot", "channel", "revue.txt"); + } + + /* (non-Javadoc) + * @see org.april.hebdobot.irc.Bot#onMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ + @Override + public void onMessage(final String channel, final String sender, final String login, final String hostname, final String message) + { + super.onMessage(channel, sender, login, hostname, message); + } +} diff --git a/test/org/april/hebdobot/BotTest.java b/test/org/april/hebdobot/BotTest.java index 9aab94d..4911276 100644 --- a/test/org/april/hebdobot/BotTest.java +++ b/test/org/april/hebdobot/BotTest.java @@ -26,6 +26,7 @@ import java.io.Reader; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.april.hebdobot.model.Hebdobot; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration;