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 = {
set: this.set,
motd: "",
debug: false,
me: {},
channel: [],
user: new Map()

View File

@ -11,20 +11,21 @@ const execFile = promisify(ef);
const bin = process.cwd() + "/bin/youtube-dl";
const b = process.cwd() + "/b";
const _args = [ "--dump-json" ];
const regex = /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi;
export default bot => {
bot._trigger.set("parser", new bot.trigger({
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
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(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
tmp.forEach(link => execFile(bin, [...[link], ..._args])
.then(({ stdout }) => JSON.parse(stdout))
.then(data => data.direct ? {
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,
@ -49,7 +50,9 @@ export default bot => {
return false;
if(/playlist/i.test(f.url))
return false;
//e.reply(`${f.ext} - ${f.url} - ${f.format}`);
if(e.self.debug)
e.reply(`${f.ext} - ${f.url} - ${f.format}`);
return f;
})
.splice(-1, 1)
@ -60,8 +63,8 @@ export default bot => {
size: lib.formatSize(f.filesize),
rsize: f.filesize
}))
})
.then(data => {
}))
.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 })
@ -83,6 +86,10 @@ export default bot => {
clearInterval(t);
t = false;
}
else {
if(e.self.debug)
e.reply(`${data.file}: ${lib.formatSize(size)}`);
}
}, 2000);
});
dest.on("close", blah => {
@ -98,7 +105,8 @@ export default bot => {
.catch(err => {
console.error(err);
});
}).catch(err => e.reply(JSON.stringify(err)))
}))
.catch(err => e.reply(JSON.stringify(err))
);
}
}));