From 2f56c15ecc151ec8d0d764b7c3a4dcb10ec8f6e1 Mon Sep 17 00:00:00 2001 From: Akazawa Daisuke <40195276+akkadaska@users.noreply.github.com> Date: Sun, 2 Oct 2022 14:00:24 +0900 Subject: [PATCH] feat(LiveChat): add support for moderation & more (#202) * Live Chat - Implement moderation * Live Chat - Implement class ItemMenu * fix moderation method Co-authored-by: LuanRT --- package.json | 3 +- src/core/Actions.ts | 3 +- src/parser/classes/NavigationEndpoint.ts | 19 ++++-- .../livechat/items/LiveChatAutoModMessage.ts | 8 ++- .../livechat/items/LiveChatPaidSticker.ts | 4 +- .../livechat/items/LiveChatTextMessage.ts | 5 +- src/parser/index.ts | 9 +++ src/parser/youtube/ItemMenu.ts | 65 +++++++++++++++++++ src/parser/youtube/LiveChat.ts | 35 +++++++++- 9 files changed, 137 insertions(+), 14 deletions(-) create mode 100644 src/parser/youtube/ItemMenu.ts diff --git a/package.json b/package.json index f8e0e1b0..931a9a88 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "contributors": [ "Wykerd (https://github.com/wykerd/)", "MasterOfBob777 (https://github.com/MasterOfBob777)", - "patrickkfkan (https://github.com/patrickkfkan)" + "patrickkfkan (https://github.com/patrickkfkan)", + "akkadaska (https://github.com/akkadaska)" ], "directories": { "test": "./test", diff --git a/src/core/Actions.ts b/src/core/Actions.ts index 025ecb52..11fcd226 100644 --- a/src/core/Actions.ts +++ b/src/core/Actions.ts @@ -455,8 +455,7 @@ class Actions { }; break; case 'live_chat/get_item_context_menu': - // Note: this is currently broken due to a recent refactor - // TODO: this should be implemented + data.params = args.params; break; case 'live_chat/moderate': data.params = args.params; diff --git a/src/parser/classes/NavigationEndpoint.ts b/src/parser/classes/NavigationEndpoint.ts index 0fbea7c5..a9635de7 100644 --- a/src/parser/classes/NavigationEndpoint.ts +++ b/src/parser/classes/NavigationEndpoint.ts @@ -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; @@ -307,7 +312,7 @@ class NavigationEndpoint extends YTNode { if (parse && result) return Parser.parseResponse(result.data); - return this.#call(actions, client); + return result; } } diff --git a/src/parser/classes/livechat/items/LiveChatAutoModMessage.ts b/src/parser/classes/livechat/items/LiveChatAutoModMessage.ts index 8518cff3..0861b891 100644 --- a/src/parser/classes/livechat/items/LiveChatAutoModMessage.ts +++ b/src/parser/classes/livechat/items/LiveChatAutoModMessage.ts @@ -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