de807ff96936a13cb5357986367fab7055b88802
Fenris Wolf 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(),
Fenris Wolf malgranda gxisdatigajxo

Fenris Wolf authored 7 years ago

100) 								"-- uzo: " + ero.kromajxo.uzo_legi(),
Fenris Wolf 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) 						{
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

149) 							// let vojo : string = "kromajxoj/" + nomo + ".js";
150) 							let vojo : string = nomo;
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

151) 							klaso_kromajxo_ekstera.krei
152) 							(
153) 								vojo,
154) 								function (eraro : Error, kromajxo : klaso_kromajxo_ekstera) : void
155) 								{
156) 									if (eraro != null)
157) 									{
158) 										console.warn(eraro);
159) 										if (celo != null) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "aldoni kromajxon fiaskis"));
160) 									}
161) 									else
162) 									{
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

163) 										that.kromajxo_aldoni
164) 										(
165) 											kromajxo,
166) 											undefined,
167) 											undefined,
168) 											function (eraro_ : Error) : void
169) 											{
170) 												if (eraro_ != null)
171) 												{
172) 													console.warn(eraro_);
173) 													if (celo != null) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "aldoni kromajxon fiaskis"));
174) 												}
175) 												else
176) 												{
177) 													if (celo != null) that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "kromajxo sukcese aldonita"));
178) 												}
179) 											}
180) 										);
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

181) 									}
182) 								}
183) 							);
184) 						}
185) 					},
Fenris Wolf malgranda gxisdatigajxo

Fenris Wolf authored 7 years ago

186) 					"elmontri_helpon": function (celo : string) : void
187) 					{
188) 						that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "'!kromajxo listigi': listigi la nomojn de cxiuj kromajxoj kaj elmontri cxu ili estas sxaltitaj"));
189) 						that.eligi(new klaso_evento_eliga_mesagxo(celo, null, "'!kromajxo detaloj [nomo]': elmontri detalojn pri la kromajxo kun la nomo [nomo]"));
190) 					},
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

191) 				}
192) 			)
193) 		);
194) 	}
195) 	
196) 	
197) 	/**
198) 	 * @author fenris
199) 	 */
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

200) 	public kromajxo_aldoni(kromajxo : klaso_kromajxo, aktiva : boolean = true, anstatauxigi : boolean = false, finado : (eraro ?: Error)=>void = vokado_nenio) : void
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

201) 	{
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

202) 		let that : klaso_kliento = this;
203) 		kromajxo.starigi
204) 		(
205) 			function (eraro : Error) : void
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

206) 			{
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

207) 				if (eraro != null)
208) 				{
209) 					finado(eraro);
210) 				}
211) 				else
212) 				{
213) 					let identigilo : string = kromajxo.identigilo_legi();
214) 					if (identigilo in that.kromajxoj)
215) 					{
216) 						if (anstatauxigi && (identigilo != "stirado"))
217) 						{
218) 							let mesagxo : string = ("kromajxo '" + identigilo + "' jam registrita; gxi anstatauxigatos");
219) 							console.warn(mesagxo);
220) 							that.kromajxoj[identigilo] = {"kromajxo": kromajxo, "aktiva": aktiva};
221) 							finado(null);
222) 						}
223) 						else
224) 						{
225) 							let mesagxo : string = ("kromajxo '" + identigilo + "' jam registrita; gxi NE anstatauxigatos");
226) 							finado(new Error(mesagxo));
227) 						}
228) 					}
229) 					else
230) 					{
231) 						that.kromajxoj[identigilo] = {"kromajxo": kromajxo, "aktiva": aktiva};
232) 						finado(null);
233) 					}
234) 				}
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

235) 			}
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

236) 		);