diff --git a/.gitignore b/.gitignore index 0f0b850..876a2c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules/ -logs/*.log cfg/*.json -b/ \ No newline at end of file +b/ +t/ diff --git a/bin/youtube-dl b/bin/youtube-dl deleted file mode 100755 index f8aab0a..0000000 Binary files a/bin/youtube-dl and /dev/null differ diff --git a/logs/.empty b/logs/.empty deleted file mode 100644 index e69de29..0000000 diff --git a/package-lock.json b/package-lock.json index 5e1567c..83377cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,66 +4,14 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "ansicolors": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz", - "integrity": "sha1-ZlWX3oap/+Oqm/vmyuXG6kJrSXk=" - }, - "async": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz", - "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k=" - }, - "bluebird": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.2.tgz", - "integrity": "sha512-dhHTWMI7kMx5whMQntl7Vr9C6BvV10lFXDAasnqnrMYhXVCzzk6IO9Fo2L75jXHT07WrOngL1WDXOp+yYS91Yg==" - }, - "cardinal": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/cardinal/-/cardinal-2.1.1.tgz", - "integrity": "sha1-fMEFXYItISlU0HsIXeolHMe8VQU=", - "requires": { - "ansicolors": "~0.3.2", - "redeyed": "~2.1.0" - } - }, - "colors": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", - "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=" - }, "cuffeo": { "version": "git+https://gitfap.de/keinBot/cuffeo.git#d55586ce5520d4119fa0900ef15ce8736fc62364", "from": "git+https://gitfap.de/keinBot/cuffeo.git" }, - "cycle": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz", - "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI=" - }, "denque": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/denque/-/denque-1.3.0.tgz", - "integrity": "sha512-4SRaSj+PqmrS1soW5/Avd7eJIM2JJIqLLmwhRqIGleZM/8KwZq80njbSS2Iqas+6oARkSkLDHEk4mm78q3JlIg==" - }, - "esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" - }, - "eyes": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz", - "integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A=" - }, - "generate-function": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", - "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", - "requires": { - "is-property": "^1.0.2" - } + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz", + "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ==" }, "iconv-lite": { "version": "0.4.24", @@ -73,130 +21,25 @@ "safer-buffer": ">= 2.1.2 < 3" } }, - "is-property": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", - "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=" - }, - "isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" - }, "long": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==" }, - "lru-cache": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.1.tgz", - "integrity": "sha512-q4spe4KTfsAS1SUHLO0wz8Qiyf1+vMIAgpRYioFYDMNqKfHQbg+AVDH3i4fvpl71/P1L0dBl+fQi+P37UYf0ew==", + "mariadb": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/mariadb/-/mariadb-2.0.3.tgz", + "integrity": "sha512-/0poOq++rcAWrSHdS+ozLDbK+/ZOpQ2XHYoVHXeZtMuhxEH/w7g/KfwryCqr3BCIC0JC/9UeJJG3v7vNNlshag==", "requires": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, - "mysql2": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-1.6.1.tgz", - "integrity": "sha512-BNrJH5HavPqskXEy8oVz7ucRbkhegKQ7VD8rNGFwvTuk0WiUSi1wXFOg67NjCGquZnim8nKgHdDiih6LqG5knA==", - "requires": { - "cardinal": "2.1.1", - "denque": "1.3.0", - "generate-function": "^2.0.0", - "iconv-lite": "^0.4.18", - "long": "^4.0.0", - "lru-cache": "4.1.1", - "named-placeholders": "1.1.1", - "object-assign": "^4.1.1", - "seq-queue": "0.0.5", - "sqlstring": "2.3.1" - } - }, - "named-placeholders": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.1.tgz", - "integrity": "sha1-O3oNJiA910s6nfTJz7gnsvuQfmQ=", - "requires": { - "lru-cache": "2.5.0" - }, - "dependencies": { - "lru-cache": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.5.0.tgz", - "integrity": "sha1-2COIrpyWC+y+oMc7uet5tsbOmus=" - } - } - }, - "node-fetch": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.2.0.tgz", - "integrity": "sha512-OayFWziIxiHY8bCUyLX6sTpDH8Jsbp4FfYd1j1f7vZyfgkcOnAyM4oQR16f8a0s7Gl/viMGRey8eScYk4V4EZA==" - }, - "nodejs-mysql2": { - "version": "git+https://gitfap.de/Flummi/nodejs-mysql2.git#981d9f0946d25937675cb21a94099ad11a45d9fb", - "from": "git+https://gitfap.de/Flummi/nodejs-mysql2.git", - "requires": { - "bluebird": "^3.4.6", - "mysql2": "^1.5.3" - } - }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" - }, - "pseudomap": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", - "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" - }, - "redeyed": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/redeyed/-/redeyed-2.1.1.tgz", - "integrity": "sha1-iYS1gV2ZyyIEacme7v/jiRPmzAs=", - "requires": { - "esprima": "~4.0.0" + "denque": "^1.4.0", + "iconv-lite": "^0.4.24", + "long": "^4.0.0" } }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" - }, - "seq-queue": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", - "integrity": "sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4=" - }, - "sqlstring": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", - "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A=" - }, - "stack-trace": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", - "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=" - }, - "winston": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.4.tgz", - "integrity": "sha512-NBo2Pepn4hK4V01UfcWcDlmiVTs7VTB1h7bgnB0rgP146bYhMxX0ypCz3lBOfNxCO4Zuek7yeT+y/zM1OfMw4Q==", - "requires": { - "async": "~1.0.0", - "colors": "1.0.x", - "cycle": "1.0.x", - "eyes": "0.1.x", - "isstream": "0.1.x", - "stack-trace": "0.0.x" - } - }, - "yallist": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", - "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" } } } diff --git a/package.json b/package.json index daa8a8a..8e09e59 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,6 @@ "license": "ISC", "dependencies": { "cuffeo": "git+https://gitfap.de/keinBot/cuffeo.git", - "node-fetch": "^2.2.0", - "nodejs-mysql2": "git+https://gitfap.de/Flummi/nodejs-mysql2.git", - "winston": "^2.4.0" + "mariadb": "^2.0.3" } } diff --git a/src/inc/trigger/debug.mjs b/src/inc/trigger/debug.mjs index ff8a882..ea9e5dc 100644 --- a/src/inc/trigger/debug.mjs +++ b/src/inc/trigger/debug.mjs @@ -1,39 +1,36 @@ import { admins, getLevel } from "../admin"; - import vm from "vm"; -const maxoutput = 750; +const maxoutput = 1000; let context = vm.createContext({ e: null, bot: null, admins: null, }); -export default bot => { - bot._trigger.set("sandbox_debug", new bot.trigger({ - call: /^\!debug (.*)/i, - level: 100, - active: true, - f: e => { - const args = e.message.trim().substring(7); - if(args === "true" || args === "false") - return e.self.debug = !e.self.debug; - try { - context.admins = admins; - context.e = e; - context.bot = bot; - context.level = getLevel; - let output = vm.runInContext(args, vm.createContext(context)); - if (typeof output !== undefined && output) { - output = JSON.stringify(output); - if (output.length > maxoutput) - return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`); - else - return e.reply(output); - } - } - catch (err) { - e.reply(err.message); +export default bot => bot._trigger.set("sandbox_debug", new bot.trigger({ + call: /^\!debug (.*)/i, + level: 100, + active: true, + f: e => { + const args = e.message.trim().substring(7); + if(args === "true" || args === "false") + return e.self.debug = !e.self.debug; + try { + context.admins = admins; + context.e = e; + context.bot = bot; + context.level = getLevel; + let output = vm.runInContext(args, vm.createContext(context)); + if (typeof output !== undefined && output) { + output = JSON.stringify(output); + if (output.length > maxoutput) + return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`); + else + return e.reply(output); } } + catch (err) { + e.reply(err.message); + } + } })); -}; \ No newline at end of file diff --git a/src/inc/trigger/index.mjs b/src/inc/trigger/index.mjs index 89dca98..29c22ca 100644 --- a/src/inc/trigger/index.mjs +++ b/src/inc/trigger/index.mjs @@ -1,4 +1,3 @@ import debug from "./debug"; -import parser from "./parser_new"; -export default [ debug, parser ]; +export default [ debug ]; diff --git a/src/inc/trigger/parser.mjs b/src/inc/trigger/parser.mjs deleted file mode 100644 index edca977..0000000 --- a/src/inc/trigger/parser.mjs +++ /dev/null @@ -1,241 +0,0 @@ -import { cfg } from "../cfg"; -import sql from "../sql"; -import fs from "fs"; -import path from "path"; -import crypto from "crypto"; - -import uuid from "uuid"; -import cloudscraper from "cloudscraper"; -import readChunk from "read-chunk"; -import ytdl from "ytdl-core"; -import request from "request"; -import fileType from "file-type"; - -import { Readable } from "stream"; - -const checkRepost = (url, cbcr) => { - sql.exec("select count(id) as count, id from `f0ck`.`items` where `src` = ?", url).then(rows => { - cbcr((rows[0].count == 0)?true:rows[0].id); - }); -}; - -const checkRepostCheckSum = (cs, cbcrcs) => { - sql.exec("select count(id) as count, id from `f0ck`.`items` where `checksum` = ?", cs).then(rows => { - cbcrcs((rows[0].count == 0)?true:rows[0].id); - }); -}; -const formatSize = size => { - const i = ~~(Math.log(size) / Math.log(1024)); - return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; -}; -const getCheckSum = (file, cbcs) => { - var sha256sum = crypto.createHash('sha256'); - fs.ReadStream(file) - .on('data', d => sha256sum.update(d)) - .on('end', () => cbcs(sha256sum.digest('hex'))); -}; - - -export default bot => { - bot._trigger.set("parser", new bot.trigger({ - call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi, - f: e => { - if(e.channel === "#kbot-dev" || e.message.match(/(!|-)f0ck/i)) { - if(!e.message.match(/(!|-)ignore/)) { - const tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links - tmp.forEach((entry,i,a) => { - if(!entry.match(/f0ck\.me/i) && !entry.match(/\.onion/i)) { - getLink(entry, ((e.message.match(/(!|-)force/i) && e.user.level.level >= 100)?true:false), e.user.level.level, cb => { - if(cb.success === true) { - fs.rename(cb.file, cb.file + '.' + cb.info.ext, (err) => { - if(!err) { - sql.exec("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`,`thumb`) values (?,?,?,?,?,?,?,?,?,?,?)", [ - entry, - cb.file + '.' + cb.info.ext, - cb.info.mime, - cb.size, - cb.checksum, - e.user.nick, - e.channel, - e.network, - ~~(new Date() / 1000), - 0, - cb.info.thumb ? cb.info.thumb : '' - ]).then(result => { - //lib.generateThumbs(); - e.reply(cfg.main.url.val+"/"+result.insertId+" - "+cb.info.title+" ("+cb.info.mime+", ~"+formatSize(cb.size)+") by "+e.user.nick+" ("+e.user.prefix+")"); - }).catch(msg => { - e.reply("ups", msg); - }); - } - else { - e.reply("Datei konnte nicht verschoben werden D:"); - e.reply(`${cb.file} -> ${cb.file}.${cb.info.ext}`); - } - }); - } - else { - e.reply(JSON.stringify(cb)); - fs.stat(process.cwd() + '/b/' + cb.file, (err, stat) => { - if(cb.msg !== '') - e.reply(cb.msg); - if(!err && stat.isFile()) - fs.unlinkSync(process.cwd() + '/b/' + cb.file); - }); - } - }); - } - }); - } - else - e.reply("ignored"); - } - else - e.reply("ignore"); - } - })); -}; - -const getLink = (url, force, userlevel, cb) => { - const yt = /https?:\/\/(www\.)?youtu(\.be\/|be\.com\/)((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi; - const sc = /https?:\/\/(www\.)?(soundcloud\.com|snd\.sc)(\/\S*)(\/\S*)/gi; - checkRepost(url, cbcr => { - var tmpdest = uuid.v1().split('-')[0]; - if(cbcr === true) { - var dat = fs.createWriteStream(process.cwd() + '/b/' + tmpdest); - var info; - if(url.match(yt)) { // ytdl - ytdl.getInfo(url, (err, inf) => { - if(!err) { - var title = inf.title; - var iurl = inf.thumbnail_url; //JSON.parse(inf.player_response).videoDetails.thumbnail.thumbnails[0].url.split('?')[0]; - try { - dlformat = { filter: (format) => { return format.container === 'webm'; } }; - ytdl.downloadFromInfo(inf, dlformat) - .on('response', (res) => { - if( ( res.headers['content-length'] <= cfg.main.maxFileSize.val ) || force || ( userlevel >= 60 && res.headers['content-length'] <= (cfg.main.maxFileSize.val * 2) ) ) { - info = { - type: 'youtube', - title: title, - mime: 'video/webm', - ext: 'webm', - thumb: iurl - }; - } - else { - res.destroy(); - dat.end(); - return cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+formatSize(res.headers['content-length'])+'), max '+formatSize( ( userlevel >= 60?(cfg.main.maxFileSize.val*2):cfg.main.maxFileSize.val ) )+' allowed' }); - } - }) - .on('error', (err) => { - dat.end(); - return cb({ success: false, file: tmpdest, msg: err.message }); - }) - .pipe(dat); - } - catch(ex) { - dat.end(); - return cb({ success: false, file: tmpdest, msg: ex.message }); - } - } - }); - } - else if(url.match(sc)) { // scdl - request('https://api.soundcloud.com/resolve.json?client_id=' + cfg.main.scclientid.val + '&url=' + url, (err, res, body) => { - if(!err && res.statusCode === 200) { - var data = JSON.parse(body); - request(data.stream_url + ((data.stream_url.indexOf('?') === -1)?'?':'&') + 'client_id=' + cfg.main.scclientid.val) - .pipe(dat); - info = { - type: 'soundcloud', - title: data.title, - mime: 'audio/mpeg', - ext: 'mp3', - thumb: (data.artwork_url !== null)?data.artwork_url.replace('large.jpg', 't300x300.jpg'):null - }; - } - else { - dat.end(); - return cb({ success: false, file: tmpdest, msg: 'f0ck sc-api' }); - } - }); - } - else { // various - cloudscraper.request({ - method: 'GET', - url: url, - encoding: null, - }, - (err, res, data) => { - if(!err) { - var type = res.headers['content-type'].split(";")[0]; - if(cfg.main.allowedMimes.val.hasOwnProperty(type)) { - if( ( data.length <= cfg.main.maxFileSize.val ) || force || ( userlevel >= 60 && data.length <= (cfg.main.maxFileSize.val * 2) ) ) { - var s = new Readable; - s.push(data); - s.push(null); - s.pipe(dat); - info = { - type: 'other', - title: path.parse(url).base, - mime: type, - ext: cfg.main.allowedMimes[type], - thumb: null - }; - } - else { - dat.end(); - return cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+formatSize(data.length)+'), max '+formatSize( ( userlevel >= 60?(cfg.main.maxFileSize.val*2):cfg.main.maxFileSize.val ) )+' allowed' }); - } - } - else { - dat.end(); - return cb({ success: false, file: tmpdest, msg: 'irgendwas mit mime oder so.' }); - } - } - else { - dat.end(); - return cb({ success: false, file: tmpdest, msg: 'nope.' }); - } - }); - } - - dat - .on('finish', () => { - var size = dat.bytesWritten; - dat.end(); - if( ( size <= cfg.main.maxFileSize.val ) || force || ( userlevel >= 60 && size <= (cfg.main.maxFileSize.val * 2) ) ) { - fs.stat(process.cwd() + '/b/' + tmpdest, (err, stat) => { - if(!err && stat.isFile() && stat.size > 300) { - getCheckSum(process.cwd() + '/b/' + tmpdest, (cbcs) => { - checkRepostCheckSum(cbcs, (cbcrcs) => { - if(cbcrcs === true) { - var mime = fileType(readChunk.sync(process.cwd() + '/b/' + tmpdest, 0, 262)); - info.ext = mime.ext; - info.mime = mime.mime; - if(cfg.main.allowedMimes.val.hasOwnProperty(mime.mime) || info.type === 'soundcloud') - return cb({ success: true, info: info, size: size, file: process.cwd() + '/b/' + tmpdest, checksum: cbcs }); - else - return cb({ success: false, file: tmpdest, msg: 'lol, go f0ck yourself ('+mime.mime+')' }); - } - else - return cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.main.url.val+'/'+cbcrcs }); - }); - }); - } - else - return cb({ success: false, file: tmpdest, msg: 'nope' }); - }); - } - else - return cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+formatSize(size)+'), max '+formatSize( ( userlevel >= 60?(cfg.main.maxFileSize.val*2):cfg.main.maxFileSize.val ) )+' allowed' }); - }) - .on('error', err => { - return cb({ success: false, file: tmpdest, msg: err }); - }); - } - else - return cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.main.url.val+'/'+cbcr }); - }); -}; diff --git a/src/inc/trigger/parser_new.mjs b/src/inc/trigger/parser_new.mjs deleted file mode 100644 index 075d576..0000000 --- a/src/inc/trigger/parser_new.mjs +++ /dev/null @@ -1,119 +0,0 @@ -import { cfg } from "../cfg"; -import sql from "../sql"; -import * as lib from "./inc/parser"; - -import fs from "fs"; -//import fetch from "node-fetch"; -import fetch from "../fetch"; -import { promisify } from "util"; -import { execFile as ef } from "child_process"; - -const execFile = promisify(ef) - , bin = process.cwd() + "/bin/youtube-dl" - , b = process.cwd() + "/b" - , _args = [ "--dump-json" ] - , regex = /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi; - -export default bot => { - bot._trigger.set("parser", new bot.trigger({ - call: regex, - f: e => { - if(e.channel !== "#kbot-dev" && !e.message.match(/(!|-)f0ck/i)) - return; - if(e.message.match(/(!|-)ignore/)) - return e.reply("ignored"); - - const tmp = e.message.match(regex); // get links - Promise.all(tmp.map(link => execFile(bin, [...[link], ..._args]))) - .then(data => data.map(d => JSON.parse(d.stdout))) - .then(d => d.map(data => data.direct ? { - thumbnail: "", - link: data.url, - file: data.title, - format: [{ - ext: data.ext, - note: "direct", - url: data.url, - size: 0, - rsize: 0 - }] - } : { - thumbnail: data.thumbnail, - link: data.webpage_url, - file: data.id, - format: data.formats - .filter(f => { - if(f.hasOwnProperty("fragments")) - return false; - if(!["webm", "mp4", "mp3"].includes(f.ext)) - return false; - if(f.filesize > cfg.main.maxFileSize.val && f.ext !== "mp3") - return false; - if(/playlist/i.test(f.url)) - return false; - - if(e.self.debug) - e.reply(`${f.ext} - ${f.url} - ${f.format}`); - return f; - }) - .splice(-1, 1) - .map(f => ({ - ext: f.ext, - note: f.format_note, - url: f.url, - size: lib.formatSize(f.filesize), - rsize: f.filesize - })) - })) - .then(d => d.map(data => { - if(data.format.length === 0) - return e.reply("no filters found, f0ck! D:"); - fetch(data.format[0].url, { size: cfg.main.maxFileSize.val }) - .then(res => { - if(res.headers["content-length"] >= cfg.main.maxFileSize.val) - return e.reply(`file too large soos! D; (~${lib.formatSize(res.headers["content-length"])} / ~${lib.formatSize(cfg.main.maxFileSize.val)})`); - const uuid = lib.getUUID(); - const file = `${b}/${uuid}.${data.format[0].ext}`; - const dest = fs.createWriteStream(file); - const start = new Date(); - res.body.pipe(dest); - let t; - dest.on("open", () => { - e.reply(`downloading ${data.file}...`); - t = setInterval(() => { - const size = fs.statSync(file).size; - if(size >= cfg.main.maxFileSize.val) { - e.reply(`file too large lol! D: (${lib.formatSize(size)})`); - res.body.unpipe(dest); - dest.destroy(); - fs.unlinkSync(file); - clearInterval(t); - t = false; - } - else { - if(e.self.debug) - e.reply(`${data.file}: ${lib.formatSize(size)}`); - } - }, 2000); - }); - dest.on("close", blah => { - if(t) { - clearInterval(t); - const size = fs.statSync(file).size; - const time = ~~((new Date() - start) / 1000); - e.reply(`gef0ckt lol: ${data.file} -> ${uuid}.${data.format[0].ext}, ~${lib.formatSize(size)}, speed: ${lib.calcSpeed(size, time)}`); - } - else { - // recursive - } - }); - }) - .catch(err => { - console.error(err); - }); - })) - .catch(err => e.reply(JSON.stringify(err)) - ); - } - })); -};