a0446177031947b59c313597f75f611b6cc6e5c0
[euphorik.git] / js / pageMinichat / commandes.js
1 // coding: utf-8
2 // Copyright 2008 Grégory Burri
3 //
4 // This file is part of Euphorik.
5 //
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.
10 //
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.
15 //
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/>.
18
19 /*jslint laxbreak:true */
20
21 /**
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>
25 *
26 * Voici les commandes supportées :
27 * /nick <nouveau nick>
28 * Modifie le pseudo courant
29 */
30 euphorik.Commandes = function(client) {
31 this.client = client;
32 };
33
34 euphorik.Commandes.statut = {ok : 0, pas_une_commande : 1, erreur_commande : 2};
35
36 euphorik.Commandes.liste = {
37 "nick" : {
38 usage :
39 };
40
41 /**
42 * Execute une commande.
43 * @return [statut, message], 'message' n'est utilisé que pour le statut 'erreur_commande'.
44 */
45 euphorik.Commandes.prototype.exec = function(chaine) {
46 chaine = chaine.trim();
47
48 var fragments = chaine.split(/\s*/);
49 if (fragments.length === 0 || fragments[0].charAt(0) != '/') {
50 return [euphorik.Commandes.statut.pas_une_commande, ''];
51 }
52
53 var nomCommande = fragments[0].slice(1);
54 var args = fragments.slice(1);
55
56 if (nomCommande === "") {
57 return [euphorik.Commandes.statut.erreur_commande, 'La commande est vide'];
58 }
59
60 if (euphorik.Commandes.liste.hasOwnProperty(commande) {
61 var commande =
62 return this.commandeNick(args);
63 }
64
65 switch (commande) {
66 case "" :
67 case "nick" :
68 }
69
70 return [euphorik.Commandes.statut.erreur_commande, 'La commande \\' + commande + ' est inconnue'];
71 };
72
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>"'];
76 }
77
78 this.client.pseudo = args[0];
79 $("form#posterMessage input.pseudo").val(this.client.pseudo);
80
81 return [euphorik.Commandes.statut.ok, ''];
82 };