X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=js%2FpageMinichat%2Fcommandes.js;fp=js%2FpageMinichat%2Fcommandes.js;h=0a2c38ef5f86a2b51f5137c2161946f03b2bf7da;hb=7e471788d9356b1cb8659513674df9a883101807;hp=0000000000000000000000000000000000000000;hpb=75e69b9fa74954d55acaa5f342579524c3397cb4;p=euphorik.git diff --git a/js/pageMinichat/commandes.js b/js/pageMinichat/commandes.js new file mode 100644 index 0000000..0a2c38e --- /dev/null +++ b/js/pageMinichat/commandes.js @@ -0,0 +1,68 @@ +// coding: utf-8 +// Copyright 2008 Grégory Burri +// +// This file is part of Euphorik. +// +// Euphorik is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Euphorik is distributed in the hope that it will be useful, +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Euphorik. If not, see . + + /*jslint laxbreak:true */ + +/** + * Permet d'executer des commandes tapées par l'utilisateur. + * les commandes sont entrées directement dans la ligne de saisie du message sous la forme : + * / + * + * Voici les commandes supportées : + * /nick + * Modifie le pseudo courant + */ +euphorik.Commandes = function(client) { + this.client = client; +}; + +euphorik.Commandes.statut = {ok : 0, pas_une_commande : 1, erreur_commande : 2}; + +/** + * 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*/); + if (fragments.length === 0 || fragments[0].charAt(0) != '/') { + return [euphorik.Commandes.statut.pas_une_commande, '']; + } + + var commande = 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); + } + + 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 "']; + } + + this.client.pseudo = args[0]; + $("form#posterMessage input.pseudo").val(this.client.pseudo); + + return [euphorik.Commandes.statut.ok, '']; +};