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 => {
console.log(err);
logger.error(`(main) ${err.message}`);
});
function trigger(args) {

View File

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

View File

@ -11,6 +11,7 @@ export class tg extends EventEmitter {
this.options = options || {};
this.token = options.token || null;
this.options.pollrate = options.pollrate || 1000;
this.network = "Telegram";
this.api = `https://api.telegram.org/bot${this.token}`;
this.lastUpdate = 0;
this.server = {
@ -38,10 +39,15 @@ export class tg extends EventEmitter {
};
resolve();
}
else
else {
logger.error(`(${this.network}) ${res}`);
reject();
}
})
.catch(err => reject());
.catch(err => {
logger.error(`(${this.network}) ${err.message}`);
reject();
});
});
}
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) {
const opts = {
@ -81,7 +89,9 @@ export class tg extends EventEmitter {
opts.body.reply_to_message_id = reply;
rp(opts)
.then(res => {})
.catch(err => console.log(err));
.catch(err => {
logger.error(`(${this.network}) ${err.message}`);
});
}
reply(tmp) {
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`,
level: "info"
}),
new (winston.transports.File)({
name: "error-file",
filename: `${__dirname}/../../logs/${~~(Date.now() / 1000)}_error.log`,
level: "error"
}),
new (winston.transports.Console)({
level: "info"
})