refactor: improve livechat parser & add remaining action nodes (#285)

* refactor: improve live chat parsers & add missing nodes

* chore: update example and docs

* docs: rephrasing/formatting

* chore: remove unneeded test (unrelated)
This commit is contained in:
LuanRT
2023-01-10 01:44:51 -03:00
committed by GitHub
parent 5a362a0bd5
commit 8e37efa575
35 changed files with 413 additions and 182 deletions

View File

@@ -1,8 +1,10 @@
import { observe, ObservedArray, YTNode } from '../../../helpers';
import Parser from '../../../index';
import NavigationEndpoint from '../../NavigationEndpoint';
import Thumbnail from '../../misc/Thumbnail';
import LiveChatAuthorBadge from '../../LiveChatAuthorBadge';
import MetadataBadge from '../../MetadataBadge';
import Text from '../../misc/Text';
import { YTNode } from '../../../helpers';
import Thumbnail from '../../misc/Thumbnail';
import NavigationEndpoint from '../../NavigationEndpoint';
class LiveChatPaidSticker extends YTNode {
static type = 'LiveChatPaidSticker';
@@ -13,7 +15,10 @@ class LiveChatPaidSticker extends YTNode {
id: string;
name: Text;
thumbnails: Thumbnail[];
badges: any;
badges: ObservedArray<LiveChatAuthorBadge | MetadataBadge>;
is_moderator: boolean | null;
is_verified: boolean | null;
is_verified_artist: boolean | null;
};
money_chip_background_color: number;
@@ -34,9 +39,19 @@ class LiveChatPaidSticker extends YTNode {
id: data.authorExternalChannelId,
name: new Text(data.authorName),
thumbnails: Thumbnail.fromResponse(data.authorPhoto),
badges: Parser.parse(data.authorBadges)
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.money_chip_background_color = data.moneyChipBackgroundColor;
this.money_chip_text_color = data.moneyChipTextColor;
this.background_color = data.backgroundColor;