mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-16 23:57:48 +02:00
trop de truc pour tout ecrire
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const db = new sqlite3.Database('myDatabase.db');
|
||||
module.exports = {
|
||||
name: 'marry',
|
||||
description: 'Proposez en mariage à un utilisateur',
|
||||
emote: '💍',
|
||||
category: 'game',
|
||||
category: '+marry @user',
|
||||
async execute(message, args, client) {
|
||||
const targetUser = message.mentions.users.first() || message.guild.members.cache.get(args[0]);
|
||||
if (!targetUser) {
|
||||
return message.reply('Veuillez mentionner un utilisateur ou fournir un ID d\'utilisateur.');
|
||||
}
|
||||
const isRequesterMarried = checkIfMarried(message.author.id, client);
|
||||
if (isRequesterMarried === true) {
|
||||
return message.reply('Vous êtes déjà marié.');
|
||||
}
|
||||
const isTargetMarried = checkIfMarried(targetUser.id, client);
|
||||
if (isTargetMarried === true) {
|
||||
return message.reply('Cet utilisateur est déjà marié.');
|
||||
}
|
||||
const row = new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`acceptmarriage_${targetUser.id}_${message.author.id}`)
|
||||
.setLabel('Accepter')
|
||||
.setStyle(ButtonStyle.Success),
|
||||
);
|
||||
|
||||
message.channel.send({ content: `${targetUser}`, components: [row] });
|
||||
},
|
||||
};
|
||||
async function checkIfMarried(userId, client) {
|
||||
let data = await new Promise((resolve, reject) => {
|
||||
db.get('SELECT value FROM gestion WHERE id = ?', [client.user.id], (err, row) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
reject(err);
|
||||
}
|
||||
const parsedData = row ? JSON.parse(row.value) : {};
|
||||
parsedData.marry = parsedData.marry || [];
|
||||
resolve(parsedData);
|
||||
});
|
||||
});
|
||||
|
||||
const isMarried = data.marry.some(pair => {
|
||||
const [userId1, userId2] = pair.split('_');
|
||||
return userId1 === userId || userId2 === userId;
|
||||
});
|
||||
|
||||
return isMarried;
|
||||
}
|
||||
Reference in New Issue
Block a user