Cleaned ressources.

This commit is contained in:
Christian P. MOMON 2017-12-24 11:22:31 +01:00
parent 10189f547b
commit 366f35d7a4
9 changed files with 383 additions and 0 deletions

13
CHANGES Normal file
View File

@ -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

4
resources/hebdobot.cron Normal file
View File

@ -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

34
resources/hebdobot.initd Executable file
View File

@ -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

View File

@ -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

3
resources/notes Normal file
View File

@ -0,0 +1,3 @@
root@bots:/srv/hebdobot# find / -name "hebdobot*"
/etc/cron.d/hebdobot
/etc/init.d/hebdobot

157
resources/pom.xml Normal file
View File

@ -0,0 +1,157 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.april</groupId>
<artifactId>hebdobot</artifactId>
<version>1.2.3-SNAPSHOT</version>
<scm>
<connection>scm:hg:file://${basedir}</connection>
</scm>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
<slf4j.version>1.7.12</slf4j.version>
<spring.version>4.1.7.RELEASE</spring.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/org/april/hebdobot</schemaDirectory>
<bindingDirectory>${basedir}/src/main/resources/org/april/hebdobot</bindingDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/jaxb</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<localCheckout>true</localCheckout>
<pushChanges>false</pushChanges>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>pircbot</groupId>
<artifactId>pircbot</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.12</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-twitter</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,96 @@
/**
* Copyright (C) 2011-2013,2017 Nicolas Vinot <aeris@imirhil.fr>
* 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.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;
}
}

View File

@ -0,0 +1,48 @@
/**
* Copyright (C) 2011-2013,2017 Nicolas Vinot <aeris@imirhil.fr>
* 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;
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);
}
}

View File

@ -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;