Files
YouTube.js/src/parser/classes/livechat/items/LiveChatPaidMessage.ts
Chinmay Kumar cfc1a183e0 refactor(parser): type YTNodes' data arg as RawNode (wip) (#339)
* replaced YTNode's data arg as RawNode

* updated documentation

* removed unused import

---- Note that there are still many nodes that need to be updated, hence the WIP status.
2023-03-07 02:02:07 -03:00

67 lines
2.5 KiB
TypeScript

import { observe, ObservedArray, YTNode } from '../../../helpers.js';
import Parser from '../../../index.js';
import LiveChatAuthorBadge from '../../LiveChatAuthorBadge.js';
import MetadataBadge from '../../MetadataBadge.js';
import Text from '../../misc/Text.js';
import Thumbnail from '../../misc/Thumbnail.js';
import NavigationEndpoint from '../../NavigationEndpoint.js';
import type { RawNode } from '../../../index.js';
class LiveChatPaidMessage extends YTNode {
static type = 'LiveChatPaidMessage';
message: Text;
author: {
id: string;
name: Text;
thumbnails: Thumbnail[];
badges: ObservedArray<LiveChatAuthorBadge | MetadataBadge>;
is_moderator: boolean | null;
is_verified: boolean | null;
is_verified_artist: boolean | null;
};
header_background_color: number;
header_text_color: number;
body_background_color: number;
body_text_color: number;
purchase_amount: string;
menu_endpoint: NavigationEndpoint;
timestamp: number;
timestamp_text: string;
id: string;
constructor(data: RawNode) {
super();
this.message = new Text(data.message);
this.author = {
id: data.authorExternalChannelId,
name: new Text(data.authorName),
thumbnails: Thumbnail.fromResponse(data.authorPhoto),
badges: observe([]).as(LiveChatAuthorBadge, MetadataBadge),
is_moderator: null,
is_verified: null,
is_verified_artist: null
};
const badges = Parser.parseArray<LiveChatAuthorBadge | MetadataBadge>(data.authorBadges, [ MetadataBadge, LiveChatAuthorBadge ]);
this.author.badges = badges;
this.author.is_moderator = badges ? badges.some((badge) => badge.icon_type == 'MODERATOR') : null;
this.author.is_verified = badges ? badges.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') : null;
this.author.is_verified_artist = badges ? badges.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') : null;
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.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
this.timestamp_text = new Text(data.timestampText).toString();
this.id = data.id;
}
}
export default LiveChatPaidMessage;