This commit is contained in:
Flummi
2017-11-26 13:51:08 +01:00
parent 6f8145c5aa
commit fdafc44044
6 changed files with 54 additions and 26 deletions

View File

@ -1,13 +1,13 @@
const util = require("util")
, fs = require("fs")
, ytdl = require("youtube-dl");
const fs = require("fs")
, ytdl = require("ytdl-core");
const _args = [
"--no-progress",
"--no-warnings",
"--no-check-certificate",
"--dump-json"
//"--max-filesize 500m",
'-o "./tmp/%(title)s.%(ext)s"'
//'-o "./tmp/%(title)s.%(ext)s"'
];
@ -21,13 +21,14 @@ module.exports = bot => {
if(e.network === "n0xy" && e.channel === "#kbot-dev") {
const links = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi);
Promise.all(links.map(link => checkRepost(link))) // repostcheck
.then(res => Promise.all(res.map(link => ytdl_info(link, _args)))) // info holen
.then(
res => Promise.all(res.map(t => { e.reply(t.res); return t.link; })),
err => Promise.all(err.map(t => { e.reply(t.err); return t.link; }))
)
.then(link => {
e.reply(`link: ${link}`);
.then(res => Promise.all(res.map(link => ytdl(link, _args)))) // info holen
.then(res => {
res.forEach(info => {
e.reply(info);
});
})
.catch(err => {
e.reply(err);
});
}
}
@ -38,13 +39,4 @@ function checkRepost(link) {
return new Promise((resolve, reject) => {
resolve(link);
});
}
function ytdl_info(link, args) {
return new Promise((resolve, reject) => {
ytdl.getInfo(link, args, (err, res) => {
if(err) reject({ link: link, err: err });
if(res) resolve({ link: link, res: res });
});
});
}

View File

@ -146,7 +146,7 @@ module.exports = bot => {
let args = e.message.trim().split(" ");
args.shift();
args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0];
e.reply(`Assuming [b]${args[0]}'s[/b] gender... they're a ${data.genders[~~(Math.random() * data.genders.length)]}.`);
e.reply(`Assuming [b]${args[0]}'s[/b] gender... it's a ${data.genders[~~(Math.random() * data.genders.length)]}.`);
}
});