From 43a78f99398356776c5af2a99150c64ad68f069c Mon Sep 17 00:00:00 2001 From: loicbersier Date: Mon, 7 Sep 2020 17:37:22 +0200 Subject: [PATCH] Add proxy options Signed-off-by: loicbersier --- commands/fun/petittube.js | 40 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/commands/fun/petittube.js b/commands/fun/petittube.js index ac6cffc5..38e93c68 100644 --- a/commands/fun/petittube.js +++ b/commands/fun/petittube.js @@ -1,4 +1,5 @@ const { Command } = require('discord-akairo'); +const { proxy } = require('../../config.json'); const fetch = require('node-fetch'); const cheerio = require('cheerio'); @@ -8,6 +9,18 @@ class PetitTubeCommand extends Command { aliases: ['petittube', 'pt'], category: 'fun', clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'], + args: [ + { + id: 'proxy', + match: 'option', + flag: ['--proxy'], + }, + { + id: 'listproxy', + match: 'flag', + flag: ['--listproxy', '--proxylist'] + } + ], description: { content: 'Fetch a video from https://petittube.com/', usage: '', @@ -16,7 +29,25 @@ class PetitTubeCommand extends Command { }); } - async exec(message) { + async exec(message, args) { + if (args.listproxy) { + let proxys = []; + + let i = 0; + proxy.forEach(proxy => { + i++; + proxys.push(`[${i}] ${ proxy.hideip ? '[IP HIDDEN]' : proxy.ip.substring(0, proxy.ip.length - 5)} - ${proxy.country}`); + }); + + const Embed = this.client.util.embed() + .setColor(message.member ? message.member.displayHexColor : 'NAVY') + .setTitle('List of available proxy') + .setDescription(proxys.join('\n')) + .setFooter('You can help me get more proxy by either donating to me or providing a proxy for me'); + + return message.channel.send(Embed); + } + const response = await fetch('https://petittube.com/'); const body = await response.text(); @@ -24,7 +55,12 @@ class PetitTubeCommand extends Command { const url = $('iframe')[0].attribs.src; - this.client.commandHandler.runCommand(message, this.client.commandHandler.findCommand('download'), { link: new URL(url), proxy: 1, spoiler: !message.channel.nsfw, caption: message.channel.nsfw ? '' : 'Video might be NSFW as always, be careful!'}); + if (args.proxy) { + args.proxy = args.proxy -1; + if (!proxy[args.proxy]) args.proxy = 0; + } + + this.client.commandHandler.runCommand(message, this.client.commandHandler.findCommand('download'), { link: new URL(url), proxy: args.proxy, spoiler: !message.channel.nsfw, caption: message.channel.nsfw ? '' : 'Video might be NSFW as always, be careful!'}); } } module.exports = PetitTubeCommand; \ No newline at end of file