mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 23:36:29 +02:00
233 lines
7.3 KiB
JavaScript
233 lines
7.3 KiB
JavaScript
const { EmbedBuilder } = require("discord.js");
|
|
const db = require("../../fonctions/database.js");
|
|
const embedColor = require("../../fonctions/embedColor.js");
|
|
|
|
module.exports = {
|
|
aliases: ["hack"],
|
|
description: "Supprime un cadenas à une team. (coût : 4reputation)",
|
|
emote: "🔓",
|
|
utilisation: "<team-id>",
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
if (args.length >= 2) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Hack Impossible")
|
|
.setDescription(`❌ Veuillez indiquer l'id une team.`)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
return message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
|
|
const teamID = args[0].toLowerCase();
|
|
|
|
const user = await new Promise((resolve, reject) => {
|
|
db.get(
|
|
`SELECT * FROM users WHERE guildId = ? AND userId = ?`,
|
|
[message.guild.id, message.author.id],
|
|
(err, row) => {
|
|
if (err) reject(err);
|
|
resolve(row);
|
|
},
|
|
);
|
|
});
|
|
const userRep = user.reputation;
|
|
if (userRep < 4) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Hack Impossible")
|
|
.setDescription(
|
|
`❌ Vous n'avez pas assez de reputation. Il faut \`4\` reputation mais vous n'avez que \`${userRep}\` reputation`,
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
return message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
const lastHack = user.lastHack;
|
|
|
|
const team = await new Promise((resolve, reject) => {
|
|
db.get(
|
|
`SELECT * FROM teams WHERE guildId = ? AND id = ?`,
|
|
[message.guild.id, teamID],
|
|
async (err, row) => {
|
|
if (err) reject(err);
|
|
if (!row) {
|
|
return message.reply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle("Erreur")
|
|
.setDescription("❌ La team spécifié n'existe pas.")
|
|
.setColor(
|
|
await embedColor(message.author.id, message.guild.id),
|
|
)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
}),
|
|
],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
resolve(parseInt(row.reputation));
|
|
},
|
|
);
|
|
});
|
|
|
|
if (lastHack > Date.now() - 7200000) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Hack Impossible")
|
|
.setDescription(
|
|
`❌ Vous avez déjà hack une team récemment. Veuillez attendre ${Math.floor((lastHack + 7200000 - Date.now()) / 60000)} minutes avant de pouvoir ajouter une reputation à nouveau.`,
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
return message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
|
|
db.run(
|
|
`UPDATE users SET lastHack =? WHERE guildId =? AND userId =?`,
|
|
[Date.now(), message.guild.id, message.author.id],
|
|
(err) => {
|
|
if (err) {
|
|
console.log(`${err}`.red);
|
|
}
|
|
},
|
|
);
|
|
db.run(
|
|
`UPDATE users SET reputation = reputation - 4 WHERE guildId =? AND userId =?`,
|
|
[message.guild.id, message.author.id],
|
|
(err) => {
|
|
if (err) {
|
|
console.log(`${err}`.red);
|
|
}
|
|
},
|
|
);
|
|
|
|
if (Math.floor(Math.random() * 5) <= 1) {
|
|
db.run(
|
|
`UPDATE teams SET padlock = padlock - 1 WHERE guildId =? AND id =?`,
|
|
[message.guild.id, teamID],
|
|
(err) => {
|
|
if (err) {
|
|
console.log(`${err}`.red);
|
|
}
|
|
},
|
|
);
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Hack réussi !")
|
|
.setDescription(
|
|
"Vous avez cassé(e) un cadenas de la team `" +
|
|
team.name +
|
|
"`, cette team à maintement `" +
|
|
team.padlock -
|
|
1 +
|
|
"` cadenas !",
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setImage(
|
|
"https://cdn.discordapp.com/attachments/1173221717024448573/1188279536467579011/hack-pc.gif?ex=665721ce&is=6655d04e&hm=e2f2aacbc56c96a33cab6ce215bdc9d042c25df5ffc608098dc1595fe81ee710&",
|
|
)
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
if (team.padlock == 1) {
|
|
db.run(
|
|
`UPDATE users SET bank =? WHERE guildId =? AND userId =?`,
|
|
[user.bank + team.bank, message.guild.id, message.author.id],
|
|
(err) => {
|
|
if (err) {
|
|
console.log(`${err}`.red);
|
|
}
|
|
},
|
|
);
|
|
db.run(
|
|
`UPDATE teams SET bank = 0 WHERE guildId =? AND userId =?`,
|
|
[message.guild.id, message.author.id],
|
|
(err) => {
|
|
if (err) {
|
|
console.log(`${err}`.red);
|
|
}
|
|
},
|
|
);
|
|
|
|
const embed2 = new EmbedBuilder()
|
|
.setTitle("Vole de la banque !")
|
|
.setDescription(
|
|
"La team n'a plus de cadenas ! Vous avez donc recupéré tout l'argent de la bank (`" +
|
|
team.bank +
|
|
"`coins) !",
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setImage("")
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed, embed2],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
} else {
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
} else {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Erreur lors du hack !")
|
|
.setDescription(
|
|
"Vous n'avez pas reussi à casser un cadenas de la team `" +
|
|
team.name +
|
|
"`, qui à donc, toujours, `" +
|
|
team.padlock +
|
|
"` cadenas.",
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setImage(
|
|
"https://cdn.discordapp.com/attachments/1173221717024448573/1188280123485601842/hacker-meme.gif?ex=6655d0da&is=66547f5a&hm=103ee9971cdb67eb528df4c6031e4da69366fb1d1c638f21d4ebf0ef34220691&",
|
|
)
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
},
|
|
};
|