Création Repo pour mon bot Le Tamiseur
This commit is contained in:
94
commands/global/crack.js
Normal file
94
commands/global/crack.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const { SlashCommandBuilder } = require('discord.js')
|
||||
const iconv = require('iconv-lite')
|
||||
const axios = require('axios')
|
||||
const fs = require('fs')
|
||||
|
||||
var headers1 = {
|
||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"x-requested-with": "XMLHttpRequest"
|
||||
}
|
||||
|
||||
var headers2 = {
|
||||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||
"accept-language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",
|
||||
"cache-control": "no-cache",
|
||||
"pragma": "no-cache",
|
||||
"sec-ch-ua": "\"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"110\", \"Opera GX\";v=\"96\"",
|
||||
"sec-ch-ua-mobile": "?0",
|
||||
"sec-ch-ua-platform": "\"Windows\"",
|
||||
"sec-fetch-dest": "document",
|
||||
"sec-fetch-mode": "navigate",
|
||||
"sec-fetch-site": "none",
|
||||
"sec-fetch-user": "?1",
|
||||
"upgrade-insecure-requests": "1",
|
||||
"cookie": "online_fix_auth=gAAAAABkKM0s9WNLe_V6euTnJD7UQjppVty9B7OOyHBYOyVcbcejj8F6KveBcLxlf3mlx_vE7JEFPHlrpj-Aq6BFJyKPGzxds_wpcPV2MdXPyDGQLsz4mAvt3qgTgGg25MapWo_fSIOMiAAsF4Gv_uh4kUOiR_jgbHCZWJGPgpNQwU2HFFyvahYR6MzR7nYE9-fCmrev3obkRbro43vIVTTX4UyJMRHadrsY5Q-722TzinCZVmAuJfc=; dle_password=89465c26673e0199e5272e4730772c35; _ym_uid=1670534560361937997; _ym_d=1680394955; _ym_isad=2; dle_user_id=2619796; PHPSESSID=3v8sd281sr0n1n9f1p66q25sa2",
|
||||
"Referer": "https://online-fix.me/",
|
||||
"Referrer-Policy": "strict-origin-when-cross-origin"
|
||||
}
|
||||
|
||||
async function search(query, headers) {
|
||||
let body = await fetch("https://online-fix.me/engine/ajax/search.php", { headers, body: `query=${query}`, method: "POST" })
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(arrayBuffer => { return iconv.decode(Buffer.from(arrayBuffer), 'win1251') })
|
||||
.catch(error => console.error(error))
|
||||
let matches = body.split('</div>')[1].split('<span class="seperator fastfullsearch">')[0].split('</a>')
|
||||
let games = []
|
||||
matches.pop()
|
||||
matches.forEach(async match => {
|
||||
let name = match.split('"><span class="searchheading">')[1].split('</span>')[0].slice(0, -8)
|
||||
let link = match.split('<a href="')[1].split('"><span class="searchheading">')[0]
|
||||
games.push({ name, link })
|
||||
})
|
||||
return games
|
||||
}
|
||||
|
||||
async function repo(game, headers) {
|
||||
let body = await fetch(game.link, { headers, body: null, method: "GET" })
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(arrayBuffer => { return iconv.decode(Buffer.from(arrayBuffer), 'win1251') })
|
||||
.catch(error => console.error(error))
|
||||
let name = body.split('https://uploads.online-fix.me:2053/torrents/')[1].split('"')[0]
|
||||
let url = `https://uploads.online-fix.me:2053/torrents/${name}`
|
||||
return url
|
||||
}
|
||||
|
||||
async function torrent(url, headers) {
|
||||
let response = await fetch(url, { headers, body: null, method: "GET" })
|
||||
.catch(error => console.error(error))
|
||||
let body = await response.text()
|
||||
let file = body.split('<a href="')[2].split('">')[0]
|
||||
return file
|
||||
}
|
||||
|
||||
async function download(url, file, headers) {
|
||||
let path = `./cracks/${file}`
|
||||
let writer = fs.createWriteStream(path)
|
||||
await axios({ url: url + file, method: 'GET', responseType: 'stream', headers }).then(response => {
|
||||
return new Promise((resolve, reject) => {
|
||||
response.data.pipe(writer)
|
||||
let error = null
|
||||
writer.on('error', err => {
|
||||
error = err
|
||||
writer.close()
|
||||
reject(err)
|
||||
})
|
||||
writer.on('close', () => { if (!error) resolve(true) })
|
||||
})
|
||||
}).catch(error => console.error(error))
|
||||
return path
|
||||
}
|
||||
|
||||
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, headers1)
|
||||
let url = await repo(games[0], headers2)
|
||||
let file = await torrent(url, headers2)
|
||||
let path = await download(url, file, headers2)
|
||||
await interaction.followUp({ content: `Voici ce que j'ai trouvé pour "${query}" !`, files: [path] })
|
||||
await fs.unlink(path, (err) => { if (err) throw err })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user