0a2c38ef5f86a2b51f5137c2161946f03b2bf7da
2 // Copyright 2008 Grégory Burri
4 // This file is part of Euphorik.
6 // Euphorik is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // Euphorik is distributed in the hope that it will be useful,
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
19 /*jslint laxbreak:true */
22 * Permet d'executer des commandes tapées par l'utilisateur.
23 * les commandes sont entrées directement dans la ligne de saisie du message sous la forme :
24 * /<commande> <paramètres>
26 * Voici les commandes supportées :
27 * /nick <nouveau nick>
28 * Modifie le pseudo courant
30 euphorik
.Commandes = function(client
) {
34 euphorik
.Commandes
.statut
= {ok : 0, pas_une_commande : 1, erreur_commande : 2};
37 * Execute une commande.
38 * @return [statut, message], 'message' n'est utilisé que pour le statut 'erreur_commande'.
40 euphorik
.Commandes
.prototype.exec = function(chaine
) {
41 chaine
= chaine
.trim();
43 var fragments
= chaine
.split(/\s*/);
44 if (fragments
.length
=== 0 || fragments
[0].charAt(0) != '/') {
45 return [euphorik
.Commandes
.statut
.pas_une_commande
, ''];
48 var commande
= fragments
[0].slice(1);
49 var args
= fragments
.slice(1);
52 case "" : return [euphorik
.Commandes
.statut
.erreur_commande
, 'La commande est vide'];
53 case "nick" : return this.commandeNick(args
);
56 return [euphorik
.Commandes
.statut
.erreur_commande
, 'La commande \\' + commande
+ ' est inconnue'];
59 euphorik
.Commandes
.prototype.commandeNick = function(args
) {
60 if (args
.length
=== 0) {
61 return [euphorik
.Commandes
.statut
.erreur_commande
, 'Utilisation de la commande : "\nick <nouveau pseudo>"'];
64 this.client
.pseudo
= args
[0];
65 $("form#posterMessage input.pseudo").val(this.client
.pseudo
);
67 return [euphorik
.Commandes
.statut
.ok
, ''];