wrapper
This commit is contained in:
parent
4bbee1160d
commit
9d6f4c0f2c
197
package-lock.json
generated
197
package-lock.json
generated
@ -60,6 +60,15 @@
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"array.prototype.findindex": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/array.prototype.findindex/-/array.prototype.findindex-2.0.2.tgz",
|
||||
"integrity": "sha1-WAaNJYh+9QXknckssAxE3O5VsGc=",
|
||||
"requires": {
|
||||
"define-properties": "1.1.2",
|
||||
"es-abstract": "1.9.0"
|
||||
}
|
||||
},
|
||||
"asn1": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz",
|
||||
@ -801,6 +810,14 @@
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"bl": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/bl/-/bl-1.2.1.tgz",
|
||||
"integrity": "sha1-ysMo977kVzDUBLaSID/LWQ4XLV4=",
|
||||
"requires": {
|
||||
"readable-stream": "2.3.3"
|
||||
}
|
||||
},
|
||||
"bluebird": {
|
||||
"version": "3.5.1",
|
||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
|
||||
@ -952,11 +969,25 @@
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"define-properties": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.2.tgz",
|
||||
"integrity": "sha1-g6c/L+pWmJj7c3GTyPhzyvbUXJQ=",
|
||||
"requires": {
|
||||
"foreach": "2.0.5",
|
||||
"object-keys": "1.0.11"
|
||||
}
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||
},
|
||||
"depd": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz",
|
||||
"integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k="
|
||||
},
|
||||
"detect-indent": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz",
|
||||
@ -975,6 +1006,36 @@
|
||||
"jsbn": "0.1.1"
|
||||
}
|
||||
},
|
||||
"end-of-stream": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.0.tgz",
|
||||
"integrity": "sha1-epDYM+/abPpurA9JSduw+tOmMgY=",
|
||||
"requires": {
|
||||
"once": "1.4.0"
|
||||
}
|
||||
},
|
||||
"es-abstract": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.9.0.tgz",
|
||||
"integrity": "sha512-kk3IJoKo7A3pWJc0OV8yZ/VEX2oSUytfekrJiqoxBlKJMFAJVJVpGdHClCCTdv+Fn2zHfpDHHIelMFhZVfef3Q==",
|
||||
"requires": {
|
||||
"es-to-primitive": "1.1.1",
|
||||
"function-bind": "1.1.1",
|
||||
"has": "1.0.1",
|
||||
"is-callable": "1.1.3",
|
||||
"is-regex": "1.0.4"
|
||||
}
|
||||
},
|
||||
"es-to-primitive": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.1.1.tgz",
|
||||
"integrity": "sha1-RTVSSKiJeQNLZ5Lhm7gfK3l13Q0=",
|
||||
"requires": {
|
||||
"is-callable": "1.1.3",
|
||||
"is-date-object": "1.0.1",
|
||||
"is-symbol": "1.0.1"
|
||||
}
|
||||
},
|
||||
"escape-string-regexp": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||
@ -992,6 +1053,11 @@
|
||||
"resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-0.4.13.tgz",
|
||||
"integrity": "sha1-Coq5f5wbVjNhuJJ/noBgYndQkVM="
|
||||
},
|
||||
"eventemitter3": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz",
|
||||
"integrity": "sha1-teEHm1n7XhuidxwKmTvgYKWMmbo="
|
||||
},
|
||||
"expand-brackets": {
|
||||
"version": "0.1.5",
|
||||
"resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-0.1.5.tgz",
|
||||
@ -1042,6 +1108,11 @@
|
||||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
|
||||
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I="
|
||||
},
|
||||
"file-type": {
|
||||
"version": "3.9.0",
|
||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz",
|
||||
"integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek="
|
||||
},
|
||||
"filename-regex": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz",
|
||||
@ -1080,6 +1151,11 @@
|
||||
"for-in": "1.0.2"
|
||||
}
|
||||
},
|
||||
"foreach": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz",
|
||||
"integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k="
|
||||
},
|
||||
"forever-agent": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
|
||||
@ -1786,6 +1862,11 @@
|
||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
|
||||
"dev": true
|
||||
},
|
||||
"function-bind": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
||||
},
|
||||
"getpass": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
|
||||
@ -1861,6 +1942,14 @@
|
||||
"har-schema": "1.0.5"
|
||||
}
|
||||
},
|
||||
"has": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/has/-/has-1.0.1.tgz",
|
||||
"integrity": "sha1-hGFzP1OLCDfJNh45qauelwTcLyg=",
|
||||
"requires": {
|
||||
"function-bind": "1.1.1"
|
||||
}
|
||||
},
|
||||
"has-ansi": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
|
||||
@ -1956,6 +2045,9 @@
|
||||
"resolved": "https://registry.npmjs.org/irc-message/-/irc-message-2.0.1.tgz",
|
||||
"integrity": "sha1-3AJ1lTmgMMlq82rW/I/ukIPffLw="
|
||||
},
|
||||
"irc-socket": {
|
||||
"version": "github:ircanywhere/irc-socket#19343600ce38460c9c8d7b7b265ac23313153342"
|
||||
},
|
||||
"is-binary-path": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-1.0.1.tgz",
|
||||
@ -1972,6 +2064,16 @@
|
||||
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
|
||||
"dev": true
|
||||
},
|
||||
"is-callable": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.3.tgz",
|
||||
"integrity": "sha1-hut1OSgF3cM69xySoO7fdO52BLI="
|
||||
},
|
||||
"is-date-object": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz",
|
||||
"integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY="
|
||||
},
|
||||
"is-dotfile": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-dotfile/-/is-dotfile-1.0.3.tgz",
|
||||
@ -2044,6 +2146,19 @@
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"is-regex": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz",
|
||||
"integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=",
|
||||
"requires": {
|
||||
"has": "1.0.1"
|
||||
}
|
||||
},
|
||||
"is-symbol": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.1.tgz",
|
||||
"integrity": "sha1-PMWfAAJRlLarLjjbrmaJJWtmBXI="
|
||||
},
|
||||
"is-typedarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
@ -2184,6 +2299,11 @@
|
||||
"regex-cache": "0.4.4"
|
||||
}
|
||||
},
|
||||
"mime": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz",
|
||||
"integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ=="
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.27.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz",
|
||||
@ -2235,6 +2355,24 @@
|
||||
"sqlstring": "2.3.0"
|
||||
}
|
||||
},
|
||||
"node-telegram-bot-api": {
|
||||
"version": "0.29.0",
|
||||
"resolved": "https://registry.npmjs.org/node-telegram-bot-api/-/node-telegram-bot-api-0.29.0.tgz",
|
||||
"integrity": "sha512-WZBp5ccr0zMLRNtZ3avrevGpj05mrN59lDmxgpltls0bl3W/wqyNalNGKatTZEJ1cY0pctgd9FqKyCzWr36HcQ==",
|
||||
"requires": {
|
||||
"array.prototype.findindex": "2.0.2",
|
||||
"bl": "1.2.1",
|
||||
"bluebird": "3.5.1",
|
||||
"debug": "2.6.8",
|
||||
"depd": "1.1.1",
|
||||
"eventemitter3": "2.0.3",
|
||||
"file-type": "3.9.0",
|
||||
"mime": "1.4.1",
|
||||
"pump": "1.0.2",
|
||||
"request": "2.81.0",
|
||||
"request-promise": "4.2.2"
|
||||
}
|
||||
},
|
||||
"nodejs-mysql": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/nodejs-mysql/-/nodejs-mysql-0.1.3.tgz",
|
||||
@ -2270,6 +2408,11 @@
|
||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=",
|
||||
"dev": true
|
||||
},
|
||||
"object-keys": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.11.tgz",
|
||||
"integrity": "sha1-xUYBd4rVYPEULODgG8yotW0TQm0="
|
||||
},
|
||||
"object.omit": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/object.omit/-/object.omit-2.0.1.tgz",
|
||||
@ -2285,7 +2428,6 @@
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"wrappy": "1.0.2"
|
||||
}
|
||||
@ -2360,6 +2502,15 @@
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
|
||||
"integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
|
||||
},
|
||||
"pump": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pump/-/pump-1.0.2.tgz",
|
||||
"integrity": "sha1-Oz7mUS+U8OV1U4wXmV+fFpkKXVE=",
|
||||
"requires": {
|
||||
"end-of-stream": "1.4.0",
|
||||
"once": "1.4.0"
|
||||
}
|
||||
},
|
||||
"punycode": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
|
||||
@ -2566,6 +2717,42 @@
|
||||
"uuid": "3.1.0"
|
||||
}
|
||||
},
|
||||
"request-promise": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.2.tgz",
|
||||
"integrity": "sha1-0epG1lSm7k+O5qT+oQGMIpEZBLQ=",
|
||||
"requires": {
|
||||
"bluebird": "3.5.1",
|
||||
"request-promise-core": "1.1.1",
|
||||
"stealthy-require": "1.1.1",
|
||||
"tough-cookie": "2.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"tough-cookie": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.3.tgz",
|
||||
"integrity": "sha1-C2GKVWW23qkL80JdBNVe3EdadWE=",
|
||||
"requires": {
|
||||
"punycode": "1.4.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"request-promise-core": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.1.tgz",
|
||||
"integrity": "sha1-Pu4AssWqgyOc+wTFcA2jb4HNCLY=",
|
||||
"requires": {
|
||||
"lodash": "4.17.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash": {
|
||||
"version": "4.17.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
|
||||
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4="
|
||||
}
|
||||
}
|
||||
},
|
||||
"safe-buffer": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
|
||||
@ -2639,6 +2826,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"stealthy-require": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz",
|
||||
"integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks="
|
||||
},
|
||||
"streamify": {
|
||||
"version": "0.2.9",
|
||||
"resolved": "https://registry.npmjs.org/streamify/-/streamify-0.2.9.tgz",
|
||||
@ -2750,8 +2942,7 @@
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"dev": true
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
},
|
||||
"youtube-dl": {
|
||||
"version": "1.12.2",
|
||||
|
@ -19,6 +19,7 @@
|
||||
"irc-socket": "github:ircanywhere/irc-socket",
|
||||
"json-stringify-safe": "^5.0.0",
|
||||
"lodash": "2.4.1",
|
||||
"node-telegram-bot-api": "^0.29.0",
|
||||
"nodejs-mysql": "^0.1.3",
|
||||
"pause-queue": "~0.1.0",
|
||||
"safe-eval": "^0.3.0",
|
||||
|
98
src/bot.js
98
src/bot.js
@ -1,25 +1,87 @@
|
||||
import { cfg, read } from './inc/cfg.js';
|
||||
import { wrapper } from './inc/wrapper.js';
|
||||
//const TelegramBot = require('node-telegram-bot-api');
|
||||
//const safeEval = require('safe-eval');
|
||||
//const util = require('util');
|
||||
//const fs = require('fs');
|
||||
//const ytdl = util.promisify(require('youtube-dl').getInfo);
|
||||
|
||||
|
||||
read().then(() => {
|
||||
console.log( cfg );
|
||||
let bot = new wrapper();
|
||||
|
||||
bot.on('message', msg => {
|
||||
console.log( msg );
|
||||
});
|
||||
});
|
||||
/*const lib = new (require(`${__dirname}/inc/lib`))(cfg);
|
||||
lib.events.on('message', msg => {
|
||||
if( msg.event[1] === "privmsg" ) {
|
||||
const e = lib.reply( msg );
|
||||
console.log( `IRC: (${e.time}) ${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}` );
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const bot = new TelegramBot("381368731:AAFalG-LknIbtBDuOvRXcxHUEK9Jg_o1UCw", { polling: true });
|
||||
bot.on('message', (msg) => {
|
||||
var e = lib.replytg(bot, msg);
|
||||
console.log( `TG: (${e.time}) ${e.channel} -> ${e.user.nick}: ${e.message}` );
|
||||
|
||||
switch(e.message) {
|
||||
case "1":
|
||||
e.reply("normal");
|
||||
break;
|
||||
default:
|
||||
//if(e.user.nick === "Flummi" || e.user.nick === "jkhsjdhjs" || e.user.nick === "Flummsi" || e.user.nick === "mrhanky" || e.user.nick === "gz") {
|
||||
if(e.message.match(/^\.js /)) { // JS-Sandbox
|
||||
let args = e.message.substring(3);
|
||||
var context = {
|
||||
e: e,
|
||||
msg: msg
|
||||
}
|
||||
try {
|
||||
var output = safeEval(args, context);
|
||||
if(typeof output !== undefined && output !== 'undefined' && output) {
|
||||
let blah = JSON.stringify( output );
|
||||
if(blah != "Converting circular structure to JSON")
|
||||
e.reply( blah.length > 250 ? `holy fuck, Ausgabe wäre viel zu lang! (${blah.length} Zeichen :DDDDDD)` : blah );
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
e.reply(err.message);
|
||||
}
|
||||
}
|
||||
else if(e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // parser
|
||||
let links = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi);
|
||||
const args = [
|
||||
//"-j",
|
||||
//"-q",
|
||||
"--no-progress",
|
||||
"--no-warnings",
|
||||
"--no-check-certificate",
|
||||
"--max-filesize 500m",
|
||||
'-o "./tmp/%(title)s.%(ext)s"'
|
||||
];
|
||||
|
||||
Promise.all( links.map( link => checkRepost( link ) ) ) // repostcheck
|
||||
.then( res => Promise.all( res.map( link => ytdl(link) ) ) ) // get informations
|
||||
.then( res => {
|
||||
res.forEach( data => {
|
||||
e.reply( data.title );
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//}
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/*var config = new (require(__dirname+'/inc/cfg'))();
|
||||
config.read()
|
||||
.then(
|
||||
data => {
|
||||
config.cfg = data;
|
||||
var lib = new (require(__dirname+'/inc/lib'))(config.cfg);
|
||||
lib.events.on('message', function(msg) {
|
||||
if( msg.event[1] === 'privmsg' ) {
|
||||
var e = lib.reply(msg);
|
||||
console.log( `(${e.time}) ${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}` );
|
||||
}
|
||||
});
|
||||
},
|
||||
err => {
|
||||
console.log( "error! " + err );
|
||||
}
|
||||
)*/
|
||||
function checkRepost(link) {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve( link );
|
||||
});
|
||||
}*/
|
@ -22,7 +22,7 @@ const read = () => new Promise((resolve, reject) => {
|
||||
return parseInt(value);
|
||||
break;
|
||||
case 'bool':
|
||||
return (value === 'true')?true:false;
|
||||
return value === 'true';
|
||||
break;
|
||||
case 'json':
|
||||
return JSON.parse(value);
|
||||
|
@ -1,25 +1,6 @@
|
||||
var factory = require(__dirname+'/../inc/api');
|
||||
var fs = require('fs');
|
||||
var self = Lib.prototype;
|
||||
import { cfg } from './cfg.js';
|
||||
|
||||
self.api = new factory.Api();
|
||||
|
||||
var options = {
|
||||
events: 31920,
|
||||
rpc: 31930,
|
||||
automaticSetup: true
|
||||
};
|
||||
self.interfaces = self.api.connect(options);
|
||||
self.events = self.interfaces.events;
|
||||
self.rpc = self.interfaces.rpc;
|
||||
|
||||
module.exports = Lib;
|
||||
function Lib(config) {
|
||||
self.cfg = config;
|
||||
self.loadEvents();
|
||||
}
|
||||
|
||||
self.loadEvents = () => {
|
||||
const loadEvents = () => {
|
||||
var files = fs.readdirSync(__dirname+'/events/');
|
||||
files.forEach(file => {
|
||||
if(file.substr(-3, 3) === '.js') {
|
||||
@ -29,33 +10,4 @@ self.loadEvents = () => {
|
||||
});
|
||||
};
|
||||
|
||||
self.reply = (tmp) => {
|
||||
return {
|
||||
network: tmp.event[0],
|
||||
channel: tmp.message.target,
|
||||
user: {
|
||||
nick: tmp.message.nickname,
|
||||
username: tmp.message.username,
|
||||
hostname: tmp.message.hostname
|
||||
},
|
||||
message: tmp.message.message,
|
||||
time: tmp.message.time,
|
||||
reply: function(msg) {
|
||||
self.rpc.emit('call', this.event[0], 'privmsg', [ this.message.target, msg ]);
|
||||
}.bind(tmp),
|
||||
replyAction: function(msg) {
|
||||
self.rpc.emit('call', this.event[0], 'privmsg', [ this.message.target, '\u0001' + 'ACTION ' + msg + '\u0001' ]);
|
||||
}.bind(tmp),
|
||||
replyNotice: function(msg) {
|
||||
self.rpc.emit('call', this.event[0], 'notice', [ this.message.target, msg ]);
|
||||
}.bind(tmp)
|
||||
};
|
||||
};
|
||||
|
||||
self.loadIRC = () => {
|
||||
for(let srv in self.cfg.irc) {
|
||||
self.rpc.emit( 'createClient', srv, self.cfg.irc[srv] );
|
||||
console.log('Loading server', srv);
|
||||
}
|
||||
console.log('All servers have been loaded successfully');
|
||||
};
|
||||
export { loadEvents };
|
100
src/inc/wrapper.js
Normal file
100
src/inc/wrapper.js
Normal file
@ -0,0 +1,100 @@
|
||||
import { cfg, read } from './cfg.js';
|
||||
import { loadEvents } from './lib.js';
|
||||
|
||||
//const TelegramBot = require('node-telegram-bot-api');
|
||||
const safeEval = require('safe-eval');
|
||||
const util = require('util');
|
||||
const fs = require('fs');
|
||||
const ytdl = util.promisify(require('youtube-dl').getInfo);
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
let irc = (new (require(`${__dirname}/irc/api`)).Api()).connect({
|
||||
events: 31920,
|
||||
rpc: 31930,
|
||||
automaticSetup: true
|
||||
});
|
||||
|
||||
const wrapper = function() {
|
||||
//loadIRC();
|
||||
//loadEvents();
|
||||
//rpc.emit('call', 'n0xy', 'privmsg', [ '#kbot-dev', 'blah' ]);
|
||||
|
||||
for(let srv in cfg.irc) {
|
||||
irc.rpc.emit('createClient', srv, cfg.irc[srv]);
|
||||
console.log('Loading server', srv);
|
||||
}
|
||||
console.log('All servers have been loaded successfully');
|
||||
|
||||
const tg = new (require('node-telegram-bot-api'))('381368731:AAFalG-LknIbtBDuOvRXcxHUEK9Jg_o1UCw', { polling: true });
|
||||
|
||||
irc.events.on('message', msg => {
|
||||
this.emit('message', msg);
|
||||
//if( msg.event[1] === "privmsg" ) {
|
||||
// let e = reply( msg );
|
||||
// console.log( `IRC: (${e.time}) ${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}` );
|
||||
//}
|
||||
});
|
||||
|
||||
tg.on('message', msg => {
|
||||
this.emit('message', msg);
|
||||
//let e = replytg(tg, msg);
|
||||
//console.log( `TG: (${e.time}) ${e.channel} -> ${e.user.nick}: ${e.message}` );
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
const reply = tmp => {
|
||||
return {
|
||||
network: tmp.event[0],
|
||||
channel: tmp.message.target,
|
||||
user: {
|
||||
nick: tmp.message.nickname,
|
||||
username: tmp.message.username,
|
||||
hostname: tmp.message.hostname
|
||||
},
|
||||
message: tmp.message.message,
|
||||
time: tmp.message.time,
|
||||
reply: msg => {
|
||||
rpc.emit('call', this.network, 'privmsg', [ this.channel, msg ]);
|
||||
},
|
||||
replyAction: msg => {
|
||||
rpc.emit('call', this.network, 'privmsg', [ this.channel, '\u0001' + 'ACTION ' + msg + '\u0001' ]);
|
||||
},
|
||||
replyNotice: msg => {
|
||||
rpc.emit('call', this.network, 'notice', [ this.channel, msg ]);
|
||||
}
|
||||
};
|
||||
};
|
||||
const replytg = (bot, tmp) => {
|
||||
return {
|
||||
channel: tmp.chat.title,
|
||||
channelid: tmp.chat.id,
|
||||
user: {
|
||||
nick: tmp.from.first_name,
|
||||
username: tmp.from.username
|
||||
},
|
||||
message: tmp.text,
|
||||
time: tmp.date,
|
||||
reply: function(msg) {
|
||||
bot.sendMessage(this.channelid, msg);
|
||||
}.bind(this),
|
||||
replyAction: function(msg) {
|
||||
bot.sendMessage(this.channelid, msg);
|
||||
},
|
||||
replyNotice: function(msg) {
|
||||
bot.sendMessage(this.channelid, msg);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const loadIRC = () => {
|
||||
for(let srv in cfg.irc) {
|
||||
rpc.emit('createClient', srv, cfg.irc[srv]);
|
||||
console.log('Loading server', srv);
|
||||
}
|
||||
console.log('All servers have been loaded successfully');
|
||||
};
|
||||
|
||||
util.inherits(wrapper, EventEmitter);
|
||||
export default { wrapper };
|
Loading…
Reference in New Issue
Block a user