REPORT de la branche 1.1 (459->476)
[euphorik.git] / js / pageMinichat / commandes.js
index a044617..014b9bb 100644 (file)
   *  /nick <nouveau nick>
   *  Modifie le pseudo courant
   */
-euphorik.Commandes = function(client) {
+euphorik.Commandes = function(client, pageMinichat, util, formateur) {
+   var thisCommandes = this;
+
    this.client = client;
+   this.pageMinichat = pageMinichat;
+   this.util = util;
+   this.formateur = formateur;
+   
+   // construction du texte d'aide (liste des commandes) de manière statique
+   this.texteAide = "<div id=\"aideCommandes\"><h1>Commandes</h1><ul>";
+   objectEach(
+      euphorik.Commandes.liste,
+      function(nom, commande) {
+         thisCommandes.texteAide += "<li><span class=\"usage\">" + thisCommandes.formateur.traitementComplet(commande.usage) + "</span> : " + thisCommandes.formateur.traitementComplet(commande.description) + "</li>";
+      }
+   );
+   this.texteAide += "</ul></div>";
 };
 
 euphorik.Commandes.statut = {ok : 0, pas_une_commande : 1, erreur_commande : 2};
 
 euphorik.Commandes.liste = {
    "nick" : {
-      usage :
+      description : "Change le pseudo courant",
+      usage : "/nick <nouveau pseudo>",
+      exec : function(args, client) {
+         
+         if (args.length === 0) {
+            return [euphorik.Commandes.statut.erreur_commande, 'Utilisation de la commande : ' + this.usage];
+         }
+   
+         client.pseudo = args[0];
+         $("form#posterMessage input.pseudo").val(client.pseudo);
+   
+         return [euphorik.Commandes.statut.ok, ''];
+      }
+   },
+   "cpf" : {
+      description : "Envoie le message \"C'est pas faux\"",
+      usage : "/cpf",
+      exec : function(args, client, pageMinichat) {
+         pageMinichat.envoyerMessage("C'est pas faux");
+         return [euphorik.Commandes.statut.ok, ''];
+      }
+   }
 };
 
 /**
@@ -45,7 +81,7 @@ euphorik.Commandes.liste = {
 euphorik.Commandes.prototype.exec = function(chaine) {
    chaine = chaine.trim();
    
-   var fragments = chaine.split(/\s*/);
+   var fragments = chaine.split(/\s+/);
    if (fragments.length === 0 || fragments[0].charAt(0) != '/') {
       return [euphorik.Commandes.statut.pas_une_commande, ''];
    }
@@ -56,27 +92,21 @@ euphorik.Commandes.prototype.exec = function(chaine) {
    if (nomCommande === "") {
       return [euphorik.Commandes.statut.erreur_commande, 'La commande est vide'];
    }
-   
-   if (euphorik.Commandes.liste.hasOwnProperty(commande) {
-      var commande = 
-      return this.commandeNick(args);
+   // commandes spéciales pour afficher l'aide : "?", "h", "help", "aide"
+   if (nomCommande === "?" || nomCommande === "h" || nomCommande === "help" || nomCommande === "aide") {
+      this.util.messageDialogue(
+         this.texteAide,
+         euphorik.Util.messageType.informatif,
+         {"fermer" : function(){}},
+         false,
+         -1
+      );
+      return [euphorik.Commandes.statut.ok, ''];
    }
    
-   switch (commande) {
-      case "" : 
-      case "nick" : 
+   if (euphorik.Commandes.liste.hasOwnProperty(nomCommande)) {
+      return euphorik.Commandes.liste[nomCommande].exec(args, this.client, this.pageMinichat);
    }
    
-   return [euphorik.Commandes.statut.erreur_commande, 'La commande \\' + commande + ' est inconnue'];
-};
-
-euphorik.Commandes.prototype.commandeNick = function(args) {
-   if (args.length === 0) {
-      return [euphorik.Commandes.statut.erreur_commande, 'Utilisation de la commande : "\nick <nouveau pseudo>"'];
-   }
-   
-   this.client.pseudo = args[0];
-   $("form#posterMessage input.pseudo").val(this.client.pseudo);
-   
-   return [euphorik.Commandes.statut.ok, ''];
+   return [euphorik.Commandes.statut.erreur_commande, 'La commande /' + nomCommande + ' est inconnue'];
 };