Files
bot_Tamiseur/commands/global/crack.js
2023-06-15 20:03:46 +02:00

58 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { SlashCommandBuilder, EmbedBuilder, hyperlink } = require('discord.js')
const fs = require('fs')
const appDir = require('path').dirname(require.main.filename)
require('require-all')(appDir + '/utilsCrack')
module.exports = {
data: new SlashCommandBuilder().setName('crack').setDescription('Télécharge un crack sur le site online-fix.me !')
.addStringOption(option => option.setName('jeu').setDescription('Quel jeu tu veux DL ?').setRequired(true)),
async execute(interaction) {
await interaction.deferReply()
let query = interaction.options.getString('jeu')
let games = await search(query, headers.h1)
if (!Array.isArray(games)) {
if (games.toString() == "TypeError: Cannot read properties of undefined (reading 'split')") return interaction.followUp({ content: `J'ai rien trouvé pour "${query}" !` })
else return interaction.followUp({ content: "Une erreur s'est produite ! ```" + games + "```" })
}
let game
if (games.length > 1) {
games = games.slice(0, 9)
let list = ''
for (let i = 0; i < games.length; i++) list += `\n${i + 1}. ${games[i].name} (${games[i].link})`
let message = await interaction.followUp({ content: `J'ai trouvé plusieurs jeux pour "${query}" ! ${list}` })
let emojis = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣']
for (let i = 0; i < games.length; i++) await message.react(emojis[i])
// Wait for a reaction to be added by the interaction author.
const filter = (reaction, user) => {
return emojis.includes(reaction.emoji.name) && user.id === interaction.user.id
}
let collected = await message.awaitReactions({ filter, max: 1, time: 5000, errors: ['time'] })
.catch(() => { return interaction.followUp({ content: 'T\'as mis trop de temps à choisir !' }) })
console.log(collected)
if (!collected.first) return
let reaction = collected.first()
let index = emojis.indexOf(reaction.emoji.name)
game = games[index]
}
else game = games[0]
let url = await repo(game, headers.h2)
let file = await torrent(url, headers.h2)
let path = await download(url, file, headers.h2)
let link = await magnet(path)
let embed = new EmbedBuilder()
.setColor('#ffc370')
.setTitle(game.name)
.setURL(game.link)
.setDescription(`Voici ce que j'ai trouvé pour "${query}".\nTu peux aussi cliquer sur [ce lien](https://angels-dev.fr/magnet/${link}) pour pouvoir télécharger le jeu direct !`)
await interaction.followUp({ embeds: [embed], files: [path] })
//fs.unlink(path, (err) => { if (err) throw err })
}
}