add steal in economi

This commit is contained in:
Arthur Puechberty
2026-01-17 19:08:52 +01:00
parent 7d706b4d79
commit 90339f9323
10 changed files with 643 additions and 65 deletions
+2 -2
View File
@@ -34,11 +34,11 @@ module.exports = addCommand({
guildCondition: async (guildId) => {
return new Promise((resolve) => {
db.get(
"SELECT enabled FROM economy_config WHERE guild_id = ?",
"SELECT enabled, crime_enabled FROM economy_config WHERE guild_id = ?",
[guildId],
(err, row) => {
if (err) return resolve(false);
resolve(!!row?.enabled);
resolve(!!row?.enabled && !!row?.crime_enabled);
}
);
});
+2 -2
View File
@@ -14,11 +14,11 @@ module.exports = addCommand({
guildCondition: async (guildId) => {
return new Promise((resolve) => {
db.get(
"SELECT enabled FROM economy_config WHERE guild_id = ?",
"SELECT enabled, daily_enabled FROM economy_config WHERE guild_id = ?",
[guildId],
(err, row) => {
if (err) return resolve(false);
resolve(!!row?.enabled);
resolve(!!row?.enabled && !!row?.daily_enabled);
}
);
});
+214
View File
@@ -0,0 +1,214 @@
const addCommand = require("../fonctions/addCommand");
const { EmbedBuilder } = require("discord.js");
const db = require("../db");
const stealSuccessMessages = [
"Vous avez subtilement volé",
"Vous avez pickpocketé avec succès",
"Vous avez dérobé discrètement",
"Vous avez chapardé habilement",
"Main dans la poche, vous avez pris"
];
const stealFailMessages = [
"Vous vous êtes fait attraper la main dans le sac !",
"La victime vous a surpris et a appelé la sécurité !",
"Un passant a crié au voleur !",
"Vous avez trébuché en tentant de fuir !",
"La victime connaissait vos intentions !"
];
module.exports = addCommand({
name: "steal",
description: "Tentez de voler de l'argent à un autre utilisateur.",
aliases: ["voler", "pickpocket"],
permissions: [],
botOwnerOnly: false,
dm: false,
scope: "guild",
guildCondition: async (guildId) => {
return new Promise((resolve) => {
db.get(
"SELECT enabled, steal_enabled FROM economy_config WHERE guild_id = ?",
[guildId],
(err, row) => {
if (err) return resolve(false);
resolve(!!row?.enabled && !!row?.steal_enabled);
}
);
});
},
slashOptions: [
{
type: "USER",
name: "cible",
description: "L'utilisateur à voler.",
required: true,
},
],
executePrefix: async (client, message, args) => {
const targetUser = message.mentions.users.first();
if (!targetUser) return message.reply("Veuillez mentionner un utilisateur à voler.");
await doSteal(message.guild.id, message.author, targetUser, (embed) => {
message.reply({ embeds: [embed] });
}, (errMsg) => {
message.reply(errMsg);
});
},
executeSlash: async (client, interaction) => {
const targetUser = interaction.options.getUser("cible");
await doSteal(interaction.guild.id, interaction.user, targetUser, (embed) => {
interaction.reply({ embeds: [embed] });
}, (errMsg) => {
interaction.reply({ content: errMsg, ephemeral: true });
});
},
});
async function doSteal(guildId, thief, victim, onSuccess, onError) {
if (thief.id === victim.id) {
return onError("Vous ne pouvez pas vous voler vous-même !");
}
if (victim.bot) {
return onError("Vous ne pouvez pas voler un bot !");
}
db.get(
`SELECT currency_name, currency_symbol, steal_success_rate, steal_max_percent,
steal_fine_percent, steal_cooldown_minutes
FROM economy_config WHERE guild_id = ?`,
[guildId],
(err, config) => {
if (err || !config) {
return onError("Le système d'économie n'est pas configuré.");
}
db.get(
"SELECT balance, last_steal_timestamp FROM user_economy WHERE guild_id = ? AND user_id = ?",
[guildId, thief.id],
(err, thiefRow) => {
if (err) return onError("Erreur lors de la récupération des données.");
const now = Date.now();
const cooldownMs = config.steal_cooldown_minutes * 60 * 1000;
const lastSteal = thiefRow?.last_steal_timestamp || 0;
if (now - lastSteal < cooldownMs) {
const timeLeft = cooldownMs - (now - lastSteal);
const minutes = Math.floor(timeLeft / (60 * 1000));
const seconds = Math.floor((timeLeft % (60 * 1000)) / 1000);
return onError(`⏰ Vous devez attendre encore **${minutes}m ${seconds}s** avant de pouvoir voler quelqu'un.`);
}
// Get victim's wallet balance (not bank!)
db.get(
"SELECT balance FROM user_economy WHERE guild_id = ? AND user_id = ?",
[guildId, victim.id],
(err, victimRow) => {
if (err) return onError("Erreur lors de la récupération des données.");
const victimBalance = victimRow?.balance || 0;
if (victimBalance <= 0) {
return onError(`**${victim.username}** n'a pas d'argent dans son portefeuille à voler ! (L'argent en banque est protégé)`);
}
const thiefBalance = thiefRow?.balance || 0;
const success = Math.random() * 100 < config.steal_success_rate;
let embed;
if (success) {
// Calculate stolen amount (random % of victim's wallet, up to max_percent)
const maxStealPercent = config.steal_max_percent / 100;
const stealPercent = Math.random() * maxStealPercent;
const stolenAmount = Math.max(1, Math.floor(victimBalance * stealPercent));
const newThiefBalance = thiefBalance + stolenAmount;
const newVictimBalance = victimBalance - stolenAmount;
const stealMsg = stealSuccessMessages[Math.floor(Math.random() * stealSuccessMessages.length)];
// Update thief
db.run(
`INSERT INTO user_economy (guild_id, user_id, balance, bank, last_steal_timestamp)
VALUES (?, ?, ?, 0, ?)
ON CONFLICT(guild_id, user_id) DO UPDATE SET
balance = ?,
last_steal_timestamp = ?`,
[guildId, thief.id, newThiefBalance, now, newThiefBalance, now],
(err) => {
if (err) return onError("Erreur lors de la sauvegarde.");
// Update victim
db.run(
`UPDATE user_economy SET balance = ? WHERE guild_id = ? AND user_id = ?`,
[newVictimBalance, guildId, victim.id],
(err) => {
if (err) return onError("Erreur lors de la sauvegarde.");
embed = new EmbedBuilder()
.setTitle(`${config.currency_symbol} Vol réussi !`)
.setColor("#00FF00")
.setDescription(`${stealMsg} **${stolenAmount.toLocaleString()} ${config.currency_name}** à ${victim} !`)
.setTimestamp();
onSuccess(embed);
}
);
}
);
} else {
// Failed - pay fine to victim
const fine = Math.floor(thiefBalance * (config.steal_fine_percent / 100));
const newThiefBalance = Math.max(0, thiefBalance - fine);
const newVictimBalance = victimBalance + fine;
const failMsg = stealFailMessages[Math.floor(Math.random() * stealFailMessages.length)];
// Update thief
db.run(
`INSERT INTO user_economy (guild_id, user_id, balance, bank, last_steal_timestamp)
VALUES (?, ?, ?, 0, ?)
ON CONFLICT(guild_id, user_id) DO UPDATE SET
balance = ?,
last_steal_timestamp = ?`,
[guildId, thief.id, newThiefBalance, now, newThiefBalance, now],
(err) => {
if (err) return onError("Erreur lors de la sauvegarde.");
// Give fine to victim
db.run(
`INSERT INTO user_economy (guild_id, user_id, balance, bank)
VALUES (?, ?, ?, 0)
ON CONFLICT(guild_id, user_id) DO UPDATE SET balance = ?`,
[guildId, victim.id, newVictimBalance, newVictimBalance],
(err) => {
if (err) return onError("Erreur lors de la sauvegarde.");
embed = new EmbedBuilder()
.setTitle("🚔 Vol échoué !")
.setColor("#FF0000")
.setDescription(`${failMsg}\n\nVous avez dû payer **${fine.toLocaleString()} ${config.currency_name}** à ${victim} en dédommagement.`)
.setTimestamp();
onSuccess(embed);
}
);
}
);
}
}
);
}
);
}
);
}
+2 -2
View File
@@ -29,11 +29,11 @@ module.exports = addCommand({
guildCondition: async (guildId) => {
return new Promise((resolve) => {
db.get(
"SELECT enabled FROM economy_config WHERE guild_id = ?",
"SELECT enabled, work_enabled FROM economy_config WHERE guild_id = ?",
[guildId],
(err, row) => {
if (err) return resolve(false);
resolve(!!row?.enabled);
resolve(!!row?.enabled && !!row?.work_enabled);
}
);
});
+18
View File
@@ -99,16 +99,32 @@ db.exec(`
enabled INTEGER NOT NULL DEFAULT 0,
currency_name TEXT NOT NULL DEFAULT 'coins',
currency_symbol TEXT NOT NULL DEFAULT '💰',
daily_enabled INTEGER NOT NULL DEFAULT 1,
daily_amount INTEGER NOT NULL DEFAULT 100,
daily_cooldown_hours INTEGER NOT NULL DEFAULT 24,
work_enabled INTEGER NOT NULL DEFAULT 1,
work_min_amount INTEGER NOT NULL DEFAULT 50,
work_max_amount INTEGER NOT NULL DEFAULT 150,
work_cooldown_minutes INTEGER NOT NULL DEFAULT 60,
crime_enabled INTEGER NOT NULL DEFAULT 1,
crime_min_amount INTEGER NOT NULL DEFAULT 100,
crime_max_amount INTEGER NOT NULL DEFAULT 500,
crime_success_rate INTEGER NOT NULL DEFAULT 50,
crime_fine_percent INTEGER NOT NULL DEFAULT 30,
crime_cooldown_minutes INTEGER NOT NULL DEFAULT 120,
steal_enabled INTEGER NOT NULL DEFAULT 1,
steal_success_rate INTEGER NOT NULL DEFAULT 40,
steal_max_percent INTEGER NOT NULL DEFAULT 50,
steal_fine_percent INTEGER NOT NULL DEFAULT 25,
steal_cooldown_minutes INTEGER NOT NULL DEFAULT 180,
message_money_enabled INTEGER NOT NULL DEFAULT 0,
message_money_min INTEGER NOT NULL DEFAULT 1,
message_money_max INTEGER NOT NULL DEFAULT 5,
message_money_cooldown_seconds INTEGER NOT NULL DEFAULT 60,
voice_money_enabled INTEGER NOT NULL DEFAULT 0,
voice_money_min INTEGER NOT NULL DEFAULT 5,
voice_money_max INTEGER NOT NULL DEFAULT 15,
voice_money_interval_minutes INTEGER NOT NULL DEFAULT 5,
starting_balance INTEGER NOT NULL DEFAULT 0
);
@@ -120,6 +136,8 @@ db.exec(`
last_daily_timestamp INTEGER,
last_work_timestamp INTEGER,
last_crime_timestamp INTEGER,
last_steal_timestamp INTEGER,
last_message_money_timestamp INTEGER,
PRIMARY KEY (guild_id, user_id)
);
+45 -9
View File
@@ -8,6 +8,7 @@ module.exports = {
const guildId = message.guild.id;
// ===== XP SYSTEM =====
db.get(
`SELECT
enabled,
@@ -34,28 +35,28 @@ module.exports = {
const userRoles = message.member.roles.cache;
const requiredRoles = JSON.parse(row.role_with_without_xp || "[]");
if (!requiredRoles.some(roleId => userRoles.has(roleId))) {
return; // User has an excluded role
return;
}
} else if (row.role_with_without_type === "without") {
const userRoles = message.member.roles.cache;
const excludedRoles = JSON.parse(row.role_with_without_xp || "[]");
if (excludedRoles.some(roleId => userRoles.has(roleId))) {
return; // User does not have any of the required roles
return;
}
} else if (row.salon_with_without_type === "with") {
const channelId = message.channel.id;
const requiredChannels = JSON.parse(row.salon_with_without_xp || "[]");
if (!requiredChannels.includes(channelId)) {
return; // Message not in a required channel
return;
}
} else if (row.salon_with_without_type === "without") {
const channelId = message.channel.id;
const excludedChannels = JSON.parse(row.salon_with_without_xp || "[]");
if (excludedChannels.includes(channelId)) {
return; // Message in an excluded channel
return;
}
}
// Logic to award XP for message goes here
const now = Date.now();
db.get(
`SELECT xp, level, last_xp_message_timestamp FROM user_levels WHERE guild_id = ? AND user_id = ?`,
@@ -65,7 +66,7 @@ module.exports = {
const lastTimestamp = userRow ? userRow.last_xp_message_timestamp || 0 : 0;
if (now - lastTimestamp < row.cooldown_xp_message_seconds * 1000) {
return; // Still in cooldown
return;
}
const minXp = row.gain_xp_message_lower_bound;
@@ -83,7 +84,6 @@ module.exports = {
newLevel = 1;
}
// Level up logic based on xp_courbe_type and multiplier goes here
const multiplier = row.multiplier_courbe_for_level;
let fonction_courbe;
@@ -103,10 +103,8 @@ module.exports = {
newLevel += 1;
xpForNextLevel = fonction_courbe(newLevel);
// Announce level up if enabled and meets the criteria
if (row.level_announcements_enabled && (newLevel % row.level_annoncement_every_level === 0)) {
const channel = message.guild.channels.cache.get(row.level_announcements_channel_id);
console.log("Channel for level announcement:", channel);
if (channel) {
let announcementMsg = row.level_announcements_message;
announcementMsg = announcementMsg
@@ -132,5 +130,43 @@ module.exports = {
);
}
);
// ===== ECONOMY MESSAGE MONEY =====
db.get(
`SELECT enabled, message_money_enabled, message_money_min, message_money_max, message_money_cooldown_seconds
FROM economy_config WHERE guild_id = ?`,
[guildId],
(err, ecoRow) => {
if (err || !ecoRow || !ecoRow.enabled || !ecoRow.message_money_enabled) return;
const now = Date.now();
db.get(
`SELECT balance, last_message_money_timestamp FROM user_economy WHERE guild_id = ? AND user_id = ?`,
[guildId, message.author.id],
(err, userEcoRow) => {
if (err) return;
const lastTimestamp = userEcoRow?.last_message_money_timestamp || 0;
if (now - lastTimestamp < ecoRow.message_money_cooldown_seconds * 1000) {
return; // Still in cooldown
}
const minMoney = ecoRow.message_money_min;
const maxMoney = ecoRow.message_money_max;
const moneyToAdd = Math.floor(Math.random() * (maxMoney - minMoney + 1)) + minMoney;
const newBalance = (userEcoRow?.balance || 0) + moneyToAdd;
db.run(
`INSERT INTO user_economy (guild_id, user_id, balance, bank, last_message_money_timestamp)
VALUES (?, ?, ?, 0, ?)
ON CONFLICT(guild_id, user_id) DO UPDATE SET
balance = ?,
last_message_money_timestamp = ?`,
[guildId, message.author.id, newBalance, now, newBalance, now]
);
}
);
}
);
},
};
+77 -2
View File
@@ -1,13 +1,20 @@
const { Events } = require("discord.js");
const db = require("../db");
// Store voice join times and intervals for economy
const voiceJoinTimes = new Map(); // guildId_oderId -> timestamp
const voiceMoneyIntervals = new Map(); // guildId_userId -> intervalId
module.exports = {
name: Events.VoiceStateUpdate,
async execute(client, oldState, newState) {
if (newState.member.user.bot) return;
const guildId = newState.guild.id;
const oderId = newState.member.id;
const key = `${guildId}_${oderId}`;
// ===== AUTOROLE VOCAL =====
db.get(
"SELECT enabled, role_id, exclude_channel_ids FROM autorole_vocal_config WHERE guild_id = ?",
[guildId],
@@ -27,15 +34,83 @@ module.exports = {
const role = newState.guild.roles.cache.get(row.role_id);
if (!role) return;
// User joins a voice channel and it's not excluded et a pas déjà le rôle
if (newState.channelId && !excludeChannelIds.includes(newState.channelId) && !newState.member.roles.cache.has(role.id)) {
newState.member.roles.add(role);
}
// User leaves a voice channel or joins an excluded one
else if (!newState.channelId || excludeChannelIds.includes(newState.channelId)) {
newState.member.roles.remove(role);
}
}
);
// ===== ECONOMY VOICE MONEY =====
db.get(
`SELECT enabled, voice_money_enabled, voice_money_min, voice_money_max, voice_money_interval_minutes
FROM economy_config WHERE guild_id = ?`,
[guildId],
(err, ecoRow) => {
if (err || !ecoRow || !ecoRow.enabled || !ecoRow.voice_money_enabled) {
// Clear interval if economy is disabled
if (voiceMoneyIntervals.has(key)) {
clearInterval(voiceMoneyIntervals.get(key));
voiceMoneyIntervals.delete(key);
voiceJoinTimes.delete(key);
}
return;
}
const intervalMs = ecoRow.voice_money_interval_minutes * 60 * 1000;
const minMoney = ecoRow.voice_money_min;
const maxMoney = ecoRow.voice_money_max;
// User joined a voice channel
if (newState.channelId && !oldState.channelId) {
voiceJoinTimes.set(key, Date.now());
// Start interval for giving money
const intervalId = setInterval(() => {
// Check if user is still in voice
const member = newState.guild.members.cache.get(oderId);
if (!member || !member.voice.channelId) {
clearInterval(intervalId);
voiceMoneyIntervals.delete(key);
voiceJoinTimes.delete(key);
return;
}
// Check if user is deafened or muted (optional: don't give money if AFK)
// You can customize this behavior
const moneyToAdd = Math.floor(Math.random() * (maxMoney - minMoney + 1)) + minMoney;
db.get(
`SELECT balance FROM user_economy WHERE guild_id = ? AND user_id = ?`,
[guildId, oderId],
(err, userRow) => {
if (err) return;
const newBalance = (userRow?.balance || 0) + moneyToAdd;
db.run(
`INSERT INTO user_economy (guild_id, user_id, balance, bank)
VALUES (?, ?, ?, 0)
ON CONFLICT(guild_id, user_id) DO UPDATE SET balance = ?`,
[guildId, oderId, newBalance, newBalance]
);
}
);
}, intervalMs);
voiceMoneyIntervals.set(key, intervalId);
}
// User left voice channel
else if (!newState.channelId && oldState.channelId) {
if (voiceMoneyIntervals.has(key)) {
clearInterval(voiceMoneyIntervals.get(key));
voiceMoneyIntervals.delete(key);
}
voiceJoinTimes.delete(key);
}
}
);
},
};
+89 -2
View File
@@ -291,7 +291,12 @@
<input type="number" id="economy-starting-balance" min="0" value="0" />
</label>
<h3>📅 Récompense quotidienne</h3>
<h3>📅 Récompense quotidienne (daily)</h3>
<label>
<input type="checkbox" id="economy-daily-enabled" checked />
Activer la commande daily
</label>
<label>
Montant quotidien :
<br />
@@ -304,7 +309,12 @@
<input type="number" id="economy-daily-cooldown" min="1" value="24" />
</label>
<h3>💼 Travail</h3>
<h3>💼 Travail (work)</h3>
<label>
<input type="checkbox" id="economy-work-enabled" checked />
Activer la commande work
</label>
<label>
Gain minimum :
<br />
@@ -324,6 +334,11 @@
</label>
<h3>🔫 Crime</h3>
<label>
<input type="checkbox" id="economy-crime-enabled" checked />
Activer la commande crime
</label>
<label>
Gain minimum :
<br />
@@ -354,6 +369,78 @@
<input type="number" id="economy-crime-cooldown" min="1" value="120" />
</label>
<h3>🕵️ Vol (steal)</h3>
<label>
<input type="checkbox" id="economy-steal-enabled" checked />
Activer la commande steal (voler d'autres joueurs)
</label>
<label>
Taux de réussite (%) :
<br />
<input type="number" id="economy-steal-success" min="1" max="100" value="40" />
</label>
<label>
% maximum du portefeuille volable :
<br />
<input type="number" id="economy-steal-max-percent" min="1" max="100" value="50" />
</label>
<label>
Amende en cas d'échec (% de votre solde, donné à la victime) :
<br />
<input type="number" id="economy-steal-fine" min="0" max="100" value="25" />
</label>
<label>
Cooldown (minutes) :
<br />
<input type="number" id="economy-steal-cooldown" min="1" value="180" />
</label>
<h3>💬 Argent par message</h3>
<label>
<input type="checkbox" id="economy-message-money-enabled" />
Gagner de l'argent en envoyant des messages
</label>
<label>
Gain par message :
<br />
Entre
<input type="number" id="economy-message-money-min" min="1" value="1" />
et
<input type="number" id="economy-message-money-max" min="1" value="5" />
</label>
<label>
Cooldown (secondes) :
<br />
<input type="number" id="economy-message-money-cooldown" min="1" value="60" />
</label>
<h3>🎤 Argent en vocal</h3>
<label>
<input type="checkbox" id="economy-voice-money-enabled" />
Gagner de l'argent en étant en vocal
</label>
<label>
Gain par intervalle :
<br />
Entre
<input type="number" id="economy-voice-money-min" min="1" value="5" />
et
<input type="number" id="economy-voice-money-max" min="1" value="15" />
</label>
<label>
Intervalle de gain (minutes) :
<br />
<input type="number" id="economy-voice-money-interval" min="1" value="5" />
</label>
<button type="submit">Sauvegarder</button>
<div id="status-economy-form"></div>
</form>
+86 -1
View File
@@ -3,16 +3,45 @@ const economyEnabled = document.getElementById("economy-enabled");
const currencyName = document.getElementById("economy-currency-name");
const currencySymbol = document.getElementById("economy-currency-symbol");
const startingBalance = document.getElementById("economy-starting-balance");
// Daily
const dailyEnabled = document.getElementById("economy-daily-enabled");
const dailyAmount = document.getElementById("economy-daily-amount");
const dailyCooldown = document.getElementById("economy-daily-cooldown");
// Work
const workEnabled = document.getElementById("economy-work-enabled");
const workMin = document.getElementById("economy-work-min");
const workMax = document.getElementById("economy-work-max");
const workCooldown = document.getElementById("economy-work-cooldown");
// Crime
const crimeEnabled = document.getElementById("economy-crime-enabled");
const crimeMin = document.getElementById("economy-crime-min");
const crimeMax = document.getElementById("economy-crime-max");
const crimeSuccess = document.getElementById("economy-crime-success");
const crimeFine = document.getElementById("economy-crime-fine");
const crimeCooldown = document.getElementById("economy-crime-cooldown");
// Steal
const stealEnabled = document.getElementById("economy-steal-enabled");
const stealSuccess = document.getElementById("economy-steal-success");
const stealMaxPercent = document.getElementById("economy-steal-max-percent");
const stealFine = document.getElementById("economy-steal-fine");
const stealCooldown = document.getElementById("economy-steal-cooldown");
// Message Money
const messageMoneyEnabled = document.getElementById("economy-message-money-enabled");
const messageMoneyMin = document.getElementById("economy-message-money-min");
const messageMoneyMax = document.getElementById("economy-message-money-max");
const messageMoneyCooldown = document.getElementById("economy-message-money-cooldown");
// Voice Money
const voiceMoneyEnabled = document.getElementById("economy-voice-money-enabled");
const voiceMoneyMin = document.getElementById("economy-voice-money-min");
const voiceMoneyMax = document.getElementById("economy-voice-money-max");
const voiceMoneyInterval = document.getElementById("economy-voice-money-interval");
const statusEconomyForm = document.getElementById("status-economy-form");
// Charger la config existante
@@ -23,16 +52,44 @@ fetch(`/api/bot/get-economy-config/${guildId}`)
currencyName.value = cfg.currencyName;
currencySymbol.value = cfg.currencySymbol;
startingBalance.value = cfg.startingBalance;
// Daily
dailyEnabled.checked = cfg.dailyEnabled;
dailyAmount.value = cfg.dailyAmount;
dailyCooldown.value = cfg.dailyCooldownHours;
// Work
workEnabled.checked = cfg.workEnabled;
workMin.value = cfg.workMinAmount;
workMax.value = cfg.workMaxAmount;
workCooldown.value = cfg.workCooldownMinutes;
// Crime
crimeEnabled.checked = cfg.crimeEnabled;
crimeMin.value = cfg.crimeMinAmount;
crimeMax.value = cfg.crimeMaxAmount;
crimeSuccess.value = cfg.crimeSuccessRate;
crimeFine.value = cfg.crimeFinePercent;
crimeCooldown.value = cfg.crimeCooldownMinutes;
// Steal
stealEnabled.checked = cfg.stealEnabled;
stealSuccess.value = cfg.stealSuccessRate;
stealMaxPercent.value = cfg.stealMaxPercent;
stealFine.value = cfg.stealFinePercent;
stealCooldown.value = cfg.stealCooldownMinutes;
// Message Money
messageMoneyEnabled.checked = cfg.messageMoneyEnabled;
messageMoneyMin.value = cfg.messageMoneyMin;
messageMoneyMax.value = cfg.messageMoneyMax;
messageMoneyCooldown.value = cfg.messageMoneyCooldownSeconds;
// Voice Money
voiceMoneyEnabled.checked = cfg.voiceMoneyEnabled;
voiceMoneyMin.value = cfg.voiceMoneyMin;
voiceMoneyMax.value = cfg.voiceMoneyMax;
voiceMoneyInterval.value = cfg.voiceMoneyIntervalMinutes;
})
.catch(console.error);
@@ -49,16 +106,44 @@ economyForm.addEventListener("submit", async e => {
currencyName: currencyName.value,
currencySymbol: currencySymbol.value,
startingBalance: parseInt(startingBalance.value, 10),
// Daily
dailyEnabled: dailyEnabled.checked,
dailyAmount: parseInt(dailyAmount.value, 10),
dailyCooldownHours: parseInt(dailyCooldown.value, 10),
// Work
workEnabled: workEnabled.checked,
workMinAmount: parseInt(workMin.value, 10),
workMaxAmount: parseInt(workMax.value, 10),
workCooldownMinutes: parseInt(workCooldown.value, 10),
// Crime
crimeEnabled: crimeEnabled.checked,
crimeMinAmount: parseInt(crimeMin.value, 10),
crimeMaxAmount: parseInt(crimeMax.value, 10),
crimeSuccessRate: parseInt(crimeSuccess.value, 10),
crimeFinePercent: parseInt(crimeFine.value, 10),
crimeCooldownMinutes: parseInt(crimeCooldown.value, 10)
crimeCooldownMinutes: parseInt(crimeCooldown.value, 10),
// Steal
stealEnabled: stealEnabled.checked,
stealSuccessRate: parseInt(stealSuccess.value, 10),
stealMaxPercent: parseInt(stealMaxPercent.value, 10),
stealFinePercent: parseInt(stealFine.value, 10),
stealCooldownMinutes: parseInt(stealCooldown.value, 10),
// Message Money
messageMoneyEnabled: messageMoneyEnabled.checked,
messageMoneyMin: parseInt(messageMoneyMin.value, 10),
messageMoneyMax: parseInt(messageMoneyMax.value, 10),
messageMoneyCooldownSeconds: parseInt(messageMoneyCooldown.value, 10),
// Voice Money
voiceMoneyEnabled: voiceMoneyEnabled.checked,
voiceMoneyMin: parseInt(voiceMoneyMin.value, 10),
voiceMoneyMax: parseInt(voiceMoneyMax.value, 10),
voiceMoneyIntervalMinutes: parseInt(voiceMoneyInterval.value, 10)
})
});
+106 -43
View File
@@ -554,43 +554,78 @@ module.exports = (app, db, client) => {
router.get("/bot/get-economy-config/:guildId", (req, res) => {
const { guildId } = req.params;
// Valeurs par défaut
const defaults = {
enabled: false,
currencyName: "coins",
currencySymbol: "💰",
dailyEnabled: true,
dailyAmount: 100,
dailyCooldownHours: 24,
workEnabled: true,
workMinAmount: 50,
workMaxAmount: 150,
workCooldownMinutes: 60,
crimeEnabled: true,
crimeMinAmount: 100,
crimeMaxAmount: 500,
crimeSuccessRate: 50,
crimeFinePercent: 30,
crimeCooldownMinutes: 120,
stealEnabled: true,
stealSuccessRate: 40,
stealMaxPercent: 50,
stealFinePercent: 25,
stealCooldownMinutes: 180,
messageMoneyEnabled: false,
messageMoneyMin: 1,
messageMoneyMax: 5,
messageMoneyCooldownSeconds: 60,
voiceMoneyEnabled: false,
voiceMoneyMin: 5,
voiceMoneyMax: 15,
voiceMoneyIntervalMinutes: 5,
startingBalance: 0
};
db.get(
`SELECT * FROM economy_config WHERE guild_id = ?`,
[guildId],
(err, row) => {
if (err || !row) {
return res.json({
enabled: false,
currencyName: "coins",
currencySymbol: "💰",
dailyAmount: 100,
dailyCooldownHours: 24,
workMinAmount: 50,
workMaxAmount: 150,
workCooldownMinutes: 60,
crimeMinAmount: 100,
crimeMaxAmount: 500,
crimeSuccessRate: 50,
crimeFinePercent: 30,
crimeCooldownMinutes: 120,
startingBalance: 0
});
return res.json(defaults);
}
res.json({
enabled: !!row.enabled,
currencyName: row.currency_name,
currencySymbol: row.currency_symbol,
dailyAmount: row.daily_amount,
dailyCooldownHours: row.daily_cooldown_hours,
workMinAmount: row.work_min_amount,
workMaxAmount: row.work_max_amount,
workCooldownMinutes: row.work_cooldown_minutes,
crimeMinAmount: row.crime_min_amount,
crimeMaxAmount: row.crime_max_amount,
crimeSuccessRate: row.crime_success_rate,
crimeFinePercent: row.crime_fine_percent,
crimeCooldownMinutes: row.crime_cooldown_minutes,
startingBalance: row.starting_balance
enabled: row.enabled != null ? !!row.enabled : defaults.enabled,
currencyName: row.currency_name ?? defaults.currencyName,
currencySymbol: row.currency_symbol ?? defaults.currencySymbol,
dailyEnabled: row.daily_enabled != null ? !!row.daily_enabled : defaults.dailyEnabled,
dailyAmount: row.daily_amount ?? defaults.dailyAmount,
dailyCooldownHours: row.daily_cooldown_hours ?? defaults.dailyCooldownHours,
workEnabled: row.work_enabled != null ? !!row.work_enabled : defaults.workEnabled,
workMinAmount: row.work_min_amount ?? defaults.workMinAmount,
workMaxAmount: row.work_max_amount ?? defaults.workMaxAmount,
workCooldownMinutes: row.work_cooldown_minutes ?? defaults.workCooldownMinutes,
crimeEnabled: row.crime_enabled != null ? !!row.crime_enabled : defaults.crimeEnabled,
crimeMinAmount: row.crime_min_amount ?? defaults.crimeMinAmount,
crimeMaxAmount: row.crime_max_amount ?? defaults.crimeMaxAmount,
crimeSuccessRate: row.crime_success_rate ?? defaults.crimeSuccessRate,
crimeFinePercent: row.crime_fine_percent ?? defaults.crimeFinePercent,
crimeCooldownMinutes: row.crime_cooldown_minutes ?? defaults.crimeCooldownMinutes,
stealEnabled: row.steal_enabled != null ? !!row.steal_enabled : defaults.stealEnabled,
stealSuccessRate: row.steal_success_rate ?? defaults.stealSuccessRate,
stealMaxPercent: row.steal_max_percent ?? defaults.stealMaxPercent,
stealFinePercent: row.steal_fine_percent ?? defaults.stealFinePercent,
stealCooldownMinutes: row.steal_cooldown_minutes ?? defaults.stealCooldownMinutes,
messageMoneyEnabled: row.message_money_enabled != null ? !!row.message_money_enabled : defaults.messageMoneyEnabled,
messageMoneyMin: row.message_money_min ?? defaults.messageMoneyMin,
messageMoneyMax: row.message_money_max ?? defaults.messageMoneyMax,
messageMoneyCooldownSeconds: row.message_money_cooldown_seconds ?? defaults.messageMoneyCooldownSeconds,
voiceMoneyEnabled: row.voice_money_enabled != null ? !!row.voice_money_enabled : defaults.voiceMoneyEnabled,
voiceMoneyMin: row.voice_money_min ?? defaults.voiceMoneyMin,
voiceMoneyMax: row.voice_money_max ?? defaults.voiceMoneyMax,
voiceMoneyIntervalMinutes: row.voice_money_interval_minutes ?? defaults.voiceMoneyIntervalMinutes,
startingBalance: row.starting_balance ?? defaults.startingBalance
});
}
);
@@ -602,16 +637,32 @@ module.exports = (app, db, client) => {
economyEnabled,
currencyName,
currencySymbol,
dailyEnabled,
dailyAmount,
dailyCooldownHours,
workEnabled,
workMinAmount,
workMaxAmount,
workCooldownMinutes,
crimeEnabled,
crimeMinAmount,
crimeMaxAmount,
crimeSuccessRate,
crimeFinePercent,
crimeCooldownMinutes,
stealEnabled,
stealSuccessRate,
stealMaxPercent,
stealFinePercent,
stealCooldownMinutes,
messageMoneyEnabled,
messageMoneyMin,
messageMoneyMax,
messageMoneyCooldownSeconds,
voiceMoneyEnabled,
voiceMoneyMin,
voiceMoneyMax,
voiceMoneyIntervalMinutes,
startingBalance
} = req.body;
@@ -630,28 +681,40 @@ module.exports = (app, db, client) => {
db.run(
`INSERT INTO economy_config (
guild_id, enabled, currency_name, currency_symbol,
daily_amount, daily_cooldown_hours,
work_min_amount, work_max_amount, work_cooldown_minutes,
crime_min_amount, crime_max_amount, crime_success_rate, crime_fine_percent, crime_cooldown_minutes,
daily_enabled, daily_amount, daily_cooldown_hours,
work_enabled, work_min_amount, work_max_amount, work_cooldown_minutes,
crime_enabled, crime_min_amount, crime_max_amount, crime_success_rate, crime_fine_percent, crime_cooldown_minutes,
steal_enabled, steal_success_rate, steal_max_percent, steal_fine_percent, steal_cooldown_minutes,
message_money_enabled, message_money_min, message_money_max, message_money_cooldown_seconds,
voice_money_enabled, voice_money_min, voice_money_max, voice_money_interval_minutes,
starting_balance
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(guild_id) DO UPDATE SET
enabled = ?, currency_name = ?, currency_symbol = ?,
daily_amount = ?, daily_cooldown_hours = ?,
work_min_amount = ?, work_max_amount = ?, work_cooldown_minutes = ?,
crime_min_amount = ?, crime_max_amount = ?, crime_success_rate = ?, crime_fine_percent = ?, crime_cooldown_minutes = ?,
daily_enabled = ?, daily_amount = ?, daily_cooldown_hours = ?,
work_enabled = ?, work_min_amount = ?, work_max_amount = ?, work_cooldown_minutes = ?,
crime_enabled = ?, crime_min_amount = ?, crime_max_amount = ?, crime_success_rate = ?, crime_fine_percent = ?, crime_cooldown_minutes = ?,
steal_enabled = ?, steal_success_rate = ?, steal_max_percent = ?, steal_fine_percent = ?, steal_cooldown_minutes = ?,
message_money_enabled = ?, message_money_min = ?, message_money_max = ?, message_money_cooldown_seconds = ?,
voice_money_enabled = ?, voice_money_min = ?, voice_money_max = ?, voice_money_interval_minutes = ?,
starting_balance = ?`,
[
guildId,
economyEnabled ? 1 : 0, currencyName, currencySymbol,
dailyAmount, dailyCooldownHours,
workMinAmount, workMaxAmount, workCooldownMinutes,
crimeMinAmount, crimeMaxAmount, crimeSuccessRate, crimeFinePercent, crimeCooldownMinutes,
dailyEnabled ? 1 : 0, dailyAmount, dailyCooldownHours,
workEnabled ? 1 : 0, workMinAmount, workMaxAmount, workCooldownMinutes,
crimeEnabled ? 1 : 0, crimeMinAmount, crimeMaxAmount, crimeSuccessRate, crimeFinePercent, crimeCooldownMinutes,
stealEnabled ? 1 : 0, stealSuccessRate, stealMaxPercent, stealFinePercent, stealCooldownMinutes,
messageMoneyEnabled ? 1 : 0, messageMoneyMin, messageMoneyMax, messageMoneyCooldownSeconds,
voiceMoneyEnabled ? 1 : 0, voiceMoneyMin, voiceMoneyMax, voiceMoneyIntervalMinutes,
startingBalance,
economyEnabled ? 1 : 0, currencyName, currencySymbol,
dailyAmount, dailyCooldownHours,
workMinAmount, workMaxAmount, workCooldownMinutes,
crimeMinAmount, crimeMaxAmount, crimeSuccessRate, crimeFinePercent, crimeCooldownMinutes,
dailyEnabled ? 1 : 0, dailyAmount, dailyCooldownHours,
workEnabled ? 1 : 0, workMinAmount, workMaxAmount, workCooldownMinutes,
crimeEnabled ? 1 : 0, crimeMinAmount, crimeMaxAmount, crimeSuccessRate, crimeFinePercent, crimeCooldownMinutes,
stealEnabled ? 1 : 0, stealSuccessRate, stealMaxPercent, stealFinePercent, stealCooldownMinutes,
messageMoneyEnabled ? 1 : 0, messageMoneyMin, messageMoneyMax, messageMoneyCooldownSeconds,
voiceMoneyEnabled ? 1 : 0, voiceMoneyMin, voiceMoneyMax, voiceMoneyIntervalMinutes,
startingBalance
],
err => {