From d132846caf1cdaa53bbcba96e48023af89c57e6c Mon Sep 17 00:00:00 2001 From: masterhc Date: Mon, 29 Jul 2024 15:43:01 +0100 Subject: [PATCH] BugFix: Only initiate download on inactivity, not on collection stop. --- controller/api.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/controller/api.js b/controller/api.js index 45d153a..b82067e 100644 --- a/controller/api.js +++ b/controller/api.js @@ -456,7 +456,7 @@ exports.torrent = (bot)=> 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 random = Random(5); const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() @@ -474,27 +474,27 @@ exports.torrent = (bot)=> new ButtonBuilder() .setCustomId('AproveLater'+random) .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] }); const collector = message.createMessageComponentCollector({ filter, time: 5*60000 }); + const Cookie = await getCookie(); + let manualStop = false; collector.on('collect', async m => { + if(!Cookie) return + manualStop = true; collector.stop(); m.deferUpdate(); - let cookie = await getCookie(); - - if(!cookie) return - - if(m.customId === 'Remove'+random) + if(m.customId.includes('Remove')) { await fetch("https://utorrent.wordfights.com/api/v2/torrents/delete", { "headers": { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", - "cookie":cookie, + "cookie":Cookie, }, "referrerPolicy": "same-origin", "body": `hashes=${req.params.id}&deleteFiles=false`, @@ -504,11 +504,11 @@ exports.torrent = (bot)=> }); 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", { "headers": { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", - "cookie": cookie, + "cookie": Cookie, }, "body": `value=true&hashes=${req.params.id}`, "method": "POST" @@ -517,10 +517,11 @@ exports.torrent = (bot)=> collector.on('end', async ()=> { message.edit({ components: [] }); + if(manualStop) return await fetch("https://utorrent.wordfights.com/api/v2/torrents/setForceStart", { "headers": { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", - "cookie": cookie, + "cookie": Cookie, }, "body": `value=true&hashes=${req.params.id}`, "method": "POST"