This commit is contained in:
Flummi 2017-11-24 15:52:57 +01:00
parent 2bf6cfae00
commit a8da8103f8
4 changed files with 14 additions and 25 deletions

View File

@ -7,7 +7,7 @@
"build": "./node_modules/.bin/babel src --presets=env --plugins=add-module-exports --out-dir dist", "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", "debug": "npm run rmlog && npm run build && node --inspect=9229 dist/bot.js",
"start": "npm run build && node dist/bot.js", "start": "npm run build && node dist/bot.js",
"rmlog": "rm logs/*.log" "rmlog": "rm logs/*.log || true"
}, },
"author": "Flummi & jkhsjdhjs", "author": "Flummi & jkhsjdhjs",
"license": "WTFPL", "license": "WTFPL",

View File

@ -5,7 +5,7 @@ const net = require("net")
, util = require("util") , util = require("util")
, fs = require("fs"); , fs = require("fs");
class irc { export class irc {
constructor(options) { constructor(options) {
EventEmitter.call(this); EventEmitter.call(this);
this.options = options || {}; this.options = options || {};
@ -23,13 +23,10 @@ class irc {
this._recachetime = 60 * 5; // 5 minutes this._recachetime = 60 * 5; // 5 minutes
this._cmd = new Map(); this._cmd = new Map();
const files = fs.readdirSync(`${__dirname}/irc/`); fs.readdirSync(`${__dirname}/irc/`).forEach(file => {
for(let file in files) { logger.debug(`(${this.network}) loading cmd: ${file}`);
if(files[file].substr(-3, 3) === ".js") { require(`${__dirname}/irc/${file}`)(this);
logger.debug(`(${this.network}) loading cmd: ${files[file]}`); });
require(`${__dirname}/irc/${files[file]}`)(this);
}
}
this.server = { this.server = {
motd: "", motd: "",
@ -49,14 +46,11 @@ class irc {
}); });
this.socket.setEncoding("utf-8"); this.socket.setEncoding("utf-8");
this.socket.on("data", msg => { this.socket.on("data", msg => {
msg = msg.split(/\r?\n|\r/); msg.split(/\r?\n|\r/).filter(tmp => tmp.length > 0).forEach(tmp => {
for(let tmp in msg) { const cmd = this.parse(tmp);
if(msg[tmp].length > 0) {
const cmd = this.parse(msg[tmp]);
if (this._cmd.has(cmd.command)) if (this._cmd.has(cmd.command))
this._cmd.get(cmd.command)(cmd); this._cmd.get(cmd.command)(cmd);
} })
}
}); });
} }
send(data) { send(data) {
@ -125,8 +119,6 @@ class irc {
; ;
} }
} }
module.exports = irc;
util.inherits(irc, EventEmitter); util.inherits(irc, EventEmitter);
Map.prototype.hasi = function(val) { Map.prototype.hasi = function(val) {

View File

@ -3,7 +3,7 @@ const tgapi = require("node-telegram-bot-api")
, EventEmitter = require("events").EventEmitter , EventEmitter = require("events").EventEmitter
, util = require("util"); , util = require("util");
class tg { export class tg {
constructor(options) { constructor(options) {
EventEmitter.call(this); EventEmitter.call(this);
this.options = options || {}; this.options = options || {};
@ -60,6 +60,4 @@ class tg {
; ;
} }
} }
module.exports = tg;
util.inherits(tg, EventEmitter); util.inherits(tg, EventEmitter);

View File

@ -1,9 +1,8 @@
import { cfg } from "./cfg.js"; 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 util = require("util");
const EventEmitter = require("events").EventEmitter; const EventEmitter = require("events").EventEmitter;
const clients = []; const clients = [];