Skip to content

Commit

Permalink
subage improved user/channel name normalization
Browse files Browse the repository at this point in the history
- before: would only normalize after checking, leading to erroneous errors
- after: normalizes first
  • Loading branch information
Supinic committed Oct 17, 2024
1 parent 4d41fb1 commit 019a4c9
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions commands/subage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,19 +21,17 @@ 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,
reply: `Provided user does not exist on Twitch!`
};
}

let channelID;
if (channel) {
channelID = await platform.getUserID(channel);
}
else {
if (!channel) {
if (context.platform.Name !== "twitch") {
return {
success: false,
Expand All @@ -46,20 +44,17 @@ 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,
reply: `Provided channel does not exist on Twitch!`
};
}

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: {
Expand Down

0 comments on commit 019a4c9

Please sign in to comment.