Browse Source

fix: +help

Martin Passard 7 years ago
parent
commit
0edf65a173
3 changed files with 20 additions and 8 deletions
  1. 2 1
      src/actions/Action.java
  2. 18 6
      src/actions/Help.java
  3. 0 1
      src/main/Bot.java

+ 2 - 1
src/actions/Action.java

@@ -11,6 +11,7 @@ public abstract class Action {
 
 
 	public List<String> keyWords;
 	public List<String> keyWords;
 	public PircBot bot;
 	public PircBot bot;
+	public static char CARACTERE_COMMANDE = '+';
 	
 	
 	protected Action(Bot b, List<String> keywords) {
 	protected Action(Bot b, List<String> keywords) {
 		this.keyWords = keywords;
 		this.keyWords = keywords;
@@ -49,7 +50,7 @@ public abstract class Action {
 	 * @return true si l'action contenue doit être executée, false sinon.
 	 * @return true si l'action contenue doit être executée, false sinon.
 	 */
 	 */
 	public boolean hasToReact(String s) {
 	public boolean hasToReact(String s) {
-		if(s.charAt(0)!=Bot.CARACTERE_COMMANDE) {
+		if(s.charAt(0)!=CARACTERE_COMMANDE) {
 			return false;								// On ne réagit pas si ce n'est pas une commande. Cela évite la suite du traitement.
 			return false;								// On ne réagit pas si ce n'est pas une commande. Cela évite la suite du traitement.
 		}
 		}
 		s=s.substring(1); // on enleve le caractère de commande
 		s=s.substring(1); // on enleve le caractère de commande

+ 18 - 6
src/actions/Help.java

@@ -18,15 +18,17 @@ public class Help extends Action {
 	@Override
 	@Override
 	public void react(String channel, String sender, String login, String hostname, String message) {
 	public void react(String channel, String sender, String login, String hostname, String message) {
 		List<Action> l = Action.getAllActions((Bot) bot);
 		List<Action> l = Action.getAllActions((Bot) bot);
-		String commande = message.substring(message.indexOf(' ')+1);
-		if(commande.indexOf(' ') != -1) {
-			commande = commande.substring(0,commande.indexOf(' '));
-		}
 			boolean hasreacted = false;
 			boolean hasreacted = false;
-			if(commande.equals("help")) {
+			String commandeSansEspaces = message.replaceAll("\\s", "").substring(1); // On enleve les espaces et le +
+			if(commandeSansEspaces.toLowerCase().equals("help")) {
 				bot.sendMessage(channel, help());
 				bot.sendMessage(channel, help());
+				afficheListeCommandes(l, channel);
 				hasreacted = true;
 				hasreacted = true;
 			}else {
 			}else {
+				String commande = message.substring(message.indexOf(' ')+1);
+				if(commande.indexOf(' ') != -1) {
+					commande = commande.substring(0,commande.indexOf(' '));
+				}
 				for(Action a : l) {
 				for(Action a : l) {
 					if(a.keyWords.contains(commande) && hasreacted == false) {
 					if(a.keyWords.contains(commande) && hasreacted == false) {
 						String msg = "";
 						String msg = "";
@@ -42,11 +44,21 @@ public class Help extends Action {
 			
 			
 			// Si il n'as pas encore réagi
 			// Si il n'as pas encore réagi
 			if(!hasreacted) {
 			if(!hasreacted) {
-				bot.sendMessage(channel, "commande inconnue");
+				bot.sendMessage(channel, "Commande inconnue.");
+				afficheListeCommandes(l, channel);
 			}
 			}
 
 
 	}
 	}
+	
+	private void afficheListeCommandes(List<Action> l, String channel) {
+		String listeCommandes="Voici la liste des commandes: ";
+		for(Action a : l) {
+			listeCommandes += CARACTERE_COMMANDE+a.keyWords.get(0)+" ";
+		}
+		bot.sendMessage(channel, listeCommandes);
+	}
 
 
+	
 	@Override
 	@Override
 	public String help() {
 	public String help() {
 		return "Utilisez +help <commande> Pour avoir les informations sur une commande.";
 		return "Utilisez +help <commande> Pour avoir les informations sur une commande.";

+ 0 - 1
src/main/Bot.java

@@ -9,7 +9,6 @@ import actions.Action;
 public class Bot extends PircBot {
 public class Bot extends PircBot {
 
 
 	public static final long TIME_BETWEEN_MESSAGES = 200;
 	public static final long TIME_BETWEEN_MESSAGES = 200;
-	public static char CARACTERE_COMMANDE = '+';
 	private List<Action> actions = Action.getAllActions(this);
 	private List<Action> actions = Action.getAllActions(this);
 
 
 	public Bot() {
 	public Bot() {