unua enmetajxo
Fenris Wolf authored 7 years ago
|
1) /*
2)
3) IRC-Bot "Kvasir"
4) Copyright (C) 2016 Fenris Wolf (fenris@folksprak.org)
5)
6) This program 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) This program is distributed in the hope that it will be useful,
12) but WITHOUT ANY WARRANTY; without even the implied warranty of
13) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 this program. If not, see <http://www.gnu.org/licenses/>.
18)
19) */
20)
21) type tipo_ero = {kromajxo : klaso_kromajxo; aktiva : boolean;};
22)
23)
24) /**
25) * @author fenris
26) */
27) abstract class klaso_kliento
28) {
29)
30) /**
31) * @author fenris
32) */
33) protected kromajxoj : {[identigilo : string] : tipo_ero};
34)
35)
36) /**
37) * @author fenris
38) */
39) protected vico_eliga : klaso_vico<klaso_evento_eliga>;
40)
41)
42) /**
43) * @author fenris
44) */
45) protected prokrasto : int;
46)
47)
48) /**
49) * @author fenris
50) */
51) protected foo : any;
52)
53)
54) /**
55) * @author fenris
56) */
57) public constructor(prokrasto : int = null)
58) {
59) this.kromajxoj = {};
60) this.vico_eliga = new klaso_vico<klaso_evento_eliga>();
61) this.foo = null;
62) this.prokrasto = prokrasto;
63) }
64)
65)
66) /**
67) * @author fenris
68) */
69) public stirado_arangxi
70) (
71) permesuloj : Array<string> = []
72) )
73) {
74) let that : klaso_kliento = this;
75) this.kromajxo_aldoni
76) (
77) new klaso_kromajxo_stirado
78) (
79) permesuloj,
80) {
81) "anigxi": function (kanalo : string, modo : boolean = true) : void
82) {
83) that.anigxi_rekte(kanalo, modo);
84) },
85) "listigi": function (celo : string) : void
86) {
87) let enhavo : string = Object.keys(that.kromajxoj).map(identigilo => (that.kromajxoj[identigilo].aktiva ? "+" : "-") + identigilo).join(", ");
88) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, enhavo));
89) },
90) "detaloj": function (identigilo : string, celo : string) : void
91) {
92) if (identigilo in that.kromajxoj)
93) {
94) let ero : tipo_ero = that.kromajxoj[identigilo];
95) let enhavoj : Array<string> =
96) [
97) "-- nomo: " + ero.kromajxo.nomo_legi(),
98) "-- auxtoro: " + ero.kromajxo.auxtoro_legi(),
99) "-- priskribo: " + ero.kromajxo.priskribo_legi(),
|
unua enmetajxo
Fenris Wolf authored 7 years ago
|
101) "-- aktiva: " + (ero.aktiva ? "jes" : "ne"),
102) ];
103) enhavoj.forEach(enhavo => that.eligi(new klaso_evento_eliga_mesagxo(celo, null, enhavo)));
104) }
105) },
106) "sxalti": function (identigilo : string, aktiva : boolean = null, celo : string = null) : void
107) {
108) if (identigilo in that.kromajxoj)
109) {
110) if (identigilo != "stirado")
111) {
112) let aktiva_ : boolean = (aktiva != null) ? aktiva : (! that.kromajxoj[identigilo].aktiva);
113) that.kromajxoj[identigilo].aktiva = aktiva_;
114) if (celo != null) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "kromajxo '" + identigilo + "' " + (aktiva_ ? "aktivigita" : "malaktivigita") + ""));
115) }
116) else
117) {
118) if (celo != null) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "vi ne vere volas sxalti la stirad-kromajxon ..."));
119) }
120) }
121) },
122) "resxargi": function (identigilo : string, celo : string = null) : void
123) {
124) let ero : tipo_ero = that.kromajxoj[identigilo];
125) if (ero.kromajxo instanceof klaso_kromajxo_ekstera)
126) {
127) let kromajxo : klaso_kromajxo_ekstera = <klaso_kromajxo_ekstera>(ero.kromajxo);
128) kromajxo.resxargi
129) (
130) function (eraro : Error) : void
131) {
132) if (eraro != null)
133) {
134) console.warn(eraro);
135) if (celo != null) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "resxargado fiaskis; detaloj trovigxas je la konzolo"));
136) }
137) else
138) {
139) if (celo != null) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "kromajxo '" + identigilo + "' resxargita"));
140) }
141) }
142) );
143) }
144) },
145) "aldoni": function (nomo : string, celo : string= null) : void
146) {
147) if ((new RegExp("\\w")).test(nomo))
148) {
149) let vojo : string = "fontoj/kromajxoj/kromajxo_" + nomo + ".js";
150) klaso_kromajxo_ekstera.krei
151) (
152) vojo,
153) function (eraro : Error, kromajxo : klaso_kromajxo_ekstera) : void
154) {
155) if (eraro != null)
156) {
157) console.warn(eraro);
158) if (celo != null) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "aldoni kromajxon fiaskis"));
159) }
160) else
161) {
162) that.kromajxo_aldoni(kromajxo);
163) if (celo != null) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "kromajxo sukcese aldonita"));
164) }
165) }
166) );
167) }
168) },
|
malgranda gxisdatigajxo
Fenris Wolf authored 7 years ago
|
169) "elmontri_helpon": function (celo : string) : void
170) {
171) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "'!kromajxo listigi': listigi la nomojn de cxiuj kromajxoj kaj elmontri cxu ili estas sxaltitaj"));
172) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "'!kromajxo detaloj [nomo]': elmontri detalojn pri la kromajxo kun la nomo [nomo]"));
173) },
|