* /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" : {
+ 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, ''];
+ }
+ }
+};
+
/**
* Execute une commande.
* @return [statut, message], 'message' n'est utilisé que pour le statut 'erreur_commande'.
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, ''];
}
- var commande = fragments[0].slice(1);
+ var nomCommande = fragments[0].slice(1);
var args = fragments.slice(1);
- switch (commande) {
- case "" : return [euphorik.Commandes.statut.erreur_commande, 'La commande est vide'];
- case "nick" : return this.commandeNick(args);
+ if (nomCommande === "") {
+ return [euphorik.Commandes.statut.erreur_commande, 'La commande est vide'];
}
-
- 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>"'];
+ // 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, ''];
}
- this.client.pseudo = args[0];
- $("form#posterMessage input.pseudo").val(this.client.pseudo);
+ if (euphorik.Commandes.liste.hasOwnProperty(nomCommande)) {
+ return euphorik.Commandes.liste[nomCommande].exec(args, this.client, this.pageMinichat);
+ }
- return [euphorik.Commandes.statut.ok, ''];
+ return [euphorik.Commandes.statut.erreur_commande, 'La commande /' + nomCommande + ' est inconnue'];
};