From 138145fa0571b04b1923d794bd4c7fd35122b692 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 14 Apr 2020 03:51:21 +1200 Subject: [PATCH] Assistant understands age restricted profiles --- src/lib/structures/Assistant.js | 3 +++ src/lib/structures/AssistantSwitcher.js | 2 +- src/site/assistant_api/user.js | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/structures/Assistant.js b/src/lib/structures/Assistant.js index 202c4c0..7117245 100644 --- a/src/lib/structures/Assistant.js +++ b/src/lib/structures/Assistant.js @@ -35,6 +35,9 @@ class Assistant { if (root.identifier === "NOT_FOUND") { this.lastRequestStatus = constants.symbols.assistant_statuses.OK reject(constants.symbols.NOT_FOUND) + } else if (root.identifier === "AGE_RESTRICTED") { + this.lastRequestStatus = constants.symbols.assistant_statuses.OK + reject(constants.symbols.extractor_results.AGE_RESTRICTED) } else if (root.identifier === "NOT_AUTHENTICATED") { this.lastRequestStatus = constants.symbols.assistant_statuses.NOT_AUTHENTICATED reject(constants.symbols.assistant_statuses.NOT_AUTHENTICATED) diff --git a/src/lib/structures/AssistantSwitcher.js b/src/lib/structures/AssistantSwitcher.js index e69a41e..6ac3872 100644 --- a/src/lib/structures/AssistantSwitcher.js +++ b/src/lib/structures/AssistantSwitcher.js @@ -25,7 +25,7 @@ class AssistantSwitcher { const user = await assistant.requestUser(username) return resolve(user) } catch (e) { - if (e === constants.symbols.NOT_FOUND) { + if (e === constants.symbols.NOT_FOUND || e === constants.symbols.extractor_results.AGE_RESTRICTED) { const rejection = Promise.reject(e) rejection.catch(() => {}) // otherwise we get a warning that the rejection was handled asynchronously collectors.userRequestCache.set(`user/${username}`, false, rejection) diff --git a/src/site/assistant_api/user.js b/src/site/assistant_api/user.js index 0268e21..f6fb393 100644 --- a/src/site/assistant_api/user.js +++ b/src/site/assistant_api/user.js @@ -96,6 +96,14 @@ module.exports = [ message: "User not found.", identifier: "NOT_FOUND" }) + } else if (error === constants.symbols.extractor_results.AGE_RESTRICTED) { + return reply(403, { + status: "fail", + version: "1.0", + generatedAt: Date.now(), + message: "Profile is age restricted.", + identifier: "AGE_RESTRICTED" + }) } else { throw error }