BugFix: Only initiate download on inactivity, not on collection stop.

master
masterhc 8 months ago
parent ab9392e530
commit d132846caf

@ -456,7 +456,7 @@ exports.torrent = (bot)=>
embed.addFields({name:req.params.name, value:" "}, embed.addFields({name:req.params.name, value:" "},
{name:'Size', value:`${req.params.size/1024/1024}MB`}, {name:'Size', value:`${req.params.size/1024/1024}MB`},
{name:'From:', value:req.params.category}); {name:'From:', value:req.params.category});
let random = Random(5); const random = Random(5);
const row = new ActionRowBuilder() const row = new ActionRowBuilder()
.addComponents( .addComponents(
new ButtonBuilder() new ButtonBuilder()
@ -474,27 +474,27 @@ exports.torrent = (bot)=>
new ButtonBuilder() new ButtonBuilder()
.setCustomId('AproveLater'+random) .setCustomId('AproveLater'+random)
.setLabel('Aprove Later') .setLabel('Aprove Later')
.setStyle(ButtonStyle.Success), .setStyle(ButtonStyle.Secondary),
) )
const filter = i => i.customId === 'Redirect'+random || i.customId === 'Remove'+random; const filter = i => i.customId.includes(random)
let message = await user.send({embeds: [embed], components: [row] }); let message = await user.send({embeds: [embed], components: [row] });
const collector = message.createMessageComponentCollector({ filter, time: 5*60000 }); const collector = message.createMessageComponentCollector({ filter, time: 5*60000 });
const Cookie = await getCookie();
let manualStop = false;
collector.on('collect', async m => collector.on('collect', async m =>
{ {
if(!Cookie) return
manualStop = true;
collector.stop(); collector.stop();
m.deferUpdate(); m.deferUpdate();
let cookie = await getCookie(); if(m.customId.includes('Remove'))
if(!cookie) return
if(m.customId === 'Remove'+random)
{ {
await fetch("https://utorrent.wordfights.com/api/v2/torrents/delete", { await fetch("https://utorrent.wordfights.com/api/v2/torrents/delete", {
"headers": { "headers": {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8", "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"cookie":cookie, "cookie":Cookie,
}, },
"referrerPolicy": "same-origin", "referrerPolicy": "same-origin",
"body": `hashes=${req.params.id}&deleteFiles=false`, "body": `hashes=${req.params.id}&deleteFiles=false`,
@ -504,11 +504,11 @@ exports.torrent = (bot)=>
}); });
return m.message.delete(); return m.message.delete();
} }
if(m.customId === 'AproveLater'+random) return if(m.customId.includes('AproveLater')) return
await fetch("https://utorrent.wordfights.com/api/v2/torrents/setForceStart", { await fetch("https://utorrent.wordfights.com/api/v2/torrents/setForceStart", {
"headers": { "headers": {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8", "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"cookie": cookie, "cookie": Cookie,
}, },
"body": `value=true&hashes=${req.params.id}`, "body": `value=true&hashes=${req.params.id}`,
"method": "POST" "method": "POST"
@ -517,10 +517,11 @@ exports.torrent = (bot)=>
collector.on('end', async ()=> collector.on('end', async ()=>
{ {
message.edit({ components: [] }); message.edit({ components: [] });
if(manualStop) return
await fetch("https://utorrent.wordfights.com/api/v2/torrents/setForceStart", { await fetch("https://utorrent.wordfights.com/api/v2/torrents/setForceStart", {
"headers": { "headers": {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8", "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"cookie": cookie, "cookie": Cookie,
}, },
"body": `value=true&hashes=${req.params.id}`, "body": `value=true&hashes=${req.params.id}`,
"method": "POST" "method": "POST"

Loading…
Cancel
Save