Package and Activity Status Update

This commit is contained in:
2025-12-06 23:38:07 +00:00
parent 6461d7ceb5
commit 59d39c9939
4 changed files with 23 additions and 8 deletions
+14 -2
View File
@@ -6,7 +6,7 @@ class Bot {
private client: Client;
// Normalize a discord.js Activity object into a simple POJO
private mapActivity(a: any) {
private async mapActivity(a: any) {
const type = typeof a.type === 'number' ? a.type : (ActivityType[a.type] ?? a.type);
const application_id = a.applicationId ?? a.application_id ?? null;
@@ -23,6 +23,17 @@ class Bot {
return raw;
};
let app_icon = null;
if (type === 0 && application_id) {
try {
const appUser = await this.client.users.fetch(application_id);
app_icon = appUser.displayAvatarURL({ extension: 'webp', size: 128 });
} catch (e) {
// Placeholder for apps that don't have a bot user
app_icon = "https://cdn.discordapp.com/embed/avatars/0.png";
}
}
return {
name: a.name ?? null,
type,
@@ -33,6 +44,7 @@ class Bot {
large_image: formatAsset(rawLarge),
small_image: formatAsset(rawSmall)
},
app_icon,
emoji: a.emoji ? { id: a.emoji.id ?? null, animated: !!a.emoji.animated } : null
};
}
@@ -91,7 +103,7 @@ class Bot {
if (!presence) return { guildId, status: 'offline', activities: [], displayName: member.displayName, avatarUrl, guildTag, guildTagBadgeImage };
const status = presence.status;
const activities = (presence.activities || []).map((a: any) => this.mapActivity(a));
const activities = await Promise.all((presence.activities || []).map(async (a: any) => await this.mapActivity(a)));
return { guildId, status, activities, displayName: member.displayName, avatarUrl, guildTag, guildTagBadgeImage };
} catch (err) {