Introduces customizable welcome cards using the canvas library and enhances the XP tracking system to incorporate active seasonal events with multipliers and bonus XP. Also adds presets and custom creation for seasonal events. Replit-Commit-Author: Agent Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: 6d6bb71e-5e8e-4841-9c13-fd5e76c7d9e6 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/auRwRay Replit-Helium-Checkpoint-Created: true
72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
const seasonalEventCache = new Map();
|
|
const CACHE_TTL = 60000;
|
|
|
|
async function getActiveSeasonalEvents(supabase, guildId) {
|
|
const now = Date.now();
|
|
const cacheKey = guildId;
|
|
const cached = seasonalEventCache.get(cacheKey);
|
|
|
|
if (cached && (now - cached.timestamp < CACHE_TTL)) {
|
|
return cached.events;
|
|
}
|
|
|
|
try {
|
|
const currentTime = new Date().toISOString();
|
|
const { data: events, error } = await supabase
|
|
.from('seasonal_events')
|
|
.select('*')
|
|
.eq('guild_id', guildId)
|
|
.lte('start_date', currentTime)
|
|
.gte('end_date', currentTime);
|
|
|
|
if (error) {
|
|
seasonalEventCache.set(cacheKey, { events: [], timestamp: now });
|
|
return [];
|
|
}
|
|
|
|
const activeEvents = events || [];
|
|
seasonalEventCache.set(cacheKey, { events: activeEvents, timestamp: now });
|
|
return activeEvents;
|
|
} catch (e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
function getSeasonalMultiplier(events) {
|
|
if (!events || events.length === 0) return 1;
|
|
|
|
let highestMultiplier = 1;
|
|
for (const event of events) {
|
|
if (event.xp_multiplier && event.xp_multiplier > highestMultiplier) {
|
|
highestMultiplier = event.xp_multiplier;
|
|
}
|
|
}
|
|
return highestMultiplier;
|
|
}
|
|
|
|
function getSeasonalBonusCoins(events) {
|
|
if (!events || events.length === 0) return 0;
|
|
|
|
let totalBonus = 0;
|
|
for (const event of events) {
|
|
if (event.bonus_coins) {
|
|
totalBonus += event.bonus_coins;
|
|
}
|
|
}
|
|
return totalBonus;
|
|
}
|
|
|
|
function clearSeasonalCache(guildId) {
|
|
if (guildId) {
|
|
seasonalEventCache.delete(guildId);
|
|
} else {
|
|
seasonalEventCache.clear();
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getActiveSeasonalEvents,
|
|
getSeasonalMultiplier,
|
|
getSeasonalBonusCoins,
|
|
clearSeasonalCache
|
|
};
|