meh
This commit is contained in:
parent
aaca4e161d
commit
1aeed75ae3
|
@ -1,30 +1,35 @@
|
||||||
const util = require('util')
|
const util = require("util")
|
||||||
, fs = require('fs')
|
, fs = require("fs")
|
||||||
, ytdl = util.promisify(require('youtube-dl').getInfo);
|
, ytdl = require("youtube-dl");
|
||||||
|
|
||||||
const args = [
|
const _args = [
|
||||||
"--no-progress",
|
"--no-progress",
|
||||||
"--no-warnings",
|
"--no-warnings",
|
||||||
"--no-check-certificate",
|
"--no-check-certificate",
|
||||||
"--max-filesize 500m",
|
//"--max-filesize 500m",
|
||||||
'-o "./tmp/%(title)s.%(ext)s"'
|
'-o "./tmp/%(title)s.%(ext)s"'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
module.exports = bot => {
|
module.exports = bot => {
|
||||||
bot._trigger.set("parser", {
|
bot._trigger.set("parser", {
|
||||||
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
|
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
|
||||||
level: 0,
|
level: 0,
|
||||||
active: false,
|
active: true,
|
||||||
clients: ["irc"],
|
clients: ["irc"],
|
||||||
f: e => {
|
f: e => {
|
||||||
const links = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi);
|
if(e.network === "n0xy" && e.channel === "#kbot-dev") {
|
||||||
Promise.all(links.map(link => checkRepost(link))) // repostcheck
|
const links = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi);
|
||||||
.then(res => Promise.all(res.map(link => ytdl(link)))) // get informations
|
Promise.all(links.map(link => checkRepost(link))) // repostcheck
|
||||||
.then(res => {
|
.then(res => Promise.all(res.map(link => ytdl_info(link, _args)))) // info holen
|
||||||
res.forEach(data => {
|
.then(
|
||||||
e.reply(data.title);
|
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}`);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -33,4 +38,13 @@ function checkRepost(link) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
resolve(link);
|
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 });
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user