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",
"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",

View File

@ -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) {

View File

@ -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);

View File

@ -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 = [];