Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser): Update LiveChatPaidMessage #846

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/parser/classes/livechat/items/CreatorHeartView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { YTNode } from '../../../helpers.js';
import type { RawNode } from '../../../index.js';
import Thumbnail from '../../misc/Thumbnail.js';

export default class CreatorHeartView extends YTNode {
static type = 'CreatorHeartView';

creator_thumbnail: Thumbnail[];
hearted_icon_name: string;
unhearted_icon_name: string;
unhearted_icon_processor: {
border_image_processor: {
image_tint: {
color: number
}
}
};
hearted_hover_text: string;
hearted_accessibility_label: string;
unhearted_accessibility_label: string;
engagement_state_key: string;

constructor(data: RawNode) {
super();
this.creator_thumbnail = Thumbnail.fromResponse(data.creatorThumbnail);
this.hearted_icon_name = data.heartedIcon.sources[0].clientResource.imageName;
this.unhearted_icon_name = data.unheartedIcon.sources[0].clientResource.imageName;
this.unhearted_icon_processor = {
border_image_processor: {
image_tint: {
color: data.unheartedIcon.processor.borderImageProcessor.imageTint.color
}
}
};
this.hearted_hover_text = data.heartedHoverText;
this.hearted_accessibility_label = data.heartedAccessibilityLabel;
this.unhearted_accessibility_label = data.unheartedAccessibilityLabel;
this.engagement_state_key = data.engagementStateKey;
}
}
32 changes: 27 additions & 5 deletions src/parser/classes/livechat/items/LiveChatPaidMessage.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import { YTNode } from '../../../helpers.js';
import type { RawNode } from '../../../index.js';
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 CreatorHeartView from './CreatorHeartView.js';
import PdgReplyButtonView from './PdgReplyButtonView.js';

export default class LiveChatPaidMessage extends YTNode {
static type = 'LiveChatPaidMessage';

id: string;
message: Text;
author: Author;
author_name_text_color: number;
header_background_color: number;
header_text_color: number;
body_background_color: number;
body_text_color: number;
purchase_amount: string;
menu_endpoint: NavigationEndpoint;
context_menu_accessibility_label: string;
timestamp: number;
timestamp_text: string;
id: string;
timestamp_usec: string;
timestamp_text?: string;
timestamp_color: number;
text_input_background_color: number;
creator_heart_button: CreatorHeartView | null;
is_v2_style: boolean;
reply_button: PdgReplyButtonView | null;

constructor(data: RawNode) {
super();
this.id = data.id;
this.message = new Text(data.message);

this.author = new Author(
Expand All @@ -30,14 +41,25 @@ export default class LiveChatPaidMessage extends YTNode {
data.authorExternalChannelId
);

this.author_name_text_color = data.authorNameTextColor;
this.header_background_color = data.headerBackgroundColor;
this.header_text_color = data.headerTextColor;
this.body_background_color = data.bodyBackgroundColor;
this.body_text_color = data.bodyTextColor;
this.purchase_amount = new Text(data.purchaseAmountText).toString();
this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint);
this.context_menu_accessibility_label = data.contextMenuAccessibility.accessibilityData.label;
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
this.timestamp_text = new Text(data.timestampText).toString();
this.id = data.id;
this.timestamp_usec = data.timestampUsec;

if (Reflect.has(data, 'timestampText')) {
this.timestamp_text = new Text(data.timestampText).toString();
}

this.timestamp_color = data.timestampColor;
this.text_input_background_color = data.textInputBackgroundColor;
this.creator_heart_button = Parser.parseItem(data.creatorHeartButton, CreatorHeartView);
this.is_v2_style = data.isV2Style;
this.reply_button = Parser.parseItem(data.replyButton, PdgReplyButtonView);
}
}
19 changes: 19 additions & 0 deletions src/parser/classes/livechat/items/PdgReplyButtonView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { YTNode } from '../../../helpers.js';
import { Parser, type RawNode } from '../../../index.js';
import ButtonView from '../../ButtonView.js';
import Text from '../../misc/Text.js';

export default class PdgReplyButtonView extends YTNode {
static type = 'PdgReplyButtonView';

reply_button: ButtonView | null;
reply_count_entity_key: string;
reply_count_placeholder: Text;

constructor(data: RawNode) {
super();
this.reply_button = Parser.parseItem(data.replyButton, ButtonView);
this.reply_count_entity_key = data.replyCountEntityKey;
this.reply_count_placeholder = Text.fromAttributed(data.replyCountPlaceholder);
}
}
2 changes: 2 additions & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 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';
Expand All @@ -241,6 +242,7 @@ export { default as LiveChatTickerPaidMessageItem } from './classes/livechat/ite
export { default as LiveChatTickerPaidStickerItem } from './classes/livechat/items/LiveChatTickerPaidStickerItem.js';
export { default as LiveChatTickerSponsorItem } from './classes/livechat/items/LiveChatTickerSponsorItem.js';
export { default as LiveChatViewerEngagementMessage } from './classes/livechat/items/LiveChatViewerEngagementMessage.js';
export { default as PdgReplyButtonView } from './classes/livechat/items/PdgReplyButtonView.js';
export { default as PollHeader } from './classes/livechat/items/PollHeader.js';
export { default as LiveChatActionPanel } from './classes/livechat/LiveChatActionPanel.js';
export { default as MarkChatItemAsDeletedAction } from './classes/livechat/MarkChatItemAsDeletedAction.js';
Expand Down
Loading