From 29897981f09683bc44690cd52a0293820ceebd39 Mon Sep 17 00:00:00 2001 From: LuanRT Date: Sun, 1 May 2022 17:49:23 -0300 Subject: [PATCH] feat: finalize protobuf encoder for comment translations --- lib/core/Actions.js | 15 +++++++++++++-- lib/proto/index.js | 27 ++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/core/Actions.js b/lib/core/Actions.js index bdb31f8e..f2b73895 100644 --- a/lib/core/Actions.js +++ b/lib/core/Actions.js @@ -96,10 +96,21 @@ class Actions { data.commentText = args.text; break; case 'comment/perform_comment_action': + const params = { + video_id: args.video_id, + comment_id: args.comment_id + }; + const target_action = ({ - like: () => Proto.encodeCommentActionParams(5, args.comment_id, args.video_id), - dislike: () => Proto.encodeCommentActionParams(4, args.comment_id, args.video_id), + like: () => Proto.encodeCommentActionParams(5, params), + dislike: () => Proto.encodeCommentActionParams(4, params), + translate: () => { + params.text = args.text; + params.target_language = args.target_language; + return Proto.encodeCommentActionParams(22, params); + } })[args.comment_action](); + data.actions = [ target_action ]; break; default: diff --git a/lib/proto/index.js b/lib/proto/index.js index 03b07b90..55ee0b44 100644 --- a/lib/proto/index.js +++ b/lib/proto/index.js @@ -142,19 +142,36 @@ class Proto { * @param {string} type * @param {string} comment_id * @param {string} video_id + * @param {string} [text] + * @param {string} [target_language] * * @returns {string} */ - static encodeCommentActionParams(type, comment_id, video_id) { - const buf = messages.PeformCommentActionParams.encode({ - type, comment_id, video_id, + static encodeCommentActionParams(type, args = {}) { + const data = { + type, + comment_id: args.comment_id, + video_id: args.video_id, /* Maybe these can be safely removed? */ unk_num: 2, unk_num_1: 0, unk_num_2: 0, unk_num_3: "0", unk_num_4: 0, unk_num_5: 12, unk_num_6: 0, - }); - + } + + if (args.hasOwnProperty('text')) { + data.translate_comment_params = { + params: { + comment: { + text: args.text + } + }, + comment_id: args.comment_id, + target_language: args.target_language + } + } + + const buf = messages.PeformCommentActionParams.encode(data); return encodeURIComponent(Buffer.from(buf).toString('base64')); }