Feature: QBitTorrent aproval to start downloading.

master
masterhc 9 months ago
parent 330113b11b
commit f9aa08f7ad

@ -3,7 +3,7 @@ const STRIKES = require('../models/strikes');
const roleRulesM = require('../models/autoRoleRule'); const roleRulesM = require('../models/autoRoleRule');
const feedsM = require('../models/feeds'); const feedsM = require('../models/feeds');
const xmlparser = require('xml-js'); const xmlparser = require('xml-js');
const {DiscordAPI, getRules, confirmArgsForYTFeed} = require('../lib') const {DiscordAPI, getRules, confirmArgsForYTFeed, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Random} = require('../lib')
exports.home = async (req,res)=> exports.home = async (req,res)=>
{ {
res.render('home.ejs'); res.render('home.ejs');
@ -441,4 +441,81 @@ exports.pp = (req, res) =>
exports.tos = (req, res) => exports.tos = (req, res) =>
{ {
res.render('tos.ejs') res.render('tos.ejs')
}
exports.torrent = (bot)=>
{
return async (req, res) =>
{
const user = await bot.users.cache.get('186540961650835456');
const embed = new EmbedBuilder()
embed.setFooter({text:'Rem-chan on ', iconURL:"https://i.imgur.com/g6FSNhL.png"})
embed.setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'});
embed.setColor(0x4287f5);
embed.setTimestamp();
embed.setTitle('Torrent Added:');
embed.addFields({name:req.params.name, value:" "},
{name:'Size', value:`${req.params.size/1024/1024}MB`},
{name:'From:', value:req.params.category});
let random = Random(5);
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('Redirect'+random)
.setLabel('Aprove')
.setStyle(ButtonStyle.Success),
)
.addComponents(
new ButtonBuilder()
.setCustomId('Remove'+random)
.setLabel('Remove')
.setStyle(ButtonStyle.Danger),
)
const filter = i => i.customId === 'Redirect'+random || i.customId === 'Remove'+random;
let message = await user.send({embeds: [embed], components: [row] });
const collector = message.createMessageComponentCollector({ filter, time: 60000 });
collector.on('collect', async m =>
{
collector.stop();
m.deferUpdate();
if(m.customId === 'Remove'+random) return m.message.delete();
let cookie = await fetch('https://utorrent.wordfights.com/api/v2/auth/login',
{
"headers":
{
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
},
"body":`username=${process.env.qbittorrentusername}&password=${process.env.qbittorrentpassword}`,
"method": "POST"
}
)
.then(handleResponse)
async function handleResponse(response)
{
let headers = [...response.headers.entries()];
headers = headers.filter(i=>i[0]=='set-cookie')[0][1]
return headers
}
await fetch("https://utorrent.wordfights.com/api/v2/torrents/setForceStart", {
"headers": {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"cookie": `${cookie}`,
},
"body": `value=true&hashes=${req.params.id}`,
"method": "POST"
});
});
collector.on('end', async ()=>
{
message.edit({ components: [] });
})
res.json({ok:'OK'})
}
} }

@ -32,6 +32,7 @@ module.exports = (io, bot)=>
router.route('/guilds').get(api.guilds(bot)); router.route('/guilds').get(api.guilds(bot));
router.route('/pp').get(api.pp); router.route('/pp').get(api.pp);
router.route('/tos').get(api.tos); router.route('/tos').get(api.tos);
router.route('/api/torrent/:name/:size/:category/:id').post(api.torrent(bot));
router.route('/strikes/:id/:userid/:strikeid?').get(api.strikeDashboard(bot)) router.route('/strikes/:id/:userid/:strikeid?').get(api.strikeDashboard(bot))
.put(api.updateStrikes(bot)) .put(api.updateStrikes(bot))

Loading…
Cancel
Save