diff --git a/package.json b/package.json index 443c582..ae3622f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "./node_modules/.bin/babel src --presets=env --plugins=add-module-exports --out-dir dist", "debug": "npm run rmlog && npm run build && node --inspect=9229 dist/bot.js", "start": "npm run build && node dist/bot.js", - "rmlog": "rm logs/*.log" + "rmlog": "rm logs/*.log || true" }, "author": "Flummi & jkhsjdhjs", "license": "WTFPL", diff --git a/src/inc/clients/irc.js b/src/inc/clients/irc.js index bcc5427..9bf8d6d 100644 --- a/src/inc/clients/irc.js +++ b/src/inc/clients/irc.js @@ -5,7 +5,7 @@ const net = require("net") , util = require("util") , fs = require("fs"); -class irc { +export class irc { constructor(options) { EventEmitter.call(this); this.options = options || {}; @@ -23,13 +23,10 @@ class irc { this._recachetime = 60 * 5; // 5 minutes this._cmd = new Map(); - const files = fs.readdirSync(`${__dirname}/irc/`); - for(let file in files) { - if(files[file].substr(-3, 3) === ".js") { - logger.debug(`(${this.network}) loading cmd: ${files[file]}`); - require(`${__dirname}/irc/${files[file]}`)(this); - } - } + fs.readdirSync(`${__dirname}/irc/`).forEach(file => { + logger.debug(`(${this.network}) loading cmd: ${file}`); + require(`${__dirname}/irc/${file}`)(this); + }); this.server = { motd: "", @@ -49,14 +46,11 @@ class irc { }); this.socket.setEncoding("utf-8"); this.socket.on("data", msg => { - msg = msg.split(/\r?\n|\r/); - for(let tmp in msg) { - if(msg[tmp].length > 0) { - const cmd = this.parse(msg[tmp]); - if(this._cmd.has(cmd.command)) - this._cmd.get(cmd.command)(cmd); - } - } + msg.split(/\r?\n|\r/).filter(tmp => tmp.length > 0).forEach(tmp => { + const cmd = this.parse(tmp); + if (this._cmd.has(cmd.command)) + this._cmd.get(cmd.command)(cmd); + }) }); } send(data) { @@ -125,8 +119,6 @@ class irc { ; } } - -module.exports = irc; util.inherits(irc, EventEmitter); Map.prototype.hasi = function(val) { diff --git a/src/inc/clients/tg.js b/src/inc/clients/tg.js index 793e48b..92d7e10 100644 --- a/src/inc/clients/tg.js +++ b/src/inc/clients/tg.js @@ -3,7 +3,7 @@ const tgapi = require("node-telegram-bot-api") , EventEmitter = require("events").EventEmitter , util = require("util"); -class tg { +export class tg { constructor(options) { EventEmitter.call(this); this.options = options || {}; @@ -60,6 +60,4 @@ class tg { ; } } - -module.exports = tg; util.inherits(tg, EventEmitter); \ No newline at end of file diff --git a/src/inc/wrapper.js b/src/inc/wrapper.js index 1a6b819..75a8809 100644 --- a/src/inc/wrapper.js +++ b/src/inc/wrapper.js @@ -1,9 +1,8 @@ import { cfg } from "./cfg.js"; +import { irc as irclib } from "./clients/irc.js"; +import { tg as tglib } from "./clients/tg.js"; -const irclib = require("./clients/irc.js"); -const tglib = require("./clients/tg.js"); const util = require("util"); - const EventEmitter = require("events").EventEmitter; const clients = [];