mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-19 04:21:35 +00:00
feat(LiveChat): add support for moderation & more (#202)
* Live Chat - Implement moderation * Live Chat - Implement class ItemMenu * fix moderation method Co-authored-by: LuanRT <luan.lrt4@gmail.com>
This commit is contained in:
@@ -230,12 +230,6 @@ class NavigationEndpoint extends YTNode {
|
||||
params: data.sendLiveChatVoteEndpoint.params
|
||||
};
|
||||
}
|
||||
|
||||
if (data?.liveChatItemContextMenuEndpoint) {
|
||||
this.live_chat_item_context_menu = {
|
||||
params: data.liveChatItemContextMenuEndpoint.params
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,6 +243,8 @@ class NavigationEndpoint extends YTNode {
|
||||
return '/player';
|
||||
case 'watchPlaylistEndpoint':
|
||||
return '/next';
|
||||
case 'liveChatItemContextMenuEndpoint':
|
||||
return 'live_chat/get_item_context_menu';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,6 +293,15 @@ class NavigationEndpoint extends YTNode {
|
||||
const response = await actions.engage(this.metadata.api_url, { video_id: this.like.target.video_id, params: this.like.params });
|
||||
return response;
|
||||
}
|
||||
|
||||
if (this.live_chat_item_context_menu) {
|
||||
if (!this.metadata.api_url)
|
||||
throw new Error('Live Chat Item Context Menu endpoint requires an api_url, but was not parsed from the response.');
|
||||
const response = await actions.livechat(this.metadata.api_url, {
|
||||
params: this.live_chat_item_context_menu.params
|
||||
});
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
async call(actions: Actions, client: string | undefined, parse: true) : Promise<ParsedResponse | undefined>;
|
||||
@@ -307,7 +312,7 @@ class NavigationEndpoint extends YTNode {
|
||||
if (parse && result)
|
||||
return Parser.parseResponse(result.data);
|
||||
|
||||
return this.#call(actions, client);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import Text from '../../misc/Text';
|
||||
import Parser from '../../../index';
|
||||
import { YTNode } from '../../../helpers';
|
||||
import { ObservedArray, YTNode } from '../../../helpers';
|
||||
import NavigationEndpoint from '../../NavigationEndpoint';
|
||||
import Button from '../../Button';
|
||||
|
||||
class LiveChatAutoModMessage extends YTNode {
|
||||
static type = 'LiveChatAutoModMessage';
|
||||
@@ -8,12 +10,16 @@ class LiveChatAutoModMessage extends YTNode {
|
||||
auto_moderated_item;
|
||||
header_text: Text;
|
||||
|
||||
menu_endpoint?: NavigationEndpoint;
|
||||
moderation_buttons: ObservedArray<Button>;
|
||||
timestamp: number;
|
||||
id: string;
|
||||
|
||||
constructor(data: any) {
|
||||
super();
|
||||
|
||||
this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint);
|
||||
this.moderation_buttons = Parser.parseArray<Button>(data.moderationButtons, [ Button ]);
|
||||
this.auto_moderated_item = Parser.parse(data.autoModeratedItem);
|
||||
this.header_text = new Text(data.headerText);
|
||||
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
|
||||
|
||||
@@ -23,6 +23,7 @@ class LiveChatPaidSticker extends YTNode {
|
||||
sticker: Thumbnail[];
|
||||
purchase_amount: string;
|
||||
context_menu: NavigationEndpoint;
|
||||
menu_endpoint?: NavigationEndpoint;
|
||||
timestamp: number;
|
||||
|
||||
constructor(data: any) {
|
||||
@@ -42,7 +43,8 @@ class LiveChatPaidSticker extends YTNode {
|
||||
this.author_name_text_color = data.authorNameTextColor;
|
||||
this.sticker = Thumbnail.fromResponse(data.sticker);
|
||||
this.purchase_amount = new Text(data.purchaseAmountText).toString();
|
||||
this.context_menu = new NavigationEndpoint(data.contextMenuEndpoint);
|
||||
this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint);
|
||||
this.context_menu = this.menu_endpoint;
|
||||
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import MetadataBadge from '../../MetadataBadge';
|
||||
import LiveChatAuthorBadge from '../../LiveChatAuthorBadge';
|
||||
import Parser from '../../../index';
|
||||
|
||||
import { YTNode } from '../../../helpers';
|
||||
import { ObservedArray, YTNode } from '../../../helpers';
|
||||
import Button from '../../Button';
|
||||
|
||||
class LiveChatTextMessage extends YTNode {
|
||||
static type = 'LiveChatTextMessage';
|
||||
@@ -22,6 +23,7 @@ class LiveChatTextMessage extends YTNode {
|
||||
};
|
||||
|
||||
menu_endpoint?: NavigationEndpoint;
|
||||
inline_action_buttons: ObservedArray<Button>;
|
||||
timestamp: number;
|
||||
id: string;
|
||||
|
||||
@@ -47,6 +49,7 @@ class LiveChatTextMessage extends YTNode {
|
||||
this.author.is_verified_artist = badges ? badges.some((badge) => badge.style == 'BADGE_STYLE_TYPE_VERIFIED_ARTIST') : null;
|
||||
|
||||
this.menu_endpoint = new NavigationEndpoint(data.contextMenuEndpoint);
|
||||
this.inline_action_buttons = Parser.parseArray<Button>(data.inlineActionButtons, [ Button ]);
|
||||
this.timestamp = Math.floor(parseInt(data.timestampUsec) / 1000);
|
||||
this.id = data.id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user