Display missing participants on the current topic

This commit is contained in:
Nicolas Vinot 2013-01-27 12:16:19 +01:00
parent db61dc2390
commit ad5445be52
3 changed files with 52 additions and 5 deletions

View File

@ -141,7 +141,6 @@
<groupId>commons-collections</groupId> <groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId> <artifactId>commons-collections</artifactId>
<version>3.2.1</version> <version>3.2.1</version>
<scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>

View File

@ -3,6 +3,8 @@ package fr.imirhil.april.hebdobot.irc;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.jibble.pircbot.PircBot; import org.jibble.pircbot.PircBot;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -66,6 +68,7 @@ public class Bot extends PircBot {
this.handleMessage(sender, message); this.handleMessage(sender, message);
} }
} }
this.handleManquants(sender, message);
this.handleComment(sender, message); this.handleComment(sender, message);
this.handleDisplayCurrent(sender, message); this.handleDisplayCurrent(sender, message);
this.handleHelp(sender, message); this.handleHelp(sender, message);
@ -86,21 +89,54 @@ public class Bot extends PircBot {
this.sendMessage(sender, "— # titre : démarrer un sujet individuel"); this.sendMessage(sender, "— # titre : démarrer un sujet individuel");
this.sendMessage(sender, "— ## titre : démarrer un sujet collectif"); this.sendMessage(sender, "— ## titre : démarrer un sujet collectif");
this.sendMessage(sender, "— !courant : affiche le sujet en cours"); this.sendMessage(sender, "— !courant : affiche le sujet en cours");
this.sendMessage(
sender,
"— !manquants : affiche les participants qui n'ont pas répondu sur le dernier sujet");
this.sendMessage(sender, "— % message : un commentaire"); this.sendMessage(sender, "— % message : un commentaire");
} }
private void handleMessage(final String sender, final String message) { private boolean handleMessage(final String sender, final String message) {
if (this.review == null || message.startsWith("%")) { if (this.review == null || message.startsWith("%")) {
return; return false;
} }
this.review.add(new Message(sender, message)); this.review.add(new Message(sender, message));
return true;
} }
private void handleComment(final String sender, final String message) { private boolean handleManquants(final String sender, final String message) {
if (this.review == null || !"!manquants".equalsIgnoreCase(message)) {
return false;
}
final Topic topic = this.review.getCurrentTopic();
if (topic == null) {
this.sendMessage("Aucun sujet traité");
return true;
}
final Collection<String> participants = this.review.getParticipants();
final Collection<String> currentParticipants = topic.getParticipants();
@SuppressWarnings("unchecked")
final Collection<String> missing =
CollectionUtils.subtract(participants, currentParticipants);
if (missing.isEmpty()) {
this.sendMessage("Aucun participant manquant \\o/");
return true;
}
this.sendMessage(String.format(
"Les participants suivants sont manquants : %1s",
StringUtils.join(missing, ", ")));
return true;
}
private boolean handleComment(final String sender, final String message) {
if (this.review == null) { if (this.review == null) {
return; return false;
} }
this.review.addRaw(new Message(sender, message)); this.review.addRaw(new Message(sender, message));
return true;
} }
private boolean handleDie(final String sender, final String message) { private boolean handleDie(final String sender, final String message) {

View File

@ -1,5 +1,6 @@
package fr.imirhil.april.hebdobot.review; package fr.imirhil.april.hebdobot.review;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -200,4 +201,15 @@ public class Review {
add(buffer, chunk(content)); add(buffer, chunk(content));
} }
public Collection<String> getParticipants() {
final Collection<String> reviewers = new HashSet<String>();
for (final Topic topic : this.individualTopics) {
reviewers.addAll(topic.getParticipants());
}
for (final Topic topic : this.collectiveTopics) {
reviewers.addAll(topic.getParticipants());
}
return reviewers;
}
} }