mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 15:07:20 +02:00
Add pouletFight
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
const { EmbedBuilder, ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js');
|
||||
const embedColor = require('../../fonctions/embedColor.js');
|
||||
const db = require('../../fonctions/database.js');
|
||||
|
||||
module.exports = {
|
||||
aliases: ['pouletfight', 'pfight', 'poulet'],
|
||||
description: 'Fait un combat de poulet.',
|
||||
emote: '🐔',
|
||||
utilisation: '<mise>',
|
||||
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('🐔 Poulet')
|
||||
.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 (isNaN(args[0]) && !args[0] == "all") {
|
||||
embedColor(message.author.id, message.guild.id).then(color => {
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('🐔 Poulet')
|
||||
.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('🐔 Poulet')
|
||||
.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
|
||||
}
|
||||
|
||||
embedColor(message.author.id, message.guild.id).then(color => {
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('🐔 Poulet')
|
||||
//.setImage('') // image de combat de poulet
|
||||
.setDescription(`Vous avez misé \`${mise}\` sur votre poulet. Les poulets se battent...\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 win = '';
|
||||
if (result === 0) {
|
||||
win = true;
|
||||
} else {
|
||||
win = false;
|
||||
}
|
||||
|
||||
let gain = 0;
|
||||
if (win == true) {
|
||||
gain = Math.round(mise * 2);
|
||||
} 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('🐔 Poulet')
|
||||
.setDescription(`Vous avez misé \`${mise}\` sur votre poulet et votre poulet a gagné ! Vous avez gagné \`${gain}\`coins !`)
|
||||
.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('🐔 Poulet')
|
||||
.setDescription(`Vous avez misé \`${mise}\` sur votre poulet et votre poulet a perdu. Vous avez perdu \`${0 - gain}\`coins !`)
|
||||
.setColor(color)
|
||||
.setTimestamp()
|
||||
.setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() })
|
||||
|
||||
message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } })
|
||||
});
|
||||
return
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user