Errorlogging

This commit is contained in:
Flummi 2017-12-03 17:55:36 +01:00
parent 877f4aec26
commit f6f882586b
4 changed files with 39 additions and 12 deletions

View File

@ -55,7 +55,7 @@ read().then(() => {
}); });
}) })
.catch(err => { .catch(err => {
console.log(err); logger.error(`(main) ${err.message}`);
}); });
function trigger(args) { function trigger(args) {

View File

@ -62,8 +62,6 @@ export class irc {
this.socket.on("data", msg => { this.socket.on("data", msg => {
msg.split(/\r?\n|\r/).filter(tmp => tmp.length > 0).forEach(tmp => { msg.split(/\r?\n|\r/).filter(tmp => tmp.length > 0).forEach(tmp => {
const cmd = this.parse(tmp); const cmd = this.parse(tmp);
//if(this.network === "n0xy")
// console.log(cmd);
if (this._cmd.has(cmd.command)) if (this._cmd.has(cmd.command))
this._cmd.get(cmd.command)(cmd); this._cmd.get(cmd.command)(cmd);
}) })
@ -125,13 +123,10 @@ export class irc {
user = user.toLowerCase(); user = user.toLowerCase();
let tmpuser = {}; let tmpuser = {};
if(this.server.user.hasi(user) && !force) { if(this.server.user.hasi(user) && !force) {
//console.log("existiert", user);
tmpuser = this.server.user.geti(user); tmpuser = this.server.user.geti(user);
if(tmpuser.cached >= ~~(Date.now() / 1000) - this._recachetime) { if(tmpuser.cached >= ~~(Date.now() / 1000) - this._recachetime)
//console.log("already cached", user);
return; return;
} }
}
tmpuser = { tmpuser = {
nickname: tmpuser.nickname || false, nickname: tmpuser.nickname || false,
@ -147,7 +142,6 @@ export class irc {
}; };
this.server.user.set(user, tmpuser); this.server.user.set(user, tmpuser);
//console.log("whois", user);
this.send(`WHOIS ${user}`); this.send(`WHOIS ${user}`);
} }
parsePrefix(prefix) { parsePrefix(prefix) {

View File

@ -11,6 +11,7 @@ export class tg extends EventEmitter {
this.options = options || {}; this.options = options || {};
this.token = options.token || null; this.token = options.token || null;
this.options.pollrate = options.pollrate || 1000; this.options.pollrate = options.pollrate || 1000;
this.network = "Telegram";
this.api = `https://api.telegram.org/bot${this.token}`; this.api = `https://api.telegram.org/bot${this.token}`;
this.lastUpdate = 0; this.lastUpdate = 0;
this.server = { this.server = {
@ -38,10 +39,15 @@ export class tg extends EventEmitter {
}; };
resolve(); resolve();
} }
else else {
logger.error(`(${this.network}) ${res}`);
reject(); reject();
}
}) })
.catch(err => reject()); .catch(err => {
logger.error(`(${this.network}) ${err.message}`);
reject();
});
}); });
} }
poll() { poll() {
@ -64,7 +70,9 @@ export class tg extends EventEmitter {
} }
} }
}) })
.catch(err => console.log(err)); .catch(err => {
logger.error(`(${this.network}) ${err.message}`);
});
} }
send(chatid, msg, reply = null) { send(chatid, msg, reply = null) {
const opts = { const opts = {
@ -81,7 +89,9 @@ export class tg extends EventEmitter {
opts.body.reply_to_message_id = reply; opts.body.reply_to_message_id = reply;
rp(opts) rp(opts)
.then(res => {}) .then(res => {})
.catch(err => console.log(err)); .catch(err => {
logger.error(`(${this.network}) ${err.message}`);
});
} }
reply(tmp) { reply(tmp) {
return { return {
@ -123,3 +133,21 @@ export class tg extends EventEmitter {
; ;
} }
} }
Map.prototype.hasi = function(val) {
for (let [key] of this)
if(key.toLowerCase() === val.toLowerCase())
return true;
return false;
};
Map.prototype.geti = function(val) {
for (let [key, value] of this)
if(key.toLowerCase() === val.toLowerCase())
return value;
return false;
};
Map.prototype.deli = function(val) {
for (let [key] of this)
if(key.toLowerCase() === val.toLowerCase())
this.delete(key);
};

View File

@ -12,6 +12,11 @@ const logger = new (winston.Logger)({
filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_info.log`, filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_info.log`,
level: "info" level: "info"
}), }),
new (winston.transports.File)({
name: "error-file",
filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_error.log`,
level: "error"
}),
new (winston.transports.Console)({ new (winston.transports.Console)({
level: "info" level: "info"
}) })