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};
36 euphorik
.Commandes
.liste
= {
42 * Execute une commande.
43 * @return [statut, message], 'message' n'est utilisé que pour le statut 'erreur_commande'.
45 euphorik
.Commandes
.prototype.exec = function(chaine
) {
46 chaine
= chaine
.trim();
48 var fragments
= chaine
.split(/\s*/);
49 if (fragments
.length
=== 0 || fragments
[0].charAt(0) != '/') {
50 return [euphorik
.Commandes
.statut
.pas_une_commande
, ''];
53 var nomCommande
= fragments
[0].slice(1);
54 var args
= fragments
.slice(1);
56 if (nomCommande
=== "") {
57 return [euphorik
.Commandes
.statut
.erreur_commande
, 'La commande est vide'];
60 if (euphorik
.Commandes
.liste
.hasOwnProperty(commande
) {
62 return this.commandeNick(args
);
70 return [euphorik
.Commandes
.statut
.erreur_commande
, 'La commande \\' + commande
+ ' est inconnue'];
73 euphorik
.Commandes
.prototype.commandeNick = function(args
) {
74 if (args
.length
=== 0) {
75 return [euphorik
.Commandes
.statut
.erreur_commande
, 'Utilisation de la commande : "\nick <nouveau pseudo>"'];
78 this.client
.pseudo
= args
[0];
79 $("form#posterMessage input.pseudo").val(this.client
.pseudo
);
81 return [euphorik
.Commandes
.statut
.ok
, ''];