mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 15:07:20 +02:00
187 lines
6.0 KiB
JavaScript
187 lines
6.0 KiB
JavaScript
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 },
|
|
});
|
|
});
|
|
},
|
|
};
|