d243fe85eabfbfee1b093fa6ea3069f48575aaaa
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) var _fs = require("fs");
22) 
23) 	
24) /**
25)  * @author fenris
26)  */
27) class klaso_kromajxo_ekstera extends klaso_kromajxo
28) {
29) 	
30) 	/**
31) 	 * @author fenris
32) 	 */
33) 	protected vojo : string;
34) 	
35) 	
36) 	/**
37) 	 * @author fenris
38) 	 */
39) 	protected memoro : Object;
40) 	
41) 	
42) 	/**
43) 	 * @author fenris
44) 	 */
45) 	protected reagi_ : (enigo_kruda : Object, eligi : (eligo_kruda : Object)=>void, memoro ?: Object)=>void;
46) 	
47) 	
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

48) 	/**
49) 	 * @author fenris
50) 	 */
51) 	protected starigi_ : (finado : (eraro ?: Error)=>void, memoro ?: Object)=>void;
52) 	
53) 	
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

54) 	/**
55) 	 * @author fenris
56) 	 */
57) 	public constructor
58) 	(
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

59) 		datumoj :
60) 		{
61) 			identigilo ?: string;
62) 			nomo ?: string;
63) 			priskribo ?: string;
64) 			uzo ?: string;
65) 			auxtoro ?: string;
66) 			starigi ?: (finado : (eraro ?: Error)=>void, memoro ?: Object)=>void;
67) 			reagi ?: (enigo_kruda : Object, eligi : (eligo_kruda : Object)=>void)=>void;
68) 			vojo ?: string;
69) 		}
70) 		= {}
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

71) 	)
72) 	{
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

73) 		super(datumoj);
74) 		this.meti_valorojn_(datumoj, false);
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

75) 		this.memoro = {};
76) 	}
77) 	
78) 	
79) 	/**
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

80) 	 * @override
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

81) 	 * @author fenris
82) 	 */
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

83) 	public meti_valorojn_(datumoj : Object, ankaux_supraj : boolean = false) : void
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

84) 	{
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

85) 		if (ankaux_supraj) this.meti_valorojn(datumoj);
86) 		this.vojo = alporti(datumoj, "vojo", null, 1);
87) 		this.starigi_ = alporti<(finado : (eraro ?: Error)=>void, memoro ?: Object)=>void>(datumoj, "starigi", (finado => finado(null)), 0);
88) 		this.reagi_ = alporti<(enigo_kruda : Object, eligi : (eligo_kruda : Object)=>void)=>void>(datumoj, "reagi", null, 1);
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

89) 	}
90) 	
91) 	
92) 	/**
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

93) 	 * @override
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

94) 	 * @author fenris
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

95) 	 */
96) 	public starigi(finado : (eraro ?: Error)=>void) : void
97) 	{
98) 		this.starigi_(finado, this.memoro);
99) 	}
100) 	
101) 	
102) 	/**
103) 	 * @override
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

104) 	 * @author fenris
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

105) 	 */
106) 	protected reagi(enigo_kruda : Object, eligi : (eligo_kruda : Object)=>void) : void
107) 	{
108) 		this.reagi_(enigo_kruda, eligi, this.memoro);
109) 	}
110) 	
111) 
112) 	/**
113) 	 * @author fenris
114) 	 */
115) 	protected static sxargi(vojo : string, uzado : (eraro : Error, datumoj : Object)=>void) : void
116) 	{
117) 		_fs.readFile
118) 		(
119) 			vojo,
120) 			{"encoding": "utf8", "flag": "r"},
121) 			function (eraro : Error, enhavo : string) : void
122) 			{
123) 				if (eraro != null)
124) 				{
125) 					uzado(eraro, null);
126) 				}
127) 				else
128) 				{
129) 					try
130) 					{
131) 						let datumoj : Object = eval("(function () {return (" + enhavo + ");})()");
132) 						uzado(null, datumoj);
133) 					}
134) 					catch (escepto)
135) 					{
136) 						uzado(new Error(String(escepto)), null);
137) 					}
138) 				}
139) 			}
140) 		);
141) 	}
142) 	
143) 	
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

144) 	/**
145) 	 * @author fenris
146) 	 */
147) 	public resxargi(fino : (eraro : Error)=>void = (eraro => {})) : void
148) 	{
149) 		let that : klaso_kromajxo_ekstera = this;
150) 		klaso_kromajxo_ekstera.sxargi
151) 		(
152) 			this.vojo,
153) 			function (eraro : Error, datumoj : Object) : void
154) 			{
155) 				if (eraro != null)
156) 				{
157) 					fino(eraro);
158) 				}
159) 				else
160) 				{
161) 					datumoj["vojo"] = that.vojo;
162) 					that.meti_valorojn_(datumoj, true);
163) 					that.starigi
164) 					(
165) 						function (eraro_ : Error) : void
166) 						{
167) 							if (eraro_ != null)
168) 							{
169) 								fino(eraro_);
170) 							}
171) 							else
172) 							{
173) 								fino(null);
174) 							}
175) 						}
176) 					);
177) 				}
178) 			}
179) 		);
180) 	}
181) 	
182) 	
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

183) 	/**
184) 	 * @author fenris
185) 	 */
186) 	public static krei(vojo : string, uzado : (eraro : Error, kromajxo : klaso_kromajxo_ekstera)=>void) : void
187) 	{
188) 		klaso_kromajxo_ekstera.sxargi
189) 		(
190) 			vojo,
191) 			function (eraro : Error, datumoj : Object) : void
192) 			{
193) 				if (eraro != null)
194) 				{
195) 					uzado(eraro, null);
196) 				}
197) 				else
198) 				{
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

199) 					datumoj["vojo"] = vojo;
200) 					let kromajxo : klaso_kromajxo_ekstera = new klaso_kromajxo_ekstera(datumoj);