mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-13 08:09:31 +02:00
233 lines
6.7 KiB
JavaScript
233 lines
6.7 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: ["dice", "dé"],
|
|
description: "Lance un dé.",
|
|
emote: "🎲",
|
|
utilisation: "<mise> <face1> <face2>",
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
let mise = 0;
|
|
let face = `${args[1]}\` et \`${args[2]}`;
|
|
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("🎲 Lancer de dé")
|
|
.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 !== 3) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Lancer de dé")
|
|
.setDescription(
|
|
`Vous devez spécifier une mise et deux face. Exemple : \`&dice 100 1 2\`.`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
if (isNaN(args[0]) && !args[0] == "all") {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Lancer de dé")
|
|
.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("🎲 Lancer de dé")
|
|
.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 (
|
|
!face.includes(1) &&
|
|
!face.includes(2) &&
|
|
!face.includes(3) &&
|
|
!face.includes(4) &&
|
|
!face.includes(5) &&
|
|
!face.includes(6)
|
|
) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Lancer de dé")
|
|
.setDescription(`La face doit être 1, 2, 3, 4, 5 ou 6.`)
|
|
.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("🎲 Lancer de dé")
|
|
.setImage(
|
|
"https://cdn.discordapp.com/attachments/1120446538544595005/1195513783997714564/dice.gif?",
|
|
)
|
|
.setDescription(
|
|
`Vous avez misé \`${mise}\` sur \`${face}\`. Le dé 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() * 6) + 1;
|
|
let gain = 0;
|
|
if (face.includes(result)) {
|
|
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("🎲 Lancer de dé")
|
|
.setDescription(
|
|
`Vous avez misé \`${mise}\` sur \`${face}\` et le dé est tombée sur \`${result}\`. 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("🎲 Lancer de dé")
|
|
.setDescription(
|
|
`Vous avez misé \`${mise}\` sur \`${face}\` et le dé est tombée sur \`${result}\`. 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;
|
|
}
|
|
},
|
|
};
|