Skip to content

Commit

Permalink
feat(LiveChatPaidMessage): Parse headerOverlayImage and `lowerBumpe…
Browse files Browse the repository at this point in the history
…r` (#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
  • Loading branch information
jonz94 authored Dec 22, 2024
1 parent 06df214 commit ef37aa0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/parser/classes/livechat/items/BumperUserEduContentView.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
14 changes: 14 additions & 0 deletions src/parser/classes/livechat/items/LiveChatItemBumperView.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 10 additions & 0 deletions src/parser/classes/livechat/items/LiveChatPaidMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ 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';
export { default as LiveChatBannerChatSummary } from './classes/livechat/items/LiveChatBannerChatSummary.js';
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';
Expand Down

0 comments on commit ef37aa0

Please sign in to comment.