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
+46 -10
View File
@@ -7,7 +7,8 @@ module.exports = {
if (message.author.bot) return;
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]
);
}
);
}
);
},
};
+78 -3
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);
}
}
);
},
};