feat: extract and display membership gift counts in chat messages

This commit is contained in:
Yusuf İpek
2025-10-05 19:13:06 +03:00
parent d2a99639b7
commit f1dd130bc0
4 changed files with 29 additions and 8 deletions
+16 -2
View File
@@ -257,6 +257,19 @@ function normalizeAction(action: any): ChatMessage | null {
(isPaid ? undefined : 'New member');
}
// Extract gift count for gift purchases
let giftCount: number | undefined;
if (isGiftPurchase) {
const text = resolveMessageText(item);
const headerText = item.header_primary_text?.toString() || item.header_subtext?.toString() || '';
const combinedText = text + ' ' + headerText;
// Try to extract number from text like "Gifted 5 memberships" or "5 memberships"
const countMatch = combinedText.match(/(\d+)\s*(?:membership|memberships|member|members)/i);
if (countMatch) {
giftCount = parseInt(countMatch[1], 10);
}
}
return {
id: String(item.id ?? item.timestamp_usec ?? Date.now()),
author: String(item.author?.name ?? 'Unknown'),
@@ -268,9 +281,10 @@ function normalizeAction(action: any): ChatMessage | null {
isMember,
isVerified,
superChat: extractSuperChatInfo(item),
membershipGift: isMembership || isGiftReceived,
membershipGift: isMembership,
membershipGiftPurchase: isGiftPurchase,
membershipLevel
membershipLevel,
giftCount
};
}