feat(parser): allow parser to find renderers by name

Now we can organize renderers in individual folders and fix the mess that `../contents/classes` is!
This commit is contained in:
LuanRT
2022-07-11 02:47:58 -03:00
parent 03f9fc5c2e
commit f924a39409
13 changed files with 31 additions and 55 deletions

View File

@@ -10,17 +10,23 @@ class Poll {
constructor(data) {
this.choices = data.choices.map((choice) => ({
text: new Text(choice.text).toString(),
select_endpoint: new NavigationEndpoint(choice.selectServiceEndpoint),
deselect_endpoint: new NavigationEndpoint(choice.deselectServiceEndpoint),
vote_ratio_if_selected: choice.voteRatioIfSelected,
select_endpoint: choice.selectServiceEndpoint ? new NavigationEndpoint(choice.selectServiceEndpoint) : null,
deselect_endpoint: choice.deselectServiceEndpoint ? new NavigationEndpoint(choice.deselectServiceEndpoint) : null,
vote_ratio_if_selected: choice?.voteRatioIfSelected || null,
vote_percentage_if_selected: new Text(choice.votePercentageIfSelected),
vote_ratio_if_not_selected: choice.voteRatioIfSelected,
vote_ratio_if_not_selected: choice?.voteRatioIfSelected || null,
vote_percentage_if_not_selected: new Text(choice.votePercentageIfSelected),
image: Thumbnail.fromResponse(choice.image)
image: choice.image ? Thumbnail.fromResponse(choice.image) : null
}));
this.total_votes = new Text(data.totalVotes);
this.poll_type = data.type;
if (poll.type)
this.poll_type = data.type;
if (data.totalVotes)
this.total_votes = new Text(data.totalVotes);
if (data.liveChatPollId)
this.live_chat_poll_id = data.liveChatPollId;
}
}

View File

@@ -4,7 +4,7 @@ const Parser = require('../..');
class AddBannerToLiveChatCommand {
constructor(data) {
return Parser.parse(data.bannerRenderer, 'livechat/items');
return Parser.parse(data.bannerRenderer);
}
}

View File

@@ -6,7 +6,7 @@ class AddChatItemAction {
type = 'AddChatItemAction';
constructor(data) {
this.item = Parser.parse(data.item, 'livechat/items');
this.item = Parser.parse(data.item);
this.client_id = data.clientId || null;
}
}

View File

@@ -6,7 +6,7 @@ class AddLiveChatTickerItemAction {
type = 'AddLiveChatTickerItemAction';
constructor(data) {
this.item = Parser.parse(data.item, 'livechat/items');
this.item = Parser.parse(data.item);
this.duration_sec = data.durationSec;
}
}

View File

@@ -7,7 +7,7 @@ class LiveChatActionPanel {
constructor(data) {
this.id = data.id;
this.contents = Parser.parse(data.contents, 'livechat/items');
this.contents = Parser.parse(data.contents);
this.target_id = data.targetId;
}
}

View File

@@ -5,7 +5,7 @@ const Parser = require('../..');
class ReplaceChatItemAction {
constructor(data) {
this.target_item_id = data.targetItemId;
this.replacement_item = Parser.parse(data.replacementItem, 'livechat/items');
this.replacement_item = Parser.parse(data.replacementItem);
}
}

View File

@@ -9,7 +9,7 @@ class ReplayChatItemAction {
this.actions = Parser.parse(data.actions?.map((action) => {
delete action.clickTrackingParams;
return action;
}), 'livechat') || [];
})) || [];
this.video_offset_time_msec = data.videoOffsetTimeMsec;
}

View File

@@ -6,7 +6,7 @@ class ShowLiveChatActionPanelAction {
type = 'ShowLiveChatActionPanelAction';
constructor(data) {
this.panel_to_show = Parser.parse(data.panelToShow, 'livechat');
this.panel_to_show = Parser.parse(data.panelToShow);
}
}

View File

@@ -6,7 +6,7 @@ class UpdateLiveChatPollAction {
type = 'UpdateLiveChatPollAction';
constructor(data) {
this.poll_to_update = Parser.parse(data.pollToUpdate, 'livechat/items');
this.poll_to_update = Parser.parse(data.pollToUpdate);
}
}

View File

@@ -1,25 +0,0 @@
'use strict';
const Parser = require('../../..');
const Text = require('../../Text');
const NavigationEndpoint = require('../../NavigationEndpoint');
class Poll {
type = 'Poll';
constructor(data) {
this.header = Parser.parse(data.header, 'livechat/items');
this.choices = data.choices.map((choice) => ({
text: new Text(choice.text).toString(),
selected: choice.selected,
vote_ratio: choice.voteRatio,
vote_percentage: new Text(choice.votePercentage).toString(),
select_endpoint: new NavigationEndpoint(choice.selectServiceEndpoint)
}));
this.live_chat_poll_id = data.liveChatPollId;
}
}
module.exports = Poll;