This commit is contained in:
Flummi 2018-09-03 21:03:58 +02:00
parent 2c832f2014
commit 37fc886839
2 changed files with 18 additions and 9 deletions

View File

@ -48,6 +48,7 @@ export class irc extends EventEmitter {
this.server = { this.server = {
set: this.set, set: this.set,
motd: "", motd: "",
debug: false,
me: {}, me: {},
channel: [], channel: [],
user: new Map() user: new Map()

View File

@ -11,20 +11,21 @@ const execFile = promisify(ef);
const bin = process.cwd() + "/bin/youtube-dl"; const bin = process.cwd() + "/bin/youtube-dl";
const b = process.cwd() + "/b"; const b = process.cwd() + "/b";
const _args = [ "--dump-json" ]; const _args = [ "--dump-json" ];
const regex = /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi;
export default bot => { export default bot => {
bot._trigger.set("parser", new bot.trigger({ bot._trigger.set("parser", new bot.trigger({
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi, call: regex,
f: e => { f: e => {
if(e.channel !== "#kbot-dev" && !e.message.match(/(!|-)f0ck/i)) if(e.channel !== "#kbot-dev" && !e.message.match(/(!|-)f0ck/i))
return; return;
if(e.message.match(/(!|-)ignore/)) if(e.message.match(/(!|-)ignore/))
return e.reply("ignored"); return e.reply("ignored");
const tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links const tmp = e.message.match(regex); // get links
tmp.forEach(link => execFile(bin, [...[link], ..._args]) Promise.all(tmp.map(link => execFile(bin, [...[link], ..._args])))
.then(({ stdout }) => JSON.parse(stdout)) .then(data => data.map(d => JSON.parse(d.stdout)))
.then(data => data.direct ? { .then(d => d.map(data => data.direct ? {
thumbnail: "", thumbnail: "",
link: data.url, link: data.url,
file: data.title, file: data.title,
@ -49,7 +50,9 @@ export default bot => {
return false; return false;
if(/playlist/i.test(f.url)) if(/playlist/i.test(f.url))
return false; return false;
//e.reply(`${f.ext} - ${f.url} - ${f.format}`);
if(e.self.debug)
e.reply(`${f.ext} - ${f.url} - ${f.format}`);
return f; return f;
}) })
.splice(-1, 1) .splice(-1, 1)
@ -60,8 +63,8 @@ export default bot => {
size: lib.formatSize(f.filesize), size: lib.formatSize(f.filesize),
rsize: f.filesize rsize: f.filesize
})) }))
}) }))
.then(data => { .then(d => d.map(data => {
if(data.format.length === 0) if(data.format.length === 0)
return e.reply("no filters found, f0ck! D:"); return e.reply("no filters found, f0ck! D:");
fetch(data.format[0].url, { size: cfg.main.maxFileSize.val }) fetch(data.format[0].url, { size: cfg.main.maxFileSize.val })
@ -83,6 +86,10 @@ export default bot => {
clearInterval(t); clearInterval(t);
t = false; t = false;
} }
else {
if(e.self.debug)
e.reply(`${data.file}: ${lib.formatSize(size)}`);
}
}, 2000); }, 2000);
}); });
dest.on("close", blah => { dest.on("close", blah => {
@ -98,7 +105,8 @@ export default bot => {
.catch(err => { .catch(err => {
console.error(err); console.error(err);
}); });
}).catch(err => e.reply(JSON.stringify(err))) }))
.catch(err => e.reply(JSON.stringify(err))
); );
} }
})); }));