27639b0c32642647434b376a4c829511e802e032
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) declare var process;
22) 
23) 
24) /**
25)  * @author fenris
26)  */
Fenris Wolf pli bona apartigado inter f...

Fenris Wolf authored 7 years ago

27) function cxefajxo(argumentoj : Array<string>) : void
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

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

Fenris Wolf authored 7 years ago

29) 	function malkonfesado() : void
30) 	{
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

31) 		console.info("Kvasir  Copyright (C) 2016  Fenris Wolf");
32) 		console.info("This program comes with ABSOLUTELY NO WARRANTY.");
33) 		console.info("This is free software, and you are welcome to redistribute it");
34) 		console.info("under certain conditions.");
35) 	}
36) 	
37) 	function sekurigi() : void
38) 	{
39) 		process.on
40) 		(
41) 			"uncaughtException",
42) 			function (event : Event) : void
43) 			{
44) 				console.warn("malloka escepto: ", event);
45) 			}
46) 		);
47) 	}
48) 	
49) 	function lancxi(agordoj : Object, fino : ()=>void = function () {}) : void
50) 	{
51) 		let kliento : klaso_kliento = new klaso_kliento_irc(agordoj, agordoj["prokrasto"]);
52) 		kliento.stirado_arangxi(agordoj["administrantoj"]);
53) 		vokado_atendi
54) 		(
55) 			agordoj["kromajxoj"].map
56) 			(
57) 				function (ero : Object) : (preta : ()=>void)=>void
58) 				{
59) 					return (
60) 						function (preta : ()=>void) : void
61) 						{
62) 							console.log("-- sxarganta na '" + ero["vojo"] + "' ...");
63) 							klaso_kromajxo_ekstera.krei
64) 							(
65) 								ero["vojo"],
66) 								function (eraro : Error, kromajxo : klaso_kromajxo_ekstera) : void
67) 								{
68) 									if (eraro != null)
69) 									{
70) 										console.warn(eraro);
71) 									}
72) 									else
73) 									{
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

74) 										kliento.kromajxo_aldoni
75) 										(
76) 											kromajxo,
77) 											ero["aktiva"],
78) 											undefined,
79) 											function (eraro : Error) : void
80) 											{
81) 												if (eraro != null)
82)  												{
Fenris Wolf pli bona laborado inter kli...

Fenris Wolf authored 7 years ago

83)  													throw (new Error("-- la kromajxo '" + ero["vojo"] + "' ne sxargeblas: " + String(eraro)));
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

84) 												}
85) 												else
86) 												{
87) 													preta();
88) 												}
89) 											}
90) 										);
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

91) 									}
Fenris Wolf malgranda gxisdatigajxo

Fenris Wolf authored 7 years ago

92) 									// console.log("-- ... preta");
Fenris Wolf 'starigi'-metodo por kromaj...

Fenris Wolf authored 7 years ago

93) 									// preta();
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

94) 								}
95) 							);
96) 						}
97) 					);
98) 				}
99) 			),
100) 			function () : void
101) 			{
102) 				console.log("-- konektanta ...");
103) 				kliento.konekti
104) 				(
105) 					{},
106) 					function () : void
107) 					{
108) 						console.log("-- konektita");
109) 						agordoj["auxtolancxo"].forEach(x => kliento.enigi(new klaso_evento_eniga_mesagxo(null, null, x)));
110) 						fino();
111) 					}
112) 				);
113) 			}
114) 		);
115) 	}
116) 	
117) 	function agordoj_legi(vojo : string, uzado : (agordoj : Object)=>void) : void
118) 	{
119) 		_fs.readFile
120) 		(
121) 			vojo,
122) 			{"encoding": "utf8", "flag": "r"},
123) 			function (eraro : any, enhavo : string) : void
124) 			{
125) 				if (eraro != undefined)
126) 				{
127) 					throw (new Error("agordoj ne enlegeblas: " + eraro.toString()));
128) 				}
129) 				else
130) 				{
131) 					let agordoj : Object;
132) 					try
133) 					{
134) 						agordoj = JSON.parse(enhavo);
135) 					}
136) 					catch (escpto)
137) 					{
138) 						throw (new Error("agordoj ne enlegeblas: " + escpto.toString()));
139) 						agordoj = null;
140) 					}
141) 					if (agordoj != null)
142) 					{
143) 						uzado(agordoj);
144) 					}
145) 				}
146) 			}
147) 		);
148) 	}
149) 	
Fenris Wolf sxangxetoj por publikigado

Fenris Wolf authored 7 years ago

150) 	// console.error(argumentoj);
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

151) 	malkonfesado();
152) 	sekurigi();
Fenris Wolf trancxado

Fenris Wolf authored 7 years ago

153) 	let vojo : string = ((argumentoj.length > 0) ? argumentoj.shift() : "agordoj.json");
154) 	agordoj_legi(vojo, agordoj => lancxi(agordoj));
Fenris Wolf unua enmetajxo

Fenris Wolf authored 7 years ago

155) }
156) 
Fenris Wolf pli bona apartigado inter f...

Fenris Wolf authored 7 years ago

157) cxefajxo(process.argv.slice(2));