From 019a4c9826cb6186cc37cc1751ab01d57f022d26 Mon Sep 17 00:00:00 2001 From: supinic Date: Thu, 17 Oct 2024 20:56:09 +0200 Subject: [PATCH] `subage` improved user/channel name normalization - before: would only normalize after checking, leading to erroneous errors - after: normalizes first --- commands/subage/index.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/commands/subage/index.js b/commands/subage/index.js index 969cb222..0badef41 100644 --- a/commands/subage/index.js +++ b/commands/subage/index.js @@ -2,7 +2,7 @@ const getTargetName = (userName, context) => { if (userName === context.user.Name) { return "You are"; } - else if (userName === context.platform.Self_Name) { + else if (userName === context.platform.selfName) { return "I am"; } else { @@ -21,7 +21,9 @@ module.exports = { Whitelist_Response: null, Code: async function subAge (context, user, channel) { const platform = sb.Platform.get("twitch"); - const userID = await platform.getUserID(user ?? context.user.Name); + const userName = sb.User.normalizeUsername(user ?? context.user.Name); + + const userID = await platform.getUserID(userName); if (!userID) { return { success: false, @@ -29,11 +31,7 @@ module.exports = { }; } - let channelID; - if (channel) { - channelID = await platform.getUserID(channel); - } - else { + if (!channel) { if (context.platform.Name !== "twitch") { return { success: false, @@ -46,10 +44,10 @@ module.exports = { reply: `When in private messages, a specific channel name must be provided!` }; } - - channelID = await platform.getUserID(context.channel.Name); } + const channelName = sb.User.normalizeUsername(channel ?? context.channel.Name); + const channelID = await platform.getUserID(channelName); if (!channelID) { return { success: false, @@ -57,9 +55,6 @@ module.exports = { }; } - const channelName = sb.User.normalizeUsername(channel ?? context.channel.Name); - const userName = sb.User.normalizeUsername(user ?? context.user.Name); - const response = await sb.Got.get("TwitchGQL")({ responseType: "json", headers: {