mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 23:36:29 +02:00
Add sys tshop batiment
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } = require('discord.js');
|
||||
const db = require('../../fonctions/database.js');
|
||||
const embedColor = require('../../fonctions/embedColor.js');
|
||||
|
||||
module.exports = {
|
||||
aliases: ['tshop', 'tmagasin', 'tboutique', 'tstore', 'teamshop', 'teammagasin', 'tboutique', 'teamstore'],
|
||||
description: 'Affiche le shop du bot.',
|
||||
emote: '🛍️',
|
||||
utilisation: '',
|
||||
permission: 0,
|
||||
|
||||
async execute(message, args, client) {
|
||||
const user = await new Promise((resolve, reject) => {
|
||||
db.get(`SELECT * FROM users WHERE guildId = ? AND userId = ?`, [message.guild.id, message.author.id], (err, row) => {
|
||||
if (err) reject(err);
|
||||
resolve(row);
|
||||
});
|
||||
});
|
||||
const team = await new Promise((resolve, reject) => {
|
||||
db.get(`SELECT * FROM teams WHERE guildId = ? AND id = ?`, [message.guild.id, user.teamId], (err, row) => {
|
||||
if (err) reject(err);
|
||||
resolve(row);
|
||||
});
|
||||
});
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('🛍️ Shop')
|
||||
.setThumbnail(message.guild.iconURL())
|
||||
.setDescription(`Sélectionnez un item à acheter POUR VOTRE TEAM, les items sont cummulable, vous gagner déjà ${team.location}coins/min. Voici les items disponibles :\n\n> 🏢 Appartement - Achete un appartement et le met en location, rapporte \`70coins/min\`\nPrix : \`100000\`coins\n\n> 🏠 Maison - Achete une petite maison et la met en location, rapporte \`75coins/min\`\nPrix : \`110000\`coins\n\n> 🏠 Grande maison - Achete une grande maison et la met en location, rapporte \`125coins/min\`\nPrix : \`150000\`coins\n\n> 💎 Villa - Achete une petite maison et la met en location, rapporte \`250coins/min\`\nPrix : \`250000\`coins\n\n> 🏝️ Île - Achete une île et la met en location, rapporte \`2500coins/min\`\nPrix : \`500000\`coins`)
|
||||
.setColor(await embedColor(message.author.id, message.guild.id))
|
||||
.setTimestamp()
|
||||
.setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() });
|
||||
|
||||
const select = new StringSelectMenuBuilder()
|
||||
.setCustomId('shop')
|
||||
.setPlaceholder('Sélectionnez un item')
|
||||
.addOptions(
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('🏢 Appartement')
|
||||
.setValue('appartement')
|
||||
.setDescription('Achete un appartement et le met en location, rapporte 70coins/min')
|
||||
.setEmoji('🏢')
|
||||
.setDefault(false),
|
||||
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('🏠 Maison')
|
||||
.setValue('maison')
|
||||
.setDescription('Achete une petite maison et la met en location, rapporte 75coins/min')
|
||||
.setEmoji('🏠')
|
||||
.setDefault(false),
|
||||
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('🏠 Grande maison')
|
||||
.setValue('maison2')
|
||||
.setDescription('Achete une grande maison et la met en location, rapporte 120coins/min')
|
||||
.setEmoji('🏠')
|
||||
.setDefault(false),
|
||||
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('💎 Villa')
|
||||
.setValue('villa')
|
||||
.setDescription('Achete une villa et la met en location, rapporte 250coins/min')
|
||||
.setEmoji('💎')
|
||||
.setDefault(false),
|
||||
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('🏝️ Île')
|
||||
.setValue('ile')
|
||||
.setDescription('Achete une île et la met en location, rapporte 2500coins/min')
|
||||
.setEmoji('🏝️')
|
||||
.setDefault(false),
|
||||
);
|
||||
|
||||
const row = new ActionRowBuilder()
|
||||
.addComponents(select);
|
||||
|
||||
message.reply({ embeds: [embed], components: [row], allowedMentions: { repliedUser: false } });
|
||||
|
||||
client.on('interactionCreate', async (interaction) => {
|
||||
if (!interaction.isStringSelectMenu()) return;
|
||||
if (!interaction.customId === 'shop') return
|
||||
const selected = interaction.values[0];
|
||||
|
||||
let coup = ''
|
||||
let item = ''
|
||||
let win = ''
|
||||
if (selected === 'appartement') {
|
||||
coup = '100000'
|
||||
item = 'appartement'
|
||||
win = '70'
|
||||
} else if (selected === 'maison') {
|
||||
coup = '110000'
|
||||
item = 'maison'
|
||||
win = '75'
|
||||
} else if (selected === 'maison2') {
|
||||
coup = '150000'
|
||||
item = 'grande maison'
|
||||
win = '120'
|
||||
} else if (selected === 'villa') {
|
||||
coup = '250000'
|
||||
item = 'villa'
|
||||
win = '250'
|
||||
} else if (selected === 'ile') {
|
||||
coup = '500000'
|
||||
item = 'île'
|
||||
win = '2500'
|
||||
}
|
||||
|
||||
if (user.teamRole !== 'officier' || user.teamRole !== 'officer') return interaction.reply({ content: 'Vous n\'avez pas les permissions pour faire cet achat', ephemeral: true });
|
||||
if (team.bank < coup) return interaction.reply({ content: 'Vous n\'avez pas assez d\'argent pour acheter cet item.', ephemeral: true });
|
||||
|
||||
db.run(`UPDATE teams SET pocket = pocket - ? WHERE guildId = ? AND userId = ?`, [coup, message.guild.id, message.author.id]);
|
||||
db.run(`UPDATE teams SET location = location + ? WHERE guildId = ? AND userId = ?`, [win, message.guild.id, message.author.id]);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('🛍️ Shop')
|
||||
.setDescription(`Vous avez acheté l'item ${item} pour \`${coup}\`coins !`)
|
||||
.setColor(await embedColor(message.author.id, message.guild.id))
|
||||
.setTimestamp()
|
||||
.setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() });
|
||||
interaction.reply({ embeds: [embed], allowedMentions: { repliedUser: false } });
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -48,6 +48,20 @@ module.exports = {
|
||||
});
|
||||
}, 15 * 60 * 1000);
|
||||
|
||||
setInterval(async () => {
|
||||
const team = await new Promise((resolve, reject) => {
|
||||
db.get(`SELECT * FROM teams`, (err, row) => {
|
||||
if (err) reject(err);
|
||||
resolve(row);
|
||||
});
|
||||
});
|
||||
|
||||
team.forEach(() => {
|
||||
if (team.location == 0) return
|
||||
db.run(`UPDATE teams SET bank = bank + ? WHERE guildId = ? AND userId = ?`, [team.location, message.guild.id, message.author.id]);
|
||||
})
|
||||
}, 1 * 60 * 1000)
|
||||
|
||||
//AntiCrash
|
||||
process.on('unhandledRejection', (error) => {
|
||||
if (error.code == "10064") return
|
||||
|
||||
@@ -53,6 +53,7 @@ db.run(`CREATE TABLE IF NOT EXISTS teams (
|
||||
banner TEXT,
|
||||
reputation INTERGER DEFAULT 0,
|
||||
bank INTEGER DEFAULT 0,
|
||||
location INTERGER DEFAULT 0,
|
||||
level INTEGER DEFAULT 1,
|
||||
padlock INTEGER DEFAULT 5,
|
||||
soldiers INTEGER DEFAULT 0,
|
||||
|
||||
Reference in New Issue
Block a user