/* IRC-Bot "Kvasir" Copyright (C) 2016 Fenris Wolf (fenris@folksprak.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /** * @author fenris */ abstract class klaso_kromajxo { /** * @author fenris */ protected identigilo : string; /** * @author fenris */ protected nomo : string; /** * @author fenris */ protected priskribo : string; /** * @author fenris */ protected uzo : string; /** * @author fenris */ protected auxtoro : string; /** * @author fenris */ public constructor ( datumoj : { identigilo ?: string; nomo ?: string; priskribo ?: string; uzo ?: string; auxtoro ?: string; } = {} ) { this.meti_valorojn(datumoj); } /** * @author fenris */ public meti_valorojn(datumoj : Object) : void { this.identigilo = alporti(datumoj, "identigilo", cxeno_generi("kromajxo_"), 1); this.nomo = alporti(datumoj, "nomo", null, 0); this.priskribo = alporti(datumoj, "priskribo", null, 0); this.uzo = alporti(datumoj, "uzo", null, 0); this.auxtoro = alporti(datumoj, "auxtoro", null, 0); } /** * @author fenris */ public identigilo_legi() : string { return this.identigilo; } /** * @author fenris */ public nomo_legi() : string { return this.nomo; } /** * @author fenris */ public priskribo_legi() : string { return this.priskribo; } /** * @author fenris */ public uzo_legi() : string { return this.uzo; } /** * @author fenris */ public auxtoro_legi() : string { return this.auxtoro; } /** * @todo sekura respondado estus mojosa * @author fenris */ public enigi(enigo : klaso_evento_eniga, eligi : (eligo : klaso_evento_eliga)=>void) : void { let that : klaso_kromajxo = this; this.reagi ( enigo.kruda_al(), eligo_kruda => eligi(klaso_evento_eliga_mesagxo.kruda_de(eligo_kruda)) ) /* function respondi_sekure(linioj) { if (linioj.length <= 5) { linioj.forEach(linio => respondi({"tipo": "mesagxo", "parametroj": {"celo": enigo_kruda["parametroj"]["fonto"], "enhavo": linio}})); } else { var avizo = "Tro multe da rezultoj, ili senditos al vi private"; respondi({"tipo": "mesagxo", "parametroj": {"celo": enigo_kruda["parametroj"]["fonto"], "alparolato": enigo_kruda["parametroj"]["sendinto"], "enhavo": avizo}}); linioj.forEach(linio => respondi({"tipo": "mesagxo", "parametroj": {"celo": enigo_kruda["parametroj"]["sendinto"], "enhavo": linio}})); } } */ } /** * @author fenris */ public starigi(finado : (eraro ?: Error)=>void) : void { finado(null); } /** * @author fenris */ protected abstract reagi(enigo_kruda : Object, eligi : (eligo_kruda : Object)=>void) : void; }