mirror of
https://github.com/arthur-pbty/New-discord-bot-coins.git
synced 2026-06-14 15:55:12 +02:00
add many fonction & add &me command
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
const addCommand = require("../../fonctions/addCommand");
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
||||
const db = require("../../fonctions/setDatabase");
|
||||
const formatValue = require("../../fonctions/formatValue");
|
||||
const formatDate = require("../../fonctions/formatDate");
|
||||
const createAccount = require("../../fonctions/createAccount");
|
||||
const getEmbedColor = require("../../fonctions/getEmbedColor");
|
||||
|
||||
module.exports = addCommand(
|
||||
(this.name = "me"),
|
||||
(this.description = "Affiche les coins du membre mentionné ou de l'auteur du message."),
|
||||
(this.aliases = [
|
||||
"coin",
|
||||
"coins",
|
||||
"money",
|
||||
"balance",
|
||||
"bal",
|
||||
"wallet",
|
||||
"cash",
|
||||
"lvl",
|
||||
"level",
|
||||
"niv",
|
||||
"niveau",
|
||||
]),
|
||||
(this.permissions = []),
|
||||
(this.botOwnerOnly = false),
|
||||
(this.dm = false),
|
||||
(this.executePrefix = async (client, message, args) => {
|
||||
const member = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.member;
|
||||
const embedColor = await getEmbedColor(message.guild.id, message.author.id);
|
||||
|
||||
let user = await new Promise((resolve, reject) => {
|
||||
db.get(
|
||||
`SELECT * FROM users WHERE guildId = ? AND userId = ?`,
|
||||
[message.guild.id, member.id],
|
||||
(err, row) => {
|
||||
if (err) reject(err);
|
||||
resolve(row);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
user = await createAccount(message.guild.id, member.id);
|
||||
}
|
||||
|
||||
user.pocket = formatValue(user.pocket);
|
||||
user.bank = formatValue(user.bank);
|
||||
user.reputation = formatValue(user.reputation);
|
||||
user.xp = formatValue(user.xp);
|
||||
user.level = formatValue(user.level);
|
||||
if (user.antiRob + 7200000 > Date.now()) {
|
||||
user.antiRob = formatDate(user.antiRob);
|
||||
} else {
|
||||
user.antiRob = "Non";
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: `Détails du Compte de ${member.user.tag}`,
|
||||
iconURL: member.user.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(`> 💰 **Argent de poche :** ${user.pocket}\n> 🏦 **Banque :** ${user.bank}\n> 🌟 **Réputation :** ${user.reputation}\n\n> 📊 **Niveau :** ${user.level}\n> 🔸 **Expérience :** ${user.xp}\n\n> 🛡️ **Anti-Rob:** ${user.antiRob}`)
|
||||
.setColor(embedColor)
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: `Demandé par ${message.author.tag}`,
|
||||
iconURL: message.author.displayAvatarURL(),
|
||||
});
|
||||
|
||||
message.reply({ embeds: [embed] });
|
||||
}),
|
||||
(this.executeSlash = async (client, interaction) => {
|
||||
const member = interaction.options.getMember("membre") || interaction.member;
|
||||
const embedColor = await getEmbedColor(interaction.guild.id, interaction.user.id);
|
||||
|
||||
let user = await new Promise((resolve, reject) => {
|
||||
db.get(
|
||||
`SELECT * FROM users WHERE guildId = ? AND userId = ?`,
|
||||
[interaction.guild.id, member.id],
|
||||
(err, row) => {
|
||||
if (err) reject(err);
|
||||
resolve(row);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
user = await createAccount(interaction.guild.id, member.id);
|
||||
}
|
||||
|
||||
user.pocket = formatValue(user.pocket);
|
||||
user.bank = formatValue(user.bank);
|
||||
user.reputation = formatValue(user.reputation);
|
||||
user.xp = formatValue(user.xp);
|
||||
user.level = formatValue(user.level);
|
||||
if (user.antiRob + 7200000 > Date.now()) {
|
||||
user.antiRob = formatDate(user.antiRob);
|
||||
} else {
|
||||
user.antiRob = "Non";
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setAuthor({
|
||||
name: `Détails du Compte de ${member.user.tag}`,
|
||||
iconURL: member.user.displayAvatarURL(),
|
||||
})
|
||||
.setDescription(`> 💰 **Argent de poche :** ${user.pocket}\n> 🏦 **Banque :** ${user.bank}\n> 🌟 **Réputation :** ${user.reputation}\n\n> 📊 **Niveau :** ${user.level}\n> 🔸 **Expérience :** ${user.xp}\n\n> 🛡️ **Anti-Rob:** ${user.antiRob}`)
|
||||
.setColor(embedColor)
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: `Demandé par ${interaction.user.tag}`,
|
||||
iconURL: interaction.user.displayAvatarURL(),
|
||||
});
|
||||
|
||||
interaction.reply({ embeds: [embed] });
|
||||
}),
|
||||
(this.slashOptions = new SlashCommandBuilder()
|
||||
.addUserOption((option) => option
|
||||
.setName("membre")
|
||||
.setDescription("Membre à afficher.")
|
||||
.setRequired(false),
|
||||
)),
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
const db = require("./setDatabase.js");
|
||||
|
||||
module.exports = async function createAccount(guildId, userId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(
|
||||
`INSERT INTO users (guildId, userId) VALUES (?, ?)`,
|
||||
[guildId, userId],
|
||||
function(err) {
|
||||
if (err) reject(err);
|
||||
db.get(
|
||||
`SELECT * FROM users WHERE guildId = ? AND userId = ?`,
|
||||
[guildId, userId],
|
||||
function(err, row) {
|
||||
if (err) reject(err);
|
||||
resolve(row);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
module.exports = function formatDate(timestamp) {
|
||||
const currentDate = new Date();
|
||||
const targetDate = new Date(timestamp);
|
||||
|
||||
const diffTime = Math.abs(targetDate - currentDate);
|
||||
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
||||
const diffHours = Math.floor((diffTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
||||
const diffMinutes = Math.floor((diffTime % (1000 * 60 * 60)) / (1000 * 60));
|
||||
|
||||
let result = "";
|
||||
if (diffDays > 0) {
|
||||
result += `${diffDays} jour${diffDays > 1 ? "s" : ""}, `;
|
||||
}
|
||||
if (diffHours > 0) {
|
||||
result += `${diffHours} heure${diffHours > 1 ? "s" : ""} et `;
|
||||
}
|
||||
result += `${diffMinutes} minute${diffMinutes > 1 ? "s" : ""}`;
|
||||
|
||||
return result;
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
module.exports = function formatValue(value) {
|
||||
let number = parseFloat(value);
|
||||
if (number >= 1000000000) {
|
||||
return (number / 1000000000).toFixed(2) + "B";
|
||||
} else if (number >= 1000000) {
|
||||
return (number / 1000000).toFixed(2) + "M";
|
||||
} else if (number >= 1000) {
|
||||
return (number / 1000).toFixed(2) + "K";
|
||||
} else {
|
||||
return number.toString();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
const db = require("./setDatabase");
|
||||
|
||||
module.exports = async function getEmbedColor(serverId, memberId) {
|
||||
const user = await new Promise((resolve, reject) => {
|
||||
db.get(
|
||||
`SELECT * FROM users WHERE guildId = ? AND userId = ?`,
|
||||
[serverId, memberId],
|
||||
(err, row) => {
|
||||
if (err) reject(err);
|
||||
resolve(row);
|
||||
},
|
||||
);
|
||||
});
|
||||
let embedColor = user.embed;
|
||||
if (embedColor === "random") {
|
||||
const colors = [
|
||||
"red",
|
||||
"orange",
|
||||
"yellow",
|
||||
"green",
|
||||
"blue",
|
||||
"purple",
|
||||
"brown",
|
||||
"black",
|
||||
"white",
|
||||
];
|
||||
embedColor = colors[Math.floor(Math.random() * colors.length)];
|
||||
}
|
||||
if (!embedColor || embedColor === "yellow") {
|
||||
embedColor = "#FFFF00";
|
||||
} else if (embedColor === "red") {
|
||||
embedColor = "#FF0000";
|
||||
} else if (embedColor === "orange") {
|
||||
embedColor = "#FFA500";
|
||||
} else if (embedColor === "green") {
|
||||
embedColor = "#008000";
|
||||
} else if (embedColor === "blue") {
|
||||
embedColor = "#0000FF";
|
||||
} else if (embedColor === "purple") {
|
||||
embedColor = "#800080";
|
||||
} else if (embedColor === "brown") {
|
||||
embedColor = "#A52A2A";
|
||||
} else if (embedColor === "black") {
|
||||
embedColor = "#000000";
|
||||
} else if (embedColor === "white") {
|
||||
embedColor = "#FFFFFF";
|
||||
}
|
||||
return embedColor;
|
||||
};
|
||||
@@ -15,4 +15,18 @@ db.run(`CREATE TABLE IF NOT EXISTS prefix (
|
||||
PRIMARY KEY (guildId)
|
||||
)`);
|
||||
|
||||
db.run(`CREATE TABLE IF NOT EXISTS users (
|
||||
guildId TEXT,
|
||||
userId TEXT,
|
||||
pocket INTEGER DEFAULT 0,
|
||||
bank INTEGER DEFAULT 0,
|
||||
reputation INTEGER DEFAULT 0,
|
||||
level INTERGER DEFAULT 0,
|
||||
xp INTERGER DEFAULT 0,
|
||||
antiRob INTEGER DEFAULT 0,
|
||||
lastRob INTEGER DEFAULT 0,
|
||||
embed TEXT DEFAULT yellow,
|
||||
PRIMARY KEY (guildId, userId)
|
||||
)`);
|
||||
|
||||
module.exports = db;
|
||||
|
||||
Reference in New Issue
Block a user