forked from syntaxbullet/AuroraBot-discord
feat: more stat components
This commit is contained in:
@@ -37,8 +37,38 @@ export const DashboardStatsSchema = z.object({
|
||||
totalWealth: z.string(),
|
||||
avgLevel: z.number(),
|
||||
topStreak: z.number(),
|
||||
totalItems: z.number().optional(),
|
||||
}),
|
||||
recentEvents: z.array(RecentEventSchema),
|
||||
activeLootdrops: z.array(z.object({
|
||||
rewardAmount: z.number(),
|
||||
currency: z.string(),
|
||||
createdAt: z.string(),
|
||||
expiresAt: z.string().nullable(),
|
||||
})).optional(),
|
||||
lootdropState: z.object({
|
||||
monitoredChannels: z.number(),
|
||||
hottestChannel: z.object({
|
||||
id: z.string(),
|
||||
messages: z.number(),
|
||||
progress: z.number(),
|
||||
cooldown: z.boolean(),
|
||||
}).nullable(),
|
||||
config: z.object({
|
||||
requiredMessages: z.number(),
|
||||
dropChance: z.number(),
|
||||
}),
|
||||
}).optional(),
|
||||
leaderboards: z.object({
|
||||
topLevels: z.array(z.object({
|
||||
username: z.string(),
|
||||
level: z.number(),
|
||||
})),
|
||||
topWealth: z.array(z.object({
|
||||
username: z.string(),
|
||||
balance: z.string(),
|
||||
})),
|
||||
}).optional(),
|
||||
uptime: z.number(),
|
||||
lastCommandTimestamp: z.number().nullable(),
|
||||
maintenanceMode: z.boolean(),
|
||||
|
||||
@@ -163,6 +163,43 @@ class LootdropService {
|
||||
return { success: false, error: "An error occurred while processing the reward." };
|
||||
}
|
||||
}
|
||||
public getLootdropState() {
|
||||
let hottestChannel: { id: string; messages: number; progress: number; cooldown: boolean; } | null = null;
|
||||
let maxMessages = -1;
|
||||
|
||||
const window = config.lootdrop.activityWindowMs;
|
||||
const now = Date.now();
|
||||
const required = config.lootdrop.minMessages;
|
||||
|
||||
for (const [channelId, timestamps] of this.channelActivity.entries()) {
|
||||
// Filter valid just to be sure we are reporting accurate numbers
|
||||
const validCount = timestamps.filter(t => now - t < window).length;
|
||||
|
||||
// Check cooldown
|
||||
const cooldownUntil = this.channelCooldowns.get(channelId);
|
||||
const isOnCooldown = !!(cooldownUntil && now < cooldownUntil);
|
||||
|
||||
if (validCount > maxMessages) {
|
||||
maxMessages = validCount;
|
||||
hottestChannel = {
|
||||
id: channelId,
|
||||
messages: validCount,
|
||||
progress: Math.min(100, (validCount / required) * 100),
|
||||
cooldown: isOnCooldown
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
monitoredChannels: this.channelActivity.size,
|
||||
hottestChannel,
|
||||
config: {
|
||||
requiredMessages: required,
|
||||
dropChance: config.lootdrop.spawnChance
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public async clearCaches() {
|
||||
this.channelActivity.clear();
|
||||
this.channelCooldowns.clear();
|
||||
|
||||
Reference in New Issue
Block a user