mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-18 21:38:32 +02:00
239 lines
6.9 KiB
JavaScript
239 lines
6.9 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: ["pf"],
|
|
description: "Lance une piece.",
|
|
emote: "🎲",
|
|
utilisation: "<mise> <cote>",
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
let mise = 0;
|
|
const pocket = await new Promise((resolve, reject) => {
|
|
db.get(
|
|
`SELECT pocket FROM users WHERE userId = ? AND guildId = ?`,
|
|
[message.author.id, message.guild.id],
|
|
(err, row) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(row.pocket);
|
|
}
|
|
},
|
|
);
|
|
});
|
|
if (args[0] == "all") {
|
|
mise = pocket;
|
|
} else {
|
|
mise = args[0];
|
|
}
|
|
|
|
if (pocket < mise) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Pile ou face")
|
|
.setDescription(
|
|
`Vous n'avez pas assez d'argent sur vous pour miser cette somme.`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (args.length !== 2) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Pile ou face")
|
|
.setDescription(
|
|
`Vous devez spécifier une mise et un côté. Exemple : \`&pile-face 100 pile\`.`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
} else if (isNaN(args[0]) && !args[0] == "all") {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Pile ou face")
|
|
.setDescription(`La mise doit être un nombre.`)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
} else if (mise < 25) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Pile ou face")
|
|
.setDescription(`La mise doit être supérieure ou égale à \`25\`.`)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
} else if (
|
|
args[1] !== "pile" &&
|
|
args[1] !== "face" &&
|
|
args[1] !== "p" &&
|
|
args[1] !== "f"
|
|
) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Pile ou face")
|
|
.setDescription(`Le côté doit être \`pile\` ou \`face\`.`)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Pile ou face")
|
|
.setImage(
|
|
"https://images-ext-1.discordapp.net/external/Zz7GmmFoFdFRB7GCjiJGaDHDjJi8noOLY8zasCmUOGQ/https/media.giphy.com/media/26uflBhaGt5lQsaCA/giphy.gif",
|
|
)
|
|
.setDescription(
|
|
`Vous avez misé \`${mise}\` sur \`${args[1]}\`. la pièce tourne...\nRésultat dans 7.5 secondes...`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
return message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 7500));
|
|
|
|
const result = Math.floor(Math.random() * 2);
|
|
let colorR = "";
|
|
if (result === 0) {
|
|
colorR = "pile";
|
|
} else {
|
|
colorR = "face";
|
|
}
|
|
|
|
let gain = 0;
|
|
if (
|
|
((args[1] === "pile" || args[1] === "p") && colorR === "pile") ||
|
|
((args[1] === "face" || args[1] === "f") && colorR === "face")
|
|
) {
|
|
gain = Math.round(mise * 1.5);
|
|
} else {
|
|
gain = 0 - mise;
|
|
}
|
|
|
|
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();
|
|
}
|
|
},
|
|
);
|
|
});
|
|
|
|
if (gain >= 0) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Pile ou face")
|
|
.setDescription(
|
|
`Vous avez misé \`${mise}\` sur \`${args[1]}\` et la pièce est tombée sur \`${colorR}\`. Vous avez gagné \`${gain}\` !`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
} else {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Pile ou face")
|
|
.setDescription(
|
|
`Vous avez misé \`${mise}\` sur \`${args[1]}\` et la pièce est tombée sur \`${colorR}\`. Vous avez perdu \`${0 - gain}\` !`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
},
|
|
};
|