Grosse refonte + Ajout /amp + Correctif /crack

This commit is contained in:
Zachary Guénot
2023-05-28 02:55:30 +02:00
parent ef58e007bc
commit 011b0d6d68
17 changed files with 233 additions and 92 deletions

96
commands/global/amp.js Normal file
View File

@@ -0,0 +1,96 @@
const { SlashCommandBuilder } = require('discord.js')
require('dotenv').config()
require('require-all')(__dirname + '/../../utilsAMP')
module.exports = {
data: new SlashCommandBuilder().setName('amp').setDescription('Accède à mon panel de jeu AMP !')
//.addSubcommand(subcommand => subcommand.setName('api_info').setDescription('Prints info about the API.'))
.addSubcommand(subcommand => subcommand.setName('login').setDescription("Connectez-vous avant d'effectuer une autre commande !")
.addStringOption(option => option.setName('username').setDescription("Nom d'Utilisateur").setRequired(true))
.addStringOption(option => option.setName('password').setDescription('Mot de Passe').setRequired(true))
.addBooleanOption(option => option.setName('remember').setDescription('Mémoriser les identifiants').setRequired(true))
.addStringOption(option => option.setName('otp').setDescription('Code de double authentification')))
.addSubcommandGroup(subcommandgroup => subcommandgroup.setName('instances').setDescription('Intéragir avec les instances AMP.')
.addSubcommand(subcommand => subcommand.setName('manage').setDescription('Gérer une instance.')
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))
.addSubcommand(subcommand => subcommand.setName('list').setDescription('Liste toutes les instances disponibles.'))
.addSubcommand(subcommand => subcommand.setName('restart').setDescription('Redémarre une instance.')
.addStringOption(option => option.setName('name').setDescription("Nom de l'instance").setRequired(true)))),
async execute(interaction) {
const base_url = process.env.AMP_HOST + '/API'
if (interaction.options.getSubcommand() == 'login') {
await interaction.deferReply({ ephemeral: true })
let result = await login(base_url, interaction.options)
//if (result) return await interaction.followUp({ content: `Sorry, something bad happened !` })
//else return await interaction.followUp({ content: `You are successfully logged in as **${result}** !` })
//await interaction.editReply(`You are successfully logged in as **${response.data.userInfo.Username}** !`)
if (result.status === 'success') return await interaction.editReply(`You are successfully logged in as **${result.data.userInfo.Username}** !`)
else if (result.status === 'fail') {
return await interaction.editReply(`Sorry, something bad happened ! (${result.data.Message})`)
}
else if (result.status === 'error') {
return await interaction.editReply(`Sorry, there has been an error ! (${result.data.error_code})`)
}
}
/*else if (interaction.options.getSubcommand() == 'api_info') {
await interaction.deferReply()
let url = `${base_url}/Core/GetAPISpec`
let headers = { headers: { SESSIONID: localStorage.getItem("AMP_sessionID") } }
try {
let response = await axios.post(url, headers)
console.log(response.data)
await interaction.editReply('Ok !')
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
}*/
else if (interaction.options.getSubcommandGroup() == 'instances') {
if (interaction.options.getSubcommand() == 'manage') {
await interaction.deferReply()
let friendlyName = interaction.options.getString('name')
let url = `${base_url}/ADSModule/GetInstances`
let headers = { SESSIONID: localStorage.getItem("AMP_sessionID") }
try {
let response = await axios.post(url, headers)
response.data.result[0].AvailableInstances.forEach(element => {
if (element.FriendlyName == friendlyName) { return instanceID = element.InstanceID }
})
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
if (!instanceID) { await interaction.editReply(`Aucune instance trouv<75>e au nom de ${friendlyName} !`) }
url = `${base_url}/ADSModule/ManageInstance`
headers = { SESSIONID: localStorage.getItem("AMP_sessionID"),
InstanceId: instanceID }
try {
let response = await axios.post(url, headers)
console.log(response)
await interaction.editReply('Ok !')
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
}
else if (interaction.options.getSubcommand() == 'list') {
await interaction.deferReply()
let url = `${base_url}/ADSModule/GetInstances`
let headers = { SESSIONID: localStorage.getItem("AMP_sessionID") }
try {
let response = await axios.post(url, headers)
console.log(response.data.result[0].AvailableInstances)
await interaction.editReply('Ok !')
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
}
else if (interaction.options.getSubcommand() == 'restart') {
await interaction.deferReply()
let url = `${base_url}/ADSModule/RestartInstance`
let headers = { SESSIONID: localStorage.getItem("AMP_sessionID"),
InstanceName: interaction.options.getString('name') }
try {
let response = await axios.post(url, headers)
console.log(response.data)
await interaction.editReply('Ok !')
} catch (error) { console.log(error), await interaction.editReply("HTTP Error !") }
}
}
}
}

View File

@@ -1,13 +1,11 @@
const { SlashCommandBuilder } = require('discord.js')
const iconv = require('iconv-lite')
const axios = require('axios')
const fs = require('fs')
require('require-all')(__dirname + '/../../utilsCrack')
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",
@@ -26,89 +24,46 @@ var headers2 = {
"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))
try {
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
} catch (error) {
console.error(error)
await interaction.followUp({ content: `Y'a eu une erreur !\n${error.toString()}` })
}
}
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))
try {
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
} catch (error) {
console.error(error)
await interaction.followUp({ content: `Y'a eu une erreur !\n${error.toString()}` })
}
}
async function torrent(url, headers) {
let response = await fetch(url, { headers, body: null, method: "GET" })
.catch(error => console.error(error))
try {
let body = await response.text()
let file = body.split('<a href="')[2].split('">')[0]
return file
} catch (error) {
console.error(error)
await interaction.followUp({ content: `Y'a eu une erreur !\n${error.toString()}` })
}
}
async function download(url, file, headers) {
let path = `./cracks/${file}`
let writer = fs.createWriteStream(path)
try {
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
} catch (error) {
console.error(error)
await interaction.followUp({ content: `Y'a eu une erreur !\n${error.toString()}` })
}
}
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)),
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 game
if (games.length === 0) return await interaction.followUp({ content: `J'ai rien trouvé pour "${query}" !` })
else 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]
console.log(interaction.user.id)
let url = await repo(game, 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 })
fs.unlink(path, (err) => { if (err) throw err })
}
}

View File

@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require('discord.js')
const generatePlayer = require('../../utils/generatePlayer.js')
const generatePlayer = require('../../utilsPlayer/generate.js')
module.exports = {
data: new SlashCommandBuilder()