refactor!: finish parser migration

Finally! :)

This removes all code related to the old parser.

#65
This commit is contained in:
LuanRT
2022-07-11 06:19:10 -03:00
parent 947fd7895b
commit 68cb841c00
285 changed files with 492 additions and 1680 deletions

View File

@@ -0,0 +1,19 @@
'use strict';
const Parser = require('../../..');
class LiveChatBanner {
type = 'LiveChatBanner';
constructor(data) {
this.header = Parser.parse(data.header, 'livechat/items');
this.contents = Parser.parse(data.contents, 'livechat/items');
this.action_id = data.actionId;
this.viewer_is_creator = data.viewerIsCreator;
this.target_id = data.targetId;
this.is_stackable = data.isStackable;
this.background_type = data.backgroundType;
}
}
module.exports = LiveChatBanner;

View File

@@ -0,0 +1,16 @@
'use strict';
const Parser = require('../../..');
const Text = require('../../Text');
class LiveChatBannerHeader {
type = 'LiveChatBannerHeader';
constructor(data) {
this.text = new Text(data.text).toString();
this.icon_type = data.icon.iconType;
this.context_menu_button = Parser.parse(data.contextMenuButton);
}
}
module.exports = LiveChatBannerHeader;

View File

@@ -0,0 +1,25 @@
'use strict';
const Parser = require('../../..');
const Text = require('../../Text');
const Thumbnail = require('../../Thumbnail');
class LiveChatBannerPoll {
type = 'LiveChatBannerPoll';
constructor(data) {
this.poll_question = new Text(data.pollQuestion);
this.author_photo = Thumbnail.fromResponse(data.authorPhoto);
this.choices = data.pollChoices.map((choice) => ({
option_id: choice.pollOptionId,
text: new Text(choice.text).toString()
}));
this.collapsed_state_entity_key = data.collapsedStateEntityKey;
this.live_chat_poll_state_entity_key = data.liveChatPollStateEntityKey;
this.context_menu_button = Parser.parse(data.contextMenuButton);
}
}
module.exports = LiveChatBannerPoll;

View File

@@ -0,0 +1,27 @@
'use strict';
const Parser = require('../../..');
const Text = require('../../Text');
const Thumbnail = require('../../Thumbnail');
const NavigationEndpoint = require('../../NavigationEndpoint');
class LiveChatMembershipItem {
type = 'LiveChatMembershipItem';
constructor(data) {
this.id = data.id;
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
this.header_subtext = new Text(data.headerSubtext);
this.author = {
id: data.authorExternalChannelId,
name: new Text(data?.authorName),
thumbnails: Thumbnail.fromResponse(data.authorPhoto),
badges: Parser.parse(data.authorBadges)
};
this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint);
}
}
module.exports = LiveChatMembershipItem;

View File

@@ -0,0 +1,37 @@
'use strict';
const Text = require('../../Text');
const Thumbnail = require('../../Thumbnail');
const NavigationEndpoint = require('../../NavigationEndpoint');
const Parser = require('../../..');
class LiveChatPaidMessage {
type = 'LiveChatPaidMessage';
constructor(data) {
this.message = new Text(data.message);
this.author = {
id: data.authorExternalChannelId,
name: new Text(data.authorName),
thumbnails: Thumbnail.fromResponse(data.authorPhoto),
badges: Parser.parse(data.authorBadges)
};
const badges = Parser.parse(data.authorBadges);
this.author.badges = badges;
this.author.is_moderator = badges?.some((badge) => badge.icon_type == 'MODERATOR') || null;
this.author.is_verified = badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null;
this.author.is_verified_artist = badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null;
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;
}
}
module.exports = LiveChatPaidMessage;

View File

@@ -0,0 +1,28 @@
'use strict';
const Parser = require('../../..');
const NavigationEndpoint = require('../../NavigationEndpoint');
const Thumbnail = require('../../Thumbnail');
const Text = require('../../Text');
class LiveChatPaidSticker {
type = 'LiveChatPaidSticker';
constructor(data) {
this.id = data.id;
this.author = {
id: data.authorExternalChannelId,
name: new Text(data.authorName),
thumbnails: Thumbnail.fromResponse(data.authorPhoto),
badges: Parser.parse(data.authorBadges)
};
this.sticker = Thumbnail.fromResponse(data.sticker);
this.purchase_amount = new Text(data.purchaseAmountText).toString();
this.context_menu = new NavigationEndpoint(data.contextMenuEndpoint);
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
}
}
module.exports = LiveChatPaidSticker;

View File

@@ -0,0 +1,12 @@
'use strict';
class LiveChatPlaceholderItem {
type = 'LiveChatPlaceholderItem';
constructor(data) {
this.id = data.id;
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
}
}
module.exports = LiveChatPlaceholderItem;

View File

@@ -0,0 +1,34 @@
'use strict';
const Text = require('../../Text');
const Thumbnail = require('../../Thumbnail');
const NavigationEndpoint = require('../../NavigationEndpoint');
const Parser = require('../../..');
class LiveChatTextMessage {
type = 'LiveChatTextMessage';
constructor(data) {
this.message = new Text(data.message);
this.author = {
id: data.authorExternalChannelId,
name: new Text(data.authorName),
thumbnails: Thumbnail.fromResponse(data.authorPhoto)
};
const badges = Parser.parse(data.authorBadges);
this.author.badges = badges;
this.author.is_moderator = badges?.some((badge) => badge.icon_type == 'MODERATOR') || null;
this.author.is_verified = badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null;
this.author.is_verified_artist = badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null;
this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint);
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
this.id = data.id;
}
}
module.exports = LiveChatTextMessage;

View File

@@ -0,0 +1,36 @@
'use strict';
const Text = require('../../Text');
const Thumbnail = require('../../Thumbnail');
const NavigationEndpoint = require('../../NavigationEndpoint');
const Parser = require('../../..');
class LiveChatTickerPaidMessageItem {
type = 'LiveChatTickerPaidMessageItem';
constructor(data) {
this.author = {
id: data.authorExternalChannelId,
thumbnails: Thumbnail.fromResponse(data.authorPhoto),
badges: Parser.parse(data.authorBadges)
};
const badges = Parser.parse(data.authorBadges);
this.author.badges = badges;
this.author.is_moderator = badges?.some((badge) => badge.icon_type == 'MODERATOR') || null;
this.author.is_verified = badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED') || null;
this.author.is_verified_artist = badges?.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') || null;
this.amount = new Text(data.amount);
this.duration_sec = data.durationSec;
this.full_duration_sec = data.fullDurationSec;
this.show_item = Parser.parse(data.showItemEndpoint.showLiveChatItemEndpoint.renderer, 'livechat/items');
this.show_item_endpoint = new NavigationEndpoint(data.showItemEndpoint);
this.id = data.id;
}
}
module.exports = LiveChatTickerPaidMessageItem;

View File

@@ -0,0 +1,28 @@
'use strict';
// Const Parser = require('../../..');
const Text = require('../../Text');
const Thumbnail = require('../../Thumbnail');
class LiveChatTickerSponsorItem {
type = 'LiveChatTickerSponsorItem';
constructor(data) {
this.id = data.id;
this.detail_text = new Text(data.detailText).toString();
this.author = {
id: data.authorExternalChannelId,
name: new Text(data?.authorName),
thumbnails: Thumbnail.fromResponse(data.sponsorPhoto)
};
this.duration_sec = data.durationSec;
// TODO: finish this
// Console.log(data)
}
}
module.exports = LiveChatTickerSponsorItem;

View File

@@ -0,0 +1,20 @@
'use strict';
const LiveChatTextMessage = require('./LiveChatTextMessage');
const Parser = require('../../..');
class LiveChatViewerEngagementMessage extends LiveChatTextMessage {
type = 'LiveChatViewerEngagementMessage';
constructor(data) {
super(data);
delete this.author;
delete this.menu_endpoint;
this.icon_type = data.icon.iconType;
this.action_button = Parser.parse(data.actionButton);
}
}
module.exports = LiveChatViewerEngagementMessage;

View File

@@ -0,0 +1,19 @@
'use strict';
const Text = require('../../Text');
const Thumbnail = require('../../Thumbnail');
const Parser = require('../../..');
class PollHeader {
type = 'PollHeader';
constructor(data) {
this.poll_question = new Text(data.pollQuestion);
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
this.metadata = new Text(data.metadataText);
this.live_chat_poll_type = data.liveChatPollType;
this.context_menu_button = Parser.parse(data.contextMenuButton);
}
}
module.exports = PollHeader;