Made a code review.

This commit is contained in:
Christian P. MOMON 2017-12-14 16:58:45 +01:00
parent 2465b8ced2
commit 688d5f0a88
21 changed files with 1177 additions and 194 deletions

View File

@ -1,4 +1,14 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
org.eclipse.jdt.core.codeComplete.fieldPrefixes=
org.eclipse.jdt.core.codeComplete.fieldSuffixes=
org.eclipse.jdt.core.codeComplete.localPrefixes=
org.eclipse.jdt.core.codeComplete.localSuffixes=
org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning

View File

@ -63,6 +63,10 @@ formatter_profile=_Hebdobot
formatter_settings_version=12 formatter_settings_version=12
jautodoc.cleanup.add_header=false jautodoc.cleanup.add_header=false
jautodoc.cleanup.replace_header=false jautodoc.cleanup.replace_header=false
org.eclipse.jdt.ui.exception.name=exception
org.eclipse.jdt.ui.gettersetter.use.is=true
org.eclipse.jdt.ui.keywordthis=false
org.eclipse.jdt.ui.overrideannotation=true
sp_cleanup.add_default_serial_version_id=true sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true sp_cleanup.add_missing_annotations=true

View File

@ -35,21 +35,36 @@ import fr.imirhil.april.hebdobot.pastebin.PastebinClient;
import fr.imirhil.april.hebdobot.pastebin.Private; import fr.imirhil.april.hebdobot.pastebin.Private;
import fr.imirhil.april.hebdobot.review.Review; import fr.imirhil.april.hebdobot.review.Review;
/**
* The Class Application.
*/
public class Application implements ReviewListener public class Application implements ReviewListener
{ {
private static final Logger LOGGER = LoggerFactory.getLogger(Application.class); private static final Logger logger = LoggerFactory.getLogger(Application.class);
private static final String FILE_SUFFIX = "file.suffix"; private static final String FILE_SUFFIX = "file.suffix";
private final Properties properties = Context.getBean("properties"); private final Properties properties;
private final Bot bot = Context.getBean(Bot.class); private final Bot bot;
private final PastebinClient pastebinClient = Context.getBean(PastebinClient.class); private final PastebinClient pastebinClient;
/**
* Instantiates a new application.
*
* @throws Exception
* the exception
*/
private Application() throws Exception private Application() throws Exception
{ {
this.properties = Context.getBean("properties");
this.bot = Context.getBean(Bot.class);
this.pastebinClient = Context.getBean(PastebinClient.class);
this.bot.add(this); this.bot.add(this);
} }
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.ReviewListener#onEnd(fr.imirhil.april.hebdobot.review.Review)
*/
@Override @Override
public void onEnd(final Review review) public void onEnd(final Review review)
{ {
@ -59,9 +74,9 @@ public class Application implements ReviewListener
{ {
this.bot.sendMessage("% Compte-rendu de la revue : " + this.pastebinClient.paste(text, "Revue APRIL " + date, Private.UNLISTED)); this.bot.sendMessage("% Compte-rendu de la revue : " + this.pastebinClient.paste(text, "Revue APRIL " + date, Private.UNLISTED));
} }
catch (final Exception e) catch (final Exception exception)
{ {
LOGGER.error("Error during Pastebin submit", e); logger.error("Error during Pastebin submit", exception);
} }
if (this.properties.containsKey(FILE_SUFFIX)) if (this.properties.containsKey(FILE_SUFFIX))
@ -72,13 +87,21 @@ public class Application implements ReviewListener
FileUtils.writeStringToFile(file, text); FileUtils.writeStringToFile(file, text);
this.bot.sendMessage("% Compte-rendu de la revue : " + file.getName()); this.bot.sendMessage("% Compte-rendu de la revue : " + file.getName());
} }
catch (final Exception e) catch (final Exception exception)
{ {
LOGGER.error("Error during file generation", e); logger.error("Error during file generation", exception);
} }
} }
} }
/**
* The main method.
*
* @param args
* the arguments
* @throws Exception
* the exception
*/
public static void main(final String[] args) throws Exception public static void main(final String[] args) throws Exception
{ {
new FileSystemXmlApplicationContext(System.getProperty("spring.conf", "conf.xml")).registerShutdownHook(); new FileSystemXmlApplicationContext(System.getProperty("spring.conf", "conf.xml")).registerShutdownHook();

View File

@ -25,17 +25,26 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/**
* The Class Context.
*/
@Component @Component
public final class Context implements ApplicationContextAware public final class Context implements ApplicationContextAware
{ {
private static ApplicationContext CONTEXT; private static ApplicationContext CONTEXT;
/* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@Override @Override
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException
{ {
CONTEXT = applicationContext; CONTEXT = applicationContext;
} }
/**
* Close.
*/
public static void close() public static void close()
{ {
if (CONTEXT instanceof ConfigurableApplicationContext) if (CONTEXT instanceof ConfigurableApplicationContext)
@ -44,12 +53,29 @@ public final class Context implements ApplicationContextAware
} }
} }
/**
* Gets the bean.
*
* @param <T>
* the generic type
* @param clazz
* the clazz
* @return the bean
*/
public static <T> T getBean(final Class<T> clazz) public static <T> T getBean(final Class<T> clazz)
{ {
return CONTEXT.getBean(clazz); return CONTEXT.getBean(clazz);
} }
@SuppressWarnings("unchecked") /**
* Gets the bean.
*
* @param <T>
* the generic type
* @param name
* the name
* @return the bean
*/
public static <T> T getBean(final String name) public static <T> T getBean(final String name)
{ {
return (T) CONTEXT.getBean(name); return (T) CONTEXT.getBean(name);

View File

@ -25,6 +25,9 @@ import org.springframework.social.twitter.api.impl.TwitterTemplate;
import fr.imirhil.april.hebdobot.irc.Bot; import fr.imirhil.april.hebdobot.irc.Bot;
/**
* The Class Job.
*/
public class Job public class Job
{ {
@Resource @Resource
@ -34,21 +37,36 @@ public class Job
private String tweet; private String tweet;
private String irc; private String irc;
/**
* At 30.
*/
public void at30() public void at30()
{ {
this.notify(30); this.notify(30);
} }
/**
* At 45.
*/
public void at45() public void at45()
{ {
this.notify(15); this.notify(15);
} }
/**
* At 55.
*/
public void at55() public void at55()
{ {
this.notify(5); this.notify(5);
} }
/**
* Notify.
*
* @param min
* the min
*/
private void notify(final int min) private void notify(final int min)
{ {
this.bot.sendMessage(String.format(this.irc, min)); this.bot.sendMessage(String.format(this.irc, min));
@ -56,11 +74,23 @@ public class Job
this.twitterClient.timelineOperations().updateStatus(tweet); this.twitterClient.timelineOperations().updateStatus(tweet);
} }
/**
* Sets the irc.
*
* @param message
* the new irc
*/
public void setIrc(final String message) public void setIrc(final String message)
{ {
this.irc = message; this.irc = message;
} }
/**
* Sets the tweet.
*
* @param message
* the new tweet
*/
public void setTweet(final String message) public void setTweet(final String message)
{ {
this.tweet = message; this.tweet = message;

View File

@ -27,8 +27,19 @@ import org.scribe.model.Token;
import org.scribe.model.Verifier; import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService; import org.scribe.oauth.OAuthService;
/**
* The Class OAuthRegistration.
*/
public class OAuthRegistration public class OAuthRegistration
{ {
/**
* The main method.
*
* @param args
* the arguments
* @throws Exception
* the exception
*/
public static void main(final String args[]) throws Exception public static void main(final String args[]) throws Exception
{ {
final OAuthService service = new ServiceBuilder().provider(TwitterApi.class).apiKey("uCZMXbUWuda7a2RqqKd2yg") final OAuthService service = new ServiceBuilder().provider(TwitterApi.class).apiKey("uCZMXbUWuda7a2RqqKd2yg")

View File

@ -20,6 +20,7 @@
package fr.imirhil.april.hebdobot.irc; package fr.imirhil.april.hebdobot.irc;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -36,41 +37,86 @@ import fr.imirhil.april.hebdobot.review.Message;
import fr.imirhil.april.hebdobot.review.Review; import fr.imirhil.april.hebdobot.review.Review;
import fr.imirhil.april.hebdobot.review.Topic; import fr.imirhil.april.hebdobot.review.Topic;
/**
* The Class Bot.
*/
public class Bot extends PircBot public class Bot extends PircBot
{ {
/**
* The Class Handler.
*/
private abstract class Handler private abstract class Handler
{ {
/**
* Handle.
*
* @param sender
* the sender
* @param message
* the message
* @return true, if successful
*/
public abstract boolean handle(String sender, String message); public abstract boolean handle(String sender, String message);
} }
private static final Logger LOGGER = LoggerFactory.getLogger(Bot.class); private static final Logger logger = LoggerFactory.getLogger(Bot.class);
private final String host; private final String host;
private final int port; private final int port;
private final String channel; private final String channel;
private Review review = null; private Review review = null;
private final Collection<ReviewListener> listeners = new LinkedList<ReviewListener>(); private final Collection<ReviewListener> listeners;
private final List<Handler> handlers = new LinkedList<Handler>(); private final List<Handler> handlers;
/**
* Instantiates a new bot.
*
* @param host
* the host
* @param port
* the port
* @param name
* the name
* @param channel
* the channel
*/
public Bot(final String host, final int port, final String name, final String channel) public Bot(final String host, final int port, final String name, final String channel)
{ {
this.host = host; this.host = host;
this.port = port; this.port = port;
this.channel = channel; this.channel = channel;
this.setName(name); this.setName(name);
this.listeners = new LinkedList<ReviewListener>();
this.handlers = new LinkedList<Handler>();
} }
/**
* Adds the.
*
* @param listener
* the listener
*/
public void add(final ReviewListener listener) public void add(final ReviewListener listener)
{ {
this.listeners.add(listener); this.listeners.add(listener);
} }
/**
* Close.
*/
public void close() public void close()
{ {
this.disconnect(); this.disconnect();
this.dispose(); this.dispose();
} }
/**
* Inits the.
*
* @throws Exception
* the exception
*/
public void init() throws Exception public void init() throws Exception
{ {
this.connect(this.host, this.port); this.connect(this.host, this.port);
@ -79,282 +125,415 @@ public class Bot extends PircBot
this.registerHandlers(); this.registerHandlers();
} }
/* (non-Javadoc)
* @see org.jibble.pircbot.PircBot#onMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
@Override @Override
protected void onMessage(final String channel, final String sender, final String login, final String hostname, String message) protected void onMessage(final String channel, final String sender, final String login, final String hostname, String message)
{ {
LOGGER.debug("Message received - channel : {}, sender : {}, message : {}", new Object[] { channel, sender, message }); logger.debug("Message received - channel : {}, sender : {}, message : {}", channel, sender, message);
if (!channel.equalsIgnoreCase(this.channel)) if (channel.equalsIgnoreCase(this.channel))
{ {
return; message = message.trim();
}
message = message.trim(); boolean ended = false;
Iterator<Handler> iterator = this.handlers.iterator();
for (final Handler handler : this.handlers) while (!ended)
{
if (handler.handle(sender, message))
{ {
break; if (iterator.hasNext())
{
Handler currentHandler = iterator.next();
if (currentHandler.handle(sender, message))
{
ended = true;
}
}
else
{
ended = true;
}
} }
} }
} }
/**
* Register handlers.
*/
private void registerHandlers() private void registerHandlers()
{ {
// Help // Help
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
if (!"!help".equalsIgnoreCase(message)) boolean result;
if (StringUtils.equalsIgnoreCase(message, "!help"))
{ {
return false; Bot.this.sendMessage(sender, "Bienvenue " + sender);
Bot.this.sendMessage(sender, "Je suis " + Bot.this.getName() + ", le robot de gestion des revues hebdomadaires de l'APRIL");
Bot.this.sendMessage(sender, "Voici les commandes que je comprend :");
Bot.this.sendMessage(sender, " ");
Bot.this.sendMessage(sender, "— !debut : commencer une nouvelle revue");
Bot.this.sendMessage(sender, "— !fin : terminer la revue en cours");
Bot.this.sendMessage(sender, "— # titre : démarrer un sujet individuel");
Bot.this.sendMessage(sender, "— ## titre : démarrer un sujet collectif");
Bot.this.sendMessage(sender, "— !courant : affiche le sujet en cours");
Bot.this.sendMessage(sender, "— !manquants : affiche les participants qui n'ont pas répondu sur le dernier sujet");
Bot.this.sendMessage(sender, "— % message : un commentaire");
result = true;
}
else
{
result = false;
} }
Bot.this.sendMessage(sender, "Bienvenue " + sender); //
Bot.this.sendMessage(sender, "Je suis " + Bot.this.getName() + ", le robot de gestion des revues hebdomadaires de l'APRIL"); return result;
Bot.this.sendMessage(sender, "Voici les commandes que je comprend :");
Bot.this.sendMessage(sender, " ");
Bot.this.sendMessage(sender, "— !debut : commencer une nouvelle revue");
Bot.this.sendMessage(sender, "— !fin : terminer la revue en cours");
Bot.this.sendMessage(sender, "— # titre : démarrer un sujet individuel");
Bot.this.sendMessage(sender, "— ## titre : démarrer un sujet collectif");
Bot.this.sendMessage(sender, "— !courant : affiche le sujet en cours");
Bot.this.sendMessage(sender, "— !manquants : affiche les participants qui n'ont pas répondu sur le dernier sujet");
Bot.this.sendMessage(sender, "— % message : un commentaire");
return true;
} }
}); });
// Die // Die
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
if (!"!stop".equalsIgnoreCase(message)) boolean result;
{
return false;
}
if (Bot.this.review != null) if (!StringUtils.equalsIgnoreCase(message, "!stop"))
{
result = false;
}
else if (Bot.this.review != null)
{ {
Bot.this.sendMessage("% Une revue est en cours, arrêt impossible"); Bot.this.sendMessage("% Une revue est en cours, arrêt impossible");
return false; result = false;
}
else
{
Context.close();
result = true;
} }
Context.close(); //
return true; return result;
} }
}); });
// Start // Start
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
if (!"!debut".equalsIgnoreCase(message)) boolean result;
if (!StringUtils.equalsIgnoreCase(message, "!debut"))
{ {
return false; result = false;
}
else
{
Bot.this.review = new Review(sender);
Bot.this.sendMessage(sender, "Vous êtes le conducteur de réunion");
Bot.this.sendMessage(sender, "Pour terminer la réunion, tapez \"!fin\"");
Bot.this.sendMessage("% Début de la réunion hebdomadaire");
Bot.this.sendMessage(
"% rappel : toute ligne commençant par % sera considérée comme un commentaire et non prise en compte dans la synthèse");
result = true;
} }
Bot.this.review = new Review(sender); //
Bot.this.sendMessage(sender, "Vous êtes le conducteur de réunion"); return result;
Bot.this.sendMessage(sender, "Pour terminer la réunion, tapez \"!fin\"");
Bot.this.sendMessage("% Début de la réunion hebdomadaire");
Bot.this.sendMessage(
"% rappel : toute ligne commençant par % sera considérée comme un commentaire et non prise en compte dans la synthèse");
return true;
} }
}); });
// Stop // Stop
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
if (Bot.this.review == null || !"!fin".equalsIgnoreCase(message)) boolean result;
if (Bot.this.review == null || !StringUtils.equalsIgnoreCase(message, "!fin"))
{ {
return false; result = false;
}
else
{
if (!Bot.this.review.isOwner(sender))
{
Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
result = false;
}
else
{
for (final ReviewListener listener : Bot.this.listeners)
{
listener.onEnd(Bot.this.review);
}
Bot.this.sendMessage("% " + Bot.this.review.getOwner()
+ ", ne pas oublier d'ajouter le compte-rendu de la revue sur https://agir.april.org/issues/135");
final String participants = StringUtils.join(Bot.this.review.getParticipants(), " ");
Bot.this.sendMessage("% " + participants + ", pensez à noter votre bénévalo : http://www.april.org/my?action=benevalo");
Bot.this.sendMessage("% Fin de la revue hebdomadaire");
Bot.this.review = null;
result = true;
}
} }
if (!Bot.this.review.isOwner(sender)) //
{ return result;
Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
return false;
}
for (final ReviewListener listener : Bot.this.listeners)
{
listener.onEnd(Bot.this.review);
}
Bot.this.sendMessage("% " + Bot.this.review.getOwner()
+ ", ne pas oublier d'ajouter le compte-rendu de la revue sur https://agir.april.org/issues/135");
final String participants = StringUtils.join(Bot.this.review.getParticipants(), " ");
Bot.this.sendMessage("% " + participants + ", pensez à noter votre bénévalo : http://www.april.org/my?action=benevalo");
Bot.this.sendMessage("% Fin de la revue hebdomadaire");
Bot.this.review = null;
return true;
} }
}); });
// Collective topic, must be before individual topic // Collective topic, must be before individual topic
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
boolean result;
if (Bot.this.review == null || !message.matches("\\s*##.*")) if (Bot.this.review == null || !message.matches("\\s*##.*"))
{ {
return false; result = false;
}
if (!Bot.this.review.isOwner(sender))
{
Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
return false;
}
final CollectiveTopic topic = new CollectiveTopic(message.replaceFirst("##", "").trim());
Bot.this.review.begin(topic);
Bot.this.sendMessage("Sujet collectif : " + topic.getTitle());
if (topic.getTitle().toLowerCase().contains("bloquage"))
{
Bot.this.sendMessage("% si rien à dire vous pouvez dire %ras");
} }
else else
{ {
Bot.this.sendMessage("% 1 minute max"); if (Bot.this.review.isOwner(sender))
{
final CollectiveTopic topic = new CollectiveTopic(message.replaceFirst("##", "").trim());
Bot.this.review.begin(topic);
Bot.this.sendMessage("Sujet collectif : " + topic.getTitle());
if (topic.getTitle().toLowerCase().contains("bloquage"))
{
Bot.this.sendMessage("% si rien à dire vous pouvez dire %ras");
}
else
{
Bot.this.sendMessage("% 1 minute max");
}
result = true;
}
else
{
Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
result = false;
}
} }
return true;
//
return result;
} }
}); });
// Individual topic // Individual topic
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
boolean result;
if (Bot.this.review == null || !message.matches("\\s*#[^#].*")) if (Bot.this.review == null || !message.matches("\\s*#[^#].*"))
{ {
return false; result = false;
} }
else
if (!Bot.this.review.isOwner(sender))
{ {
Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion"); if (Bot.this.review.isOwner(sender))
return false; {
Bot.this.sendMessage(sender + ", vous n'êtes pas le conducteur de la réunion");
result = false;
}
else
{
final IndividualTopic topic = new IndividualTopic(message.replaceFirst("#", "").trim());
Bot.this.review.begin(topic);
Bot.this.sendMessage("Sujet individuel : " + topic.getTitle());
Bot.this.sendMessage("% quand vous avez fini vous le dites par % fini");
result = true;
}
} }
final IndividualTopic topic = new IndividualTopic(message.replaceFirst("#", "").trim()); //
Bot.this.review.begin(topic); return result;
Bot.this.sendMessage("Sujet individuel : " + topic.getTitle());
Bot.this.sendMessage("% quand vous avez fini vous le dites par % fini");
return true;
} }
}); });
// Missing // Missing
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
if (Bot.this.review == null || !"!manquants".equalsIgnoreCase(message)) boolean result;
if (Bot.this.review == null || !StringUtils.equalsIgnoreCase(message, "!manquants"))
{ {
return false; result = false;
}
else
{
final Topic topic = Bot.this.review.getCurrentTopic();
if (topic == null)
{
Bot.this.sendMessage("Aucun sujet traité");
result = true;
}
else
{
final Collection<String> participants = Bot.this.review.getParticipants();
final Collection<String> currentParticipants = topic.getParticipants();
final Collection<String> missing = CollectionUtils.subtract(participants, currentParticipants);
if (missing.isEmpty())
{
Bot.this.sendMessage("Aucun participant manquant \\o/");
result = true;
}
else
{
Bot.this.sendMessage(String.format("Les participants suivants sont manquants : %1s", StringUtils.join(missing, ", ")));
result = true;
}
}
} }
final Topic topic = Bot.this.review.getCurrentTopic(); //
if (topic == null) return result;
{
Bot.this.sendMessage("Aucun sujet traité");
return true;
}
final Collection<String> participants = Bot.this.review.getParticipants();
final Collection<String> currentParticipants = topic.getParticipants();
@SuppressWarnings("unchecked")
final Collection<String> missing = CollectionUtils.subtract(participants, currentParticipants);
if (missing.isEmpty())
{
Bot.this.sendMessage("Aucun participant manquant \\o/");
return true;
}
Bot.this.sendMessage(String.format("Les participants suivants sont manquants : %1s", StringUtils.join(missing, ", ")));
return true;
} }
}); });
// Current // Current
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
if (Bot.this.review == null || !"!courant".equalsIgnoreCase(message)) boolean result;
if (Bot.this.review == null || !StringUtils.equalsIgnoreCase(message, "!courant"))
{ {
return false; result = false;
}
else
{
final Topic current = Bot.this.review.getCurrentTopic();
if (current == null)
{
Bot.this.sendMessage("% Pas de sujet en cours");
}
else if (current instanceof IndividualTopic)
{
Bot.this.sendMessage("% Sujet individuel en cours : " + current.getTitle());
}
else if (current instanceof CollectiveTopic)
{
Bot.this.sendMessage("% Sujet collectif en cours : " + current.getTitle());
}
result = true;
} }
final Topic current = Bot.this.review.getCurrentTopic(); //
if (current == null) return result;
{
Bot.this.sendMessage("% Pas de sujet en cours");
}
else if (current instanceof IndividualTopic)
{
Bot.this.sendMessage("% Sujet individuel en cours : " + current.getTitle());
}
else if (current instanceof CollectiveTopic)
{
Bot.this.sendMessage("% Sujet collectif en cours : " + current.getTitle());
}
return true;
} }
}); });
// Topic message // Topic message
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
boolean result;
if (Bot.this.review == null || message.startsWith("%")) if (Bot.this.review == null || message.startsWith("%"))
{ {
return false; result = false;
} }
Bot.this.review.add(new Message(sender, message)); else
return true; {
Bot.this.review.add(new Message(sender, message));
result = true;
}
//
return result;
} }
}); });
// All the other // All the other
this.handlers.add(new Handler() this.handlers.add(new Handler()
{ {
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot.Handler#handle(java.lang.String, java.lang.String)
*/
@Override @Override
public boolean handle(final String sender, final String message) public boolean handle(final String sender, final String message)
{ {
boolean result;
if (Bot.this.review == null) if (Bot.this.review == null)
{ {
return false; result = false;
} }
Bot.this.review.addRaw(new Message(sender, message)); else
return true; {
Bot.this.review.addRaw(new Message(sender, message));
result = true;
}
//
return result;
} }
}); });
} }
/**
* Send message.
*
* @param message
* the message
*/
public void sendMessage(final String message) public void sendMessage(final String message)
{ {
LOGGER.debug("Send message : {}", message); logger.debug("Send message : {}", message);
this.sendMessage(this.channel, message); this.sendMessage(this.channel, message);
} }
} }

View File

@ -21,7 +21,22 @@ package fr.imirhil.april.hebdobot.irc;
import fr.imirhil.april.hebdobot.review.Review; import fr.imirhil.april.hebdobot.review.Review;
/**
* The listener interface for receiving review events. The class that is
* interested in processing a review event implements this interface, and the
* object created with that class is registered with a component using the
* component's <code>addReviewListener<code> method. When the review event
* occurs, that object's appropriate method is invoked.
*
* @see ReviewEvent
*/
public interface ReviewListener public interface ReviewListener
{ {
/**
* On end.
*
* @param review
* the review
*/
void onEnd(Review review); void onEnd(Review review);
} }

View File

@ -19,6 +19,9 @@
*/ */
package fr.imirhil.april.hebdobot.pastebin; package fr.imirhil.april.hebdobot.pastebin;
/**
* The Enum Expiration.
*/
public enum Expiration public enum Expiration
{ {
NEVER(null), NEVER(null),
@ -29,11 +32,22 @@ public enum Expiration
private final String value; private final String value;
/**
* Instantiates a new expiration.
*
* @param value
* the value
*/
private Expiration(final String value) private Expiration(final String value)
{ {
this.value = value; this.value = value;
} }
/**
* Gets the value.
*
* @return the value
*/
public String getValue() public String getValue()
{ {
return this.value; return this.value;

View File

@ -19,6 +19,9 @@
*/ */
package fr.imirhil.april.hebdobot.pastebin; package fr.imirhil.april.hebdobot.pastebin;
/**
* The Enum Format.
*/
public enum Format public enum Format
{ {
NONE(null), NONE(null),
@ -29,11 +32,22 @@ public enum Format
private final String value; private final String value;
/**
* Instantiates a new format.
*
* @param value
* the value
*/
private Format(final String value) private Format(final String value)
{ {
this.value = value; this.value = value;
} }
/**
* Gets the value.
*
* @return the value
*/
public String getValue() public String getValue()
{ {
return this.value; return this.value;

View File

@ -19,17 +19,31 @@
*/ */
package fr.imirhil.april.hebdobot.pastebin; package fr.imirhil.april.hebdobot.pastebin;
/**
* The Enum Option.
*/
public enum Option public enum Option
{ {
PASTE("paste"); PASTE("paste");
private final String value; private final String value;
/**
* Instantiates a new option.
*
* @param value
* the value
*/
private Option(final String value) private Option(final String value)
{ {
this.value = value; this.value = value;
} }
/**
* Gets the value.
*
* @return the value
*/
public String getValue() public String getValue()
{ {
return this.value; return this.value;

View File

@ -32,17 +32,37 @@ import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HTTP;
/**
* The Class PastebinClient.
*/
public class PastebinClient public class PastebinClient
{ {
/**
* The Class APIException.
*/
public static class APIException extends Exception public static class APIException extends Exception
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**
* Instantiates a new API exception.
*
* @param message
* the message
*/
private APIException(final String message) private APIException(final String message)
{ {
super(message); super(message);
} }
/**
* Throw if error.
*
* @param content
* the content
* @throws APIException
* the API exception
*/
private static void throwIfError(final String content) throws APIException private static void throwIfError(final String content) throws APIException
{ {
if (content.contains(API_ERROR)) if (content.contains(API_ERROR))
@ -52,6 +72,9 @@ public class PastebinClient
} }
} }
private static final String API_LOGIN_URL = "http://pastebin.com/api/api_login.php";
private static final String API_POST_URL = "http://pastebin.com/api/api_post.php";
private static final String API_DEV_KEY = "api_dev_key"; private static final String API_DEV_KEY = "api_dev_key";
private static final String API_USER_KEY = "api_user_key"; private static final String API_USER_KEY = "api_user_key";
private static final String API_USER_NAME = "api_user_name"; private static final String API_USER_NAME = "api_user_name";
@ -60,6 +83,7 @@ public class PastebinClient
private static final String API_PASTE_PRIVATE = "api_paste_private"; private static final String API_PASTE_PRIVATE = "api_paste_private";
private static final String API_PASTE_NAME = "api_paste_name"; private static final String API_PASTE_NAME = "api_paste_name";
private static final String API_PASTE_EXPIRATION = "api_paste_expire_date"; private static final String API_PASTE_EXPIRATION = "api_paste_expire_date";
private static final String API_PASTE_FORMAT = "api_paste_format"; private static final String API_PASTE_FORMAT = "api_paste_format";
private static final String API_PASTE_CODE = "api_paste_code"; private static final String API_PASTE_CODE = "api_paste_code";
@ -68,13 +92,30 @@ public class PastebinClient
private final String apiKey; private final String apiKey;
private String apiUserKey = null; private String apiUserKey = null;
HttpClient httpClient = new DefaultHttpClient();
private HttpClient httpClient = new DefaultHttpClient();
/**
* Instantiates a new pastebin client.
*
* @param apiKey
* the api key
*/
public PastebinClient(final String apiKey) public PastebinClient(final String apiKey)
{ {
this.apiKey = apiKey; this.apiKey = apiKey;
} }
/**
* Login.
*
* @param name
* the name
* @param password
* the password
* @throws Exception
* the exception
*/
public void login(final String name, final String password) throws Exception public void login(final String name, final String password) throws Exception
{ {
final List<NameValuePair> params = new LinkedList<NameValuePair>(); final List<NameValuePair> params = new LinkedList<NameValuePair>();
@ -82,7 +123,7 @@ public class PastebinClient
setParameter(params, API_USER_NAME, name); setParameter(params, API_USER_NAME, name);
setParameter(params, API_USER_PASSWORD, password); setParameter(params, API_USER_PASSWORD, password);
final HttpPost request = new HttpPost("http://pastebin.com/api/api_login.php"); final HttpPost request = new HttpPost(API_LOGIN_URL);
request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
final HttpResponse response = this.httpClient.execute(request); final HttpResponse response = this.httpClient.execute(request);
@ -91,68 +132,297 @@ public class PastebinClient
this.apiUserKey = content; this.apiUserKey = content;
} }
/**
* Paste.
*
* @param code
* the code
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code) throws Exception public String paste(final String code) throws Exception
{ {
return this.paste(code, null, Format.NONE, Private.PUBLIC, Expiration.DAY_1); String result;
result = this.paste(code, null, Format.NONE, Private.PUBLIC, Expiration.DAY_1);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param expiration
* the expiration
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final Expiration expiration) throws Exception public String paste(final String code, final Expiration expiration) throws Exception
{ {
return this.paste(code, null, Format.NONE, Private.PUBLIC, expiration); String result;
result = this.paste(code, null, Format.NONE, Private.PUBLIC, expiration);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param format
* the format
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final Format format) throws Exception public String paste(final String code, final Format format) throws Exception
{ {
return this.paste(code, null, format, Private.PUBLIC, Expiration.DAY_1); String result;
result = this.paste(code, null, format, Private.PUBLIC, Expiration.DAY_1);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param format
* the format
* @param expiration
* the expiration
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final Format format, final Expiration expiration) throws Exception public String paste(final String code, final Format format, final Expiration expiration) throws Exception
{ {
return this.paste(code, null, format, Private.PUBLIC, expiration); String result;
result = this.paste(code, null, format, Private.PUBLIC, expiration);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param format
* the format
* @param privat
* the privat
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final Format format, final Private privat) throws Exception public String paste(final String code, final Format format, final Private privat) throws Exception
{ {
return this.paste(code, null, format, privat, Expiration.DAY_1); String result;
result = this.paste(code, null, format, privat, Expiration.DAY_1);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param format
* the format
* @param privat
* the privat
* @param expiration
* the expiration
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final Format format, final Private privat, final Expiration expiration) throws Exception public String paste(final String code, final Format format, final Private privat, final Expiration expiration) throws Exception
{ {
return this.paste(code, null, format, privat, expiration); String result;
result = this.paste(code, null, format, privat, expiration);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param privat
* the privat
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final Private privat) throws Exception public String paste(final String code, final Private privat) throws Exception
{ {
return this.paste(code, null, Format.NONE, privat, Expiration.DAY_1); String result;
result = this.paste(code, null, Format.NONE, privat, Expiration.DAY_1);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param privat
* the privat
* @param expiration
* the expiration
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final Private privat, final Expiration expiration) throws Exception public String paste(final String code, final Private privat, final Expiration expiration) throws Exception
{ {
return this.paste(code, null, Format.NONE, privat, expiration); String result;
result = this.paste(code, null, Format.NONE, privat, expiration);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param name
* the name
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final String name) throws Exception public String paste(final String code, final String name) throws Exception
{ {
return this.paste(code, name, Format.NONE, Private.PUBLIC, Expiration.DAY_1); String result;
result = this.paste(code, name, Format.NONE, Private.PUBLIC, Expiration.DAY_1);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param name
* the name
* @param format
* the format
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final String name, final Format format) throws Exception public String paste(final String code, final String name, final Format format) throws Exception
{ {
return this.paste(code, name, format, Private.PUBLIC, Expiration.DAY_1); String result;
result = this.paste(code, name, format, Private.PUBLIC, Expiration.DAY_1);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param name
* the name
* @param format
* the format
* @param expiration
* the expiration
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final String name, final Format format, final Expiration expiration) throws Exception public String paste(final String code, final String name, final Format format, final Expiration expiration) throws Exception
{ {
return this.paste(code, name, format, Private.PUBLIC, expiration); String result;
result = this.paste(code, name, format, Private.PUBLIC, expiration);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param name
* the name
* @param format
* the format
* @param privat
* the privat
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final String name, final Format format, final Private privat) throws Exception public String paste(final String code, final String name, final Format format, final Private privat) throws Exception
{ {
return this.paste(code, name, format, privat, Expiration.DAY_1); String result;
result = this.paste(code, name, format, privat, Expiration.DAY_1);
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param name
* the name
* @param format
* the format
* @param privat
* the privat
* @param expiration
* the expiration
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final String name, final Format format, final Private privat, final Expiration expiration) throws Exception public String paste(final String code, final String name, final Format format, final Private privat, final Expiration expiration) throws Exception
{ {
String result;
final List<NameValuePair> params = new LinkedList<NameValuePair>(); final List<NameValuePair> params = new LinkedList<NameValuePair>();
setParameter(params, API_DEV_KEY, this.apiKey); setParameter(params, API_DEV_KEY, this.apiKey);
setParameter(params, API_USER_KEY, this.apiUserKey); setParameter(params, API_USER_KEY, this.apiUserKey);
@ -163,20 +433,50 @@ public class PastebinClient
setParameter(params, API_PASTE_FORMAT, format.getValue()); setParameter(params, API_PASTE_FORMAT, format.getValue());
setParameter(params, API_PASTE_CODE, code); setParameter(params, API_PASTE_CODE, code);
final HttpPost request = new HttpPost("http://pastebin.com/api/api_post.php"); final HttpPost request = new HttpPost(API_POST_URL);
request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
final HttpResponse response = this.httpClient.execute(request); final HttpResponse response = this.httpClient.execute(request);
final String content = IOUtils.toString(response.getEntity().getContent()); result = IOUtils.toString(response.getEntity().getContent());
APIException.throwIfError(content); APIException.throwIfError(result);
return content;
//
return result;
} }
/**
* Paste.
*
* @param code
* the code
* @param name
* the name
* @param privat
* the privat
* @return the string
* @throws Exception
* the exception
*/
public String paste(final String code, final String name, final Private privat) throws Exception public String paste(final String code, final String name, final Private privat) throws Exception
{ {
return this.paste(code, name, Format.NONE, privat, Expiration.DAY_1); String result;
result = this.paste(code, name, Format.NONE, privat, Expiration.DAY_1);
//
return result;
} }
/**
* Sets the parameter.
*
* @param params
* the params
* @param name
* the name
* @param value
* the value
*/
private static void setParameter(final List<NameValuePair> params, final String name, final String value) private static void setParameter(final List<NameValuePair> params, final String name, final String value)
{ {
if (value == null) if (value == null)

View File

@ -19,6 +19,9 @@
*/ */
package fr.imirhil.april.hebdobot.pastebin; package fr.imirhil.april.hebdobot.pastebin;
/**
* The Enum Private.
*/
public enum Private public enum Private
{ {
PUBLIC("0"), PUBLIC("0"),
@ -27,11 +30,22 @@ public enum Private
private String value; private String value;
/**
* Instantiates a new private.
*
* @param value
* the value
*/
private Private(final String value) private Private(final String value)
{ {
this.value = value; this.value = value;
} }
/**
* Gets the value.
*
* @return the value
*/
String getValue() String getValue()
{ {
return this.value; return this.value;

View File

@ -24,26 +24,46 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
/**
* The Class CollectiveTopic.
*/
public class CollectiveTopic extends Topic public class CollectiveTopic extends Topic
{ {
private final List<Message> messages = new LinkedList<Message>(); private final List<Message> messages = new LinkedList<Message>();
/**
* Instantiates a new collective topic.
*
* @param title
* the title
*/
public CollectiveTopic(final String title) public CollectiveTopic(final String title)
{ {
super(title); super(title);
} }
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.review.Topic#add(fr.imirhil.april.hebdobot.review.Message)
*/
@Override @Override
public void add(final Message message) public void add(final Message message)
{ {
this.messages.add(message); this.messages.add(message);
} }
/**
* Gets the messages.
*
* @return the messages
*/
public List<Message> getMessages() public List<Message> getMessages()
{ {
return this.messages; return this.messages;
} }
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.review.Topic#getParticipants()
*/
@Override @Override
public Set<String> getParticipants() public Set<String> getParticipants()
{ {

View File

@ -25,15 +25,27 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
/**
* The Class IndividualTopic.
*/
public class IndividualTopic extends Topic public class IndividualTopic extends Topic
{ {
private final Map<String, List<Message>> messages = new HashMap<String, List<Message>>(); private final Map<String, List<Message>> messages = new HashMap<String, List<Message>>();
/**
* Instantiates a new individual topic.
*
* @param title
* the title
*/
public IndividualTopic(final String title) public IndividualTopic(final String title)
{ {
super(title); super(title);
} }
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.review.Topic#add(fr.imirhil.april.hebdobot.review.Message)
*/
@Override @Override
public void add(final Message message) public void add(final Message message)
{ {
@ -45,17 +57,34 @@ public class IndividualTopic extends Topic
this.messages.get(author).add(message); this.messages.get(author).add(message);
} }
/**
* Gets the messages.
*
* @param author
* the author
* @return the messages
*/
public List<Message> getMessages(final String author) public List<Message> getMessages(final String author)
{ {
return this.messages.get(author); return this.messages.get(author);
} }
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.review.Topic#getParticipants()
*/
@Override @Override
public Set<String> getParticipants() public Set<String> getParticipants()
{ {
return this.messages.keySet(); return this.messages.keySet();
} }
/**
* Checks for participant.
*
* @param participant
* the participant
* @return true, if successful
*/
public boolean hasParticipant(final String participant) public boolean hasParticipant(final String participant)
{ {
return this.messages.containsKey(participant); return this.messages.containsKey(participant);

View File

@ -21,28 +21,54 @@ package fr.imirhil.april.hebdobot.review;
import org.joda.time.DateTime; import org.joda.time.DateTime;
/**
* The Class Message.
*/
public class Message public class Message
{ {
private final DateTime date = new DateTime(); private final DateTime date = new DateTime();
private final String author; private final String author;
private final String content; private final String content;
/**
* Instantiates a new message.
*
* @param author
* the author
* @param content
* the content
*/
public Message(final String author, final String content) public Message(final String author, final String content)
{ {
this.author = author; this.author = author;
this.content = content; this.content = content;
} }
/**
* Gets the author.
*
* @return the author
*/
public String getAuthor() public String getAuthor()
{ {
return this.author; return this.author;
} }
/**
* Gets the content.
*
* @return the content
*/
public String getContent() public String getContent()
{ {
return this.content; return this.content;
} }
/**
* Gets the date.
*
* @return the date
*/
public DateTime getDate() public DateTime getDate()
{ {
return this.date; return this.date;

View File

@ -32,23 +32,43 @@ import org.joda.time.format.DateTimeFormat;
import fr.imirhil.april.hebdobot.Context; import fr.imirhil.april.hebdobot.Context;
import fr.imirhil.april.hebdobot.xml.UserAlias; import fr.imirhil.april.hebdobot.xml.UserAlias;
/**
* The Class Review.
*/
public class Review public class Review
{ {
private static final int LENGTH = 80; private static final int LENGTH = 80;
private static final UserAlias USER_ALIAS = Context.getBean(UserAlias.class); private static final UserAlias USER_ALIAS = Context.getBean(UserAlias.class);
private final Set<String> participants = new HashSet<String>(); private final Set<String> participants;
private final List<IndividualTopic> individualTopics = new LinkedList<IndividualTopic>(); private final List<IndividualTopic> individualTopics;
private final List<CollectiveTopic> collectiveTopics = new LinkedList<CollectiveTopic>(); private final List<CollectiveTopic> collectiveTopics;
private Topic currentTopic; private Topic currentTopic;
private final List<Message> messages = new LinkedList<Message>(); private final List<Message> messages;
private final String owner; private final String owner;
/**
* Instantiates a new review.
*
* @param owner
* the owner
*/
public Review(final String owner) public Review(final String owner)
{ {
this.participants = new HashSet<String>();
this.individualTopics = new LinkedList<IndividualTopic>();
this.collectiveTopics = new LinkedList<CollectiveTopic>();
this.messages = new LinkedList<Message>();
this.owner = owner; this.owner = owner;
} }
/**
* Adds the.
*
* @param message
* the message
*/
public void add(final Message message) public void add(final Message message)
{ {
if (this.currentTopic != null) if (this.currentTopic != null)
@ -59,55 +79,105 @@ public class Review
this.addRaw(message); this.addRaw(message);
} }
/**
* Adds the raw.
*
* @param message
* the message
*/
public void addRaw(final Message message) public void addRaw(final Message message)
{ {
this.messages.add(message); this.messages.add(message);
} }
/**
* Begin.
*
* @param topic
* the topic
*/
public void begin(final CollectiveTopic topic) public void begin(final CollectiveTopic topic)
{ {
this.collectiveTopics.add(topic); this.collectiveTopics.add(topic);
this.currentTopic = topic; this.currentTopic = topic;
} }
/**
* Begin.
*
* @param topic
* the topic
*/
public void begin(final IndividualTopic topic) public void begin(final IndividualTopic topic)
{ {
this.individualTopics.add(topic); this.individualTopics.add(topic);
this.currentTopic = topic; this.currentTopic = topic;
} }
/**
* Gets the current topic.
*
* @return the current topic
*/
public Topic getCurrentTopic() public Topic getCurrentTopic()
{ {
return this.currentTopic; return this.currentTopic;
} }
/**
* Gets the owner.
*
* @return the owner
*/
public String getOwner() public String getOwner()
{ {
return this.owner; return this.owner;
} }
/**
* Gets the participants.
*
* @return the participants
*/
public Collection<String> getParticipants() public Collection<String> getParticipants()
{ {
final Collection<String> reviewers = new HashSet<String>(); Collection<String> result;
result = new HashSet<String>();
for (final Topic topic : this.individualTopics) for (final Topic topic : this.individualTopics)
{ {
reviewers.addAll(topic.getParticipants()); result.addAll(topic.getParticipants());
} }
for (final Topic topic : this.collectiveTopics) for (final Topic topic : this.collectiveTopics)
{ {
reviewers.addAll(topic.getParticipants()); result.addAll(topic.getParticipants());
} }
return reviewers;
return result;
} }
/**
* Checks if is owner.
*
* @param name
* the name
* @return true, if is owner
*/
public boolean isOwner(final String name) public boolean isOwner(final String name)
{ {
return this.owner.equalsIgnoreCase(name); return this.owner.equalsIgnoreCase(name);
} }
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override @Override
public String toString() public String toString()
{ {
String result;
final StringBuffer buffer = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
addLine(buffer, '='); addLine(buffer, '=');
addCenter(buffer, "Revue de la semaine en cours"); addCenter(buffer, "Revue de la semaine en cours");
@ -173,59 +243,128 @@ public class Review
addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent() + "\n"); addChunk(buffer, "* " + message.getAuthor() + " : " + message.getContent() + "\n");
} }
return buffer.toString(); result = buffer.toString();
//
return result;
} }
/**
* Adds the.
*
* @param buffer
* the buffer
* @param content
* the content
*/
private static void add(final StringBuffer buffer, final String content) private static void add(final StringBuffer buffer, final String content)
{ {
buffer.append(content); buffer.append(content);
} }
/**
* Adds the center.
*
* @param buffer
* the buffer
* @param content
* the content
*/
private static void addCenter(final StringBuffer buffer, final String content) private static void addCenter(final StringBuffer buffer, final String content)
{ {
addCenter(buffer, content, ' '); addCenter(buffer, content, ' ');
} }
/**
* Adds the center.
*
* @param buffer
* the buffer
* @param content
* the content
* @param c
* the c
*/
private static void addCenter(final StringBuffer buffer, final String content, final char c) private static void addCenter(final StringBuffer buffer, final String content, final char c)
{ {
buffer.append(getLine(content, c)); buffer.append(getLine(content, c));
} }
/**
* Adds the chunk.
*
* @param buffer
* the buffer
* @param content
* the content
*/
private static void addChunk(final StringBuffer buffer, final String content) private static void addChunk(final StringBuffer buffer, final String content)
{ {
add(buffer, chunk(content)); add(buffer, chunk(content));
} }
/**
* Adds the empty.
*
* @param buffer
* the buffer
*/
private static void addEmpty(final StringBuffer buffer) private static void addEmpty(final StringBuffer buffer)
{ {
buffer.append("\n"); buffer.append("\n");
} }
/**
* Adds the line.
*
* @param buffer
* the buffer
* @param c
* the c
*/
private static void addLine(final StringBuffer buffer, final char c) private static void addLine(final StringBuffer buffer, final char c)
{ {
buffer.append(getLine(c)); buffer.append(getLine(c));
} }
/**
* Chunk.
*
* @param content
* the content
* @return the string
*/
private static String chunk(final String content) private static String chunk(final String content)
{ {
return chunk(content, LENGTH); return chunk(content, LENGTH);
} }
/**
* Chunk.
*
* @param content
* the content
* @param length
* the length
* @return the string
*/
private static String chunk(final String content, final int length) private static String chunk(final String content, final int length)
{ {
String result;
final String[] words = content.split(" "); final String[] words = content.split(" ");
final StringBuffer result = new StringBuffer(); final StringBuffer buffer = new StringBuffer();
StringBuffer current = new StringBuffer(); StringBuffer current = new StringBuffer();
for (final String word : words) for (final String word : words)
{ {
if (current.length() + word.length() > length) if (current.length() + word.length() > length)
{ {
if (result.length() > 0) if (buffer.length() > 0)
{ {
result.append("\n"); buffer.append("\n");
} }
result.append(current); buffer.append(current);
current = new StringBuffer(word); current = new StringBuffer(word);
} }
else else
@ -240,29 +379,70 @@ public class Review
if (current.length() > 0) if (current.length() > 0)
{ {
if (result.length() > 0) if (buffer.length() > 0)
{ {
result.append("\n"); buffer.append("\n");
} }
result.append(current); buffer.append(current);
} }
return result.toString(); result = buffer.toString();
//
return result;
} }
private static String getLine(final Character c) /**
* Gets the line.
*
* @param letter
* the letter
* @return the line
*/
private static String getLine(final Character letter)
{ {
return StringUtils.repeat(c.toString(), LENGTH) + "\n"; String result;
result = StringUtils.repeat(letter.toString(), LENGTH) + "\n";
//
return result;
} }
private static String getLine(final String content, final char c) /**
* Gets the line.
*
* @param content
* the content
* @param letter
* the c
* @return the line
*/
private static String getLine(final String content, final char letter)
{ {
return StringUtils.center(" " + content + " ", LENGTH, c) + "\n"; String result;
result = StringUtils.center(" " + content + " ", LENGTH, letter) + "\n";
//
return result;
} }
/**
* Gets the topic.
*
* @param topic
* the topic
* @return the topic
*/
private static String getTopic(final Topic topic) private static String getTopic(final Topic topic)
{ {
return "=== " + topic.getTitle() + " ===\n"; String result;
result = "=== " + topic.getTitle() + " ===\n";
//
return result;
} }
} }

View File

@ -21,19 +21,44 @@ package fr.imirhil.april.hebdobot.review;
import java.util.Set; import java.util.Set;
/**
* The Class Topic.
*/
public abstract class Topic public abstract class Topic
{ {
private final String title; private final String title;
/**
* Instantiates a new topic.
*
* @param title
* the title
*/
protected Topic(final String title) protected Topic(final String title)
{ {
this.title = title; this.title = title;
} }
/**
* Adds the.
*
* @param message
* the message
*/
public abstract void add(Message message); public abstract void add(Message message);
/**
* Gets the participants.
*
* @return the participants
*/
public abstract Set<String> getParticipants(); public abstract Set<String> getParticipants();
/**
* Gets the title.
*
* @return the title
*/
public String getTitle() public String getTitle()
{ {
return this.title; return this.title;

View File

@ -34,10 +34,19 @@ import javax.xml.validation.SchemaFactory;
import org.jibble.pircbot.User; import org.jibble.pircbot.User;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/**
* The Class UserAlias.
*/
public class UserAlias public class UserAlias
{ {
private final Map<String, String> aliases = new HashMap<String, String>(); private final Map<String, String> aliases = new HashMap<String, String>();
/**
* Instantiates a new user alias.
*
* @param source
* the source
*/
public UserAlias(final InputStream source) public UserAlias(final InputStream source)
{ {
try try
@ -55,18 +64,25 @@ public class UserAlias
} }
} }
} }
catch (final SAXException e) catch (final SAXException exception)
{ {
e.printStackTrace(); exception.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(exception);
} }
catch (final JAXBException e) catch (final JAXBException exception)
{ {
e.printStackTrace(); exception.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(exception);
} }
} }
/**
* Gets the real name.
*
* @param nick
* the nick
* @return the real name
*/
public String getRealName(final String nick) public String getRealName(final String nick)
{ {
for (final Entry<String, String> entry : this.aliases.entrySet()) for (final Entry<String, String> entry : this.aliases.entrySet())

View File

@ -38,17 +38,32 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import fr.imirhil.april.hebdobot.review.Review; import fr.imirhil.april.hebdobot.review.Review;
/**
* The Class BotTest.
*/
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/fr/imirhil/april/hebdobot/conf.xml") @ContextConfiguration(locations = "/fr/imirhil/april/hebdobot/conf.xml")
public class BotTest implements ReviewListener public class BotTest implements ReviewListener
{ {
/**
* The Class BotMock.
*/
private static class BotMock extends Bot private static class BotMock extends Bot
{ {
/**
* Instantiates a new bot mock.
*
* @throws Exception
* the exception
*/
public BotMock() throws Exception public BotMock() throws Exception
{ {
super("", 0, "bot", "channel"); super("", 0, "bot", "channel");
} }
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.Bot#onMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
@Override @Override
public void onMessage(final String channel, final String sender, final String login, final String hostname, final String message) public void onMessage(final String channel, final String sender, final String login, final String hostname, final String message)
{ {
@ -56,6 +71,9 @@ public class BotTest implements ReviewListener
} }
} }
/* (non-Javadoc)
* @see fr.imirhil.april.hebdobot.irc.ReviewListener#onEnd(fr.imirhil.april.hebdobot.review.Review)
*/
@Override @Override
public void onEnd(final Review review) public void onEnd(final Review review)
{ {
@ -66,12 +84,18 @@ public class BotTest implements ReviewListener
final File file = new File("target/" + date + "_revue.txt"); final File file = new File("target/" + date + "_revue.txt");
FileUtils.writeStringToFile(file, text); FileUtils.writeStringToFile(file, text);
} }
catch (final IOException e) catch (final IOException exception)
{ {
throw new RuntimeException(e); throw new RuntimeException(exception);
} }
} }
/**
* Redo.
*
* @throws Exception
* the exception
*/
@Test @Test
public void redo() throws Exception public void redo() throws Exception
{ {

View File

@ -21,10 +21,19 @@ package fr.imirhil.april.hebdobot.pastebin;
import org.junit.Test; import org.junit.Test;
/**
* The Class PastebinClientTest.
*/
public class PastebinClientTest public class PastebinClientTest
{ {
private final PastebinClient client = new PastebinClient("b95ea42d539ec9dca02a7da1f5b229c7"); private final PastebinClient client = new PastebinClient("b95ea42d539ec9dca02a7da1f5b229c7");
/**
* Test paste.
*
* @throws Exception
* the exception
*/
@Test @Test
public void testPaste() throws Exception public void testPaste() throws Exception
{ {