Commits

aeris committed 1231585

Display missing participants on the current topic

  • Participants
  • Parent commits db61dc2

Comments (0)

Files changed (2)

File src/main/java/fr/imirhil/april/hebdobot/irc/Bot.java

 import java.util.Collection;
 import java.util.LinkedList;
 
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
 import org.jibble.pircbot.PircBot;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 				this.handleMessage(sender, message);
 			}
 		}
+		this.handleManquants(sender, message);
 		this.handleComment(sender, message);
 		this.handleDisplayCurrent(sender, message);
 		this.handleHelp(sender, message);
 		this.sendMessage(sender, "— # titre : démarrer un sujet individuel");
 		this.sendMessage(sender, "— ## titre : démarrer un sujet collectif");
 		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");
 	}
 
-	private void handleMessage(final String sender, final String message) {
+	private boolean handleMessage(final String sender, final String message) {
 		if (this.review == null || message.startsWith("%")) {
-			return;
+			return false;
 		}
 		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) {
-			return;
+			return false;
 		}
 		this.review.addRaw(new Message(sender, message));
+		return true;
 	}
 
 	private boolean handleDie(final String sender, final String message) {

File src/main/java/fr/imirhil/april/hebdobot/review/Review.java

 package fr.imirhil.april.hebdobot.review;
 
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 		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;
+	}
+
 }