mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 15:07:20 +02:00
228 lines
6.6 KiB
JavaScript
228 lines
6.6 KiB
JavaScript
const {
|
|
EmbedBuilder,
|
|
ButtonStyle,
|
|
ButtonBuilder,
|
|
ActionRowBuilder,
|
|
} = require("discord.js");
|
|
const embedColor = require("../../fonctions/embedColor.js");
|
|
const db = require("../../fonctions/database.js");
|
|
|
|
module.exports = {
|
|
aliases: ["pfc"],
|
|
description: "Joue au pierre feuille ciseau.",
|
|
emote: "🎲",
|
|
utilisation: "<mise> <pierre|feuille|ciseau>",
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
if (args.length !== 2) {
|
|
return message.reply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle("🪨 Pierre Feuille Ciseau")
|
|
.setDescription(
|
|
`Vous devez spécifier une mise et un coup. Exemple : \`&pierre-feuille-ciseau 100 pierre\`.`,
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
}),
|
|
],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
} else if (isNaN(args[0])) {
|
|
return message.reply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle("🪨 Pierre Feuille Ciseau")
|
|
.setDescription(`La mise doit être un nombre.`)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
}),
|
|
],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
} else if (args[0] < 25) {
|
|
return message.reply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle("🪨 Pierre Feuille Ciseau")
|
|
.setDescription(`La mise doit être supérieure ou égale à \`25\`.`)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
}),
|
|
],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
} else if (
|
|
args[1] !== "pierre" &&
|
|
args[1] !== "p" &&
|
|
args[1] !== "feuille" &&
|
|
args[1] !== "f" &&
|
|
args[1] !== "ciseau" &&
|
|
args[1] !== "c"
|
|
) {
|
|
return message.reply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle("🪨 Pierre Feuille Ciseau")
|
|
.setDescription(
|
|
`La coup doit être \`pierre\`, \`feuille\` ou \`ciseau\`.`,
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
}),
|
|
],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
}
|
|
|
|
const pocket = await new Promise((resolve, reject) => {
|
|
db.get(
|
|
`SELECT pocket FROM users WHERE userId = ? AND guildId = ?`,
|
|
[message.author.id, message.guild.id],
|
|
async (err, row) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(row.pocket);
|
|
}
|
|
},
|
|
);
|
|
});
|
|
|
|
if (pocket < args[0])
|
|
return message.reply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle("🪨 Pierre Feuille Ciseau")
|
|
.setDescription(
|
|
`Vous n'avez pas assez d'argent sur vous pour miser cette somme.`,
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
}),
|
|
],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
|
|
const sendMessage = await message.reply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle("🪨 Pierre Feuille Ciseau")
|
|
.setDescription(
|
|
`Vous avez misé(e) \`${args[0]}\` coins sur \`${args[1]}\`...\nRésultat dans 7.5 secondes...`,
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
}),
|
|
],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 7500));
|
|
|
|
const result = Math.floor(Math.random() * 2);
|
|
let coupBot = "";
|
|
let coupBotA = "";
|
|
if (result === 0) {
|
|
coupBot = "feuille";
|
|
coupBotA = "f";
|
|
} else if (result === 1) {
|
|
coupBot = "ciseau";
|
|
coupBotA = "c";
|
|
} else {
|
|
coupBot = "pierre";
|
|
coupBotA = "p";
|
|
}
|
|
|
|
let gain = args[0];
|
|
let description = "";
|
|
let coupUser = "";
|
|
let win = false;
|
|
if (args[1] == "p" || args[1] == "pierre") {
|
|
coupUser = "p";
|
|
}
|
|
if (args[1] == "f" || args[1] == "feuille") {
|
|
coupUser = "f";
|
|
}
|
|
if (args[1] == "c" || args[1] == "ciseau") {
|
|
coupUser = "c";
|
|
}
|
|
|
|
if (args[1] === coupBot || args[1] === coupBotA) {
|
|
gain = 0;
|
|
description = "A refaire, le bot a jouer `" + coupBot + "`, comme toi...";
|
|
} else if (coupUser == "p" && coupBotA == "c") {
|
|
win = true;
|
|
} else if (coupUser == "f" && coupBotA == "p") {
|
|
win = true;
|
|
} else if (coupUser == "c" && coupBotA == "f") {
|
|
win = true;
|
|
} else {
|
|
gain = 0 - args[0];
|
|
description =
|
|
"Tu as perdu `" +
|
|
args[0] +
|
|
"`coins... Le bot a jouer `" +
|
|
coupBot +
|
|
"` !";
|
|
}
|
|
|
|
if (win == true) {
|
|
gain = gain * 2;
|
|
description =
|
|
"Bravo, tu as gagné(e) `" +
|
|
gain +
|
|
"` coins car le bot a jouer `" +
|
|
coupBot +
|
|
"` !";
|
|
}
|
|
|
|
sendMessage.edit({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle("🪨 Pierre Feuille Ciseau")
|
|
.setDescription(description)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
}),
|
|
],
|
|
});
|
|
|
|
await new Promise((resolve, reject) => {
|
|
db.run(
|
|
`UPDATE users SET pocket = pocket + ? WHERE userId = ? AND guildId = ?`,
|
|
[gain, message.author.id, message.guild.id],
|
|
(err) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve();
|
|
}
|
|
},
|
|
);
|
|
});
|
|
},
|
|
};
|