From ef37aa0a5abb573f192f86d1accb88d90d707752 Mon Sep 17 00:00:00 2001 From: jonz94 Date: Mon, 23 Dec 2024 03:08:37 +0800 Subject: [PATCH] feat(LiveChatPaidMessage): Parse `headerOverlayImage` and `lowerBumper` (#851) * feat(LiveChatPaidMessage): Parse `headerOverlayImage` and `lowerBumper` When a viewer donates for the 1st, 3rd, 5th, 10th, or 20th time, there will be a special type of `LiveChatPaidMessage` that includes an animated image in the header, followed by a bumper text message. * chore: npm run build:parser-map --- .../livechat/items/BumperUserEduContentView.ts | 18 ++++++++++++++++++ .../livechat/items/LiveChatItemBumperView.ts | 14 ++++++++++++++ .../livechat/items/LiveChatPaidMessage.ts | 10 ++++++++++ src/parser/nodes.ts | 2 ++ 4 files changed, 44 insertions(+) create mode 100644 src/parser/classes/livechat/items/BumperUserEduContentView.ts create mode 100644 src/parser/classes/livechat/items/LiveChatItemBumperView.ts diff --git a/src/parser/classes/livechat/items/BumperUserEduContentView.ts b/src/parser/classes/livechat/items/BumperUserEduContentView.ts new file mode 100644 index 000000000..a4aa6dabb --- /dev/null +++ b/src/parser/classes/livechat/items/BumperUserEduContentView.ts @@ -0,0 +1,18 @@ +import { YTNode } from '../../../helpers.js'; +import { type RawNode } from '../../../index.js'; +import Text from '../../misc/Text.js'; + +export default class BumperUserEduContentView extends YTNode { + static type = 'BumperUserEduContentView'; + + text: Text; + image_name: string; + image_color: number; + + constructor(data: RawNode) { + super(); + this.text = Text.fromAttributed(data.text); + this.image_name = data.image.sources[0].clientResource.imageName; + this.image_color = data.image.sources[0].clientResource.imageColor; + } +} \ No newline at end of file diff --git a/src/parser/classes/livechat/items/LiveChatItemBumperView.ts b/src/parser/classes/livechat/items/LiveChatItemBumperView.ts new file mode 100644 index 000000000..e491daf45 --- /dev/null +++ b/src/parser/classes/livechat/items/LiveChatItemBumperView.ts @@ -0,0 +1,14 @@ +import { YTNode } from '../../../helpers.js'; +import { Parser, type RawNode } from '../../../index.js'; +import BumperUserEduContentView from './BumperUserEduContentView.js'; + +export default class LiveChatItemBumperView extends YTNode { + static type = 'LiveChatItemBumperView'; + + content: BumperUserEduContentView | null; + + constructor(data: RawNode) { + super(); + this.content = Parser.parseItem(data.content, BumperUserEduContentView); + } +} \ No newline at end of file diff --git a/src/parser/classes/livechat/items/LiveChatPaidMessage.ts b/src/parser/classes/livechat/items/LiveChatPaidMessage.ts index 37be364e8..6c0935c2c 100644 --- a/src/parser/classes/livechat/items/LiveChatPaidMessage.ts +++ b/src/parser/classes/livechat/items/LiveChatPaidMessage.ts @@ -3,7 +3,9 @@ import { Parser, type RawNode } from '../../../index.js'; import NavigationEndpoint from '../../NavigationEndpoint.js'; import Author from '../../misc/Author.js'; import Text from '../../misc/Text.js'; +import Thumbnail from '../../misc/Thumbnail.js'; import CreatorHeartView from './CreatorHeartView.js'; +import LiveChatItemBumperView from './LiveChatItemBumperView.js'; import PdgReplyButtonView from './PdgReplyButtonView.js'; export default class LiveChatPaidMessage extends YTNode { @@ -24,7 +26,9 @@ export default class LiveChatPaidMessage extends YTNode { timestamp_usec: string; timestamp_text?: string; timestamp_color: number; + header_overlay_image?: Thumbnail[]; text_input_background_color: number; + lower_bumper: LiveChatItemBumperView | null; creator_heart_button: CreatorHeartView | null; is_v2_style: boolean; reply_button: PdgReplyButtonView | null; @@ -57,7 +61,13 @@ export default class LiveChatPaidMessage extends YTNode { } this.timestamp_color = data.timestampColor; + + if (Reflect.has(data, 'headerOverlayImage')) { + this.header_overlay_image = Thumbnail.fromResponse(data.headerOverlayImage); + } + this.text_input_background_color = data.textInputBackgroundColor; + this.lower_bumper = Parser.parseItem(data.lowerBumper, LiveChatItemBumperView); this.creator_heart_button = Parser.parseItem(data.creatorHeartButton, CreatorHeartView); this.is_v2_style = data.isV2Style; this.reply_button = Parser.parseItem(data.replyButton, PdgReplyButtonView); diff --git a/src/parser/nodes.ts b/src/parser/nodes.ts index 1912d2a76..1e54749d3 100644 --- a/src/parser/nodes.ts +++ b/src/parser/nodes.ts @@ -220,6 +220,7 @@ export { default as AddBannerToLiveChatCommand } from './classes/livechat/AddBan export { default as AddChatItemAction } from './classes/livechat/AddChatItemAction.js'; export { default as AddLiveChatTickerItemAction } from './classes/livechat/AddLiveChatTickerItemAction.js'; export { default as DimChatItemAction } from './classes/livechat/DimChatItemAction.js'; +export { default as BumperUserEduContentView } from './classes/livechat/items/BumperUserEduContentView.js'; export { default as CreatorHeartView } from './classes/livechat/items/CreatorHeartView.js'; export { default as LiveChatAutoModMessage } from './classes/livechat/items/LiveChatAutoModMessage.js'; export { default as LiveChatBanner } from './classes/livechat/items/LiveChatBanner.js'; @@ -227,6 +228,7 @@ export { default as LiveChatBannerChatSummary } from './classes/livechat/items/L export { default as LiveChatBannerHeader } from './classes/livechat/items/LiveChatBannerHeader.js'; export { default as LiveChatBannerPoll } from './classes/livechat/items/LiveChatBannerPoll.js'; export { default as LiveChatBannerRedirect } from './classes/livechat/items/LiveChatBannerRedirect.js'; +export { default as LiveChatItemBumperView } from './classes/livechat/items/LiveChatItemBumperView.js'; export { default as LiveChatMembershipItem } from './classes/livechat/items/LiveChatMembershipItem.js'; export { default as LiveChatModeChangeMessage } from './classes/livechat/items/LiveChatModeChangeMessage.js'; export { default as LiveChatPaidMessage } from './classes/livechat/items/LiveChatPaidMessage.js';