Skip to content

Commit

Permalink
changed the feature flag name and removed nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
RishiChaubey31 committed Oct 27, 2024
1 parent 7148548 commit faba991
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/constants/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const MENTION_EACH = {
require: false,
},
{
name: "showroles",
name: "devtitle",
description: "want to see extra details?",
type: 5,
require: false,
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/baseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export async function baseHandler(
displayMessageObj: data.find((item) => item.name === "message"),
channelId: message.channel_id,
dev: data.find((item) => item.name === "dev") as unknown as DevFlag,
showroles: data.find(
(item) => item.name === "showroles"
devtitle: data.find(
(item) => item.name === "devtitle"
) as unknown as DevFlag,
};
return await mentionEachUser(transformedArgument, env, ctx);
Expand Down
11 changes: 7 additions & 4 deletions src/controllers/mentionEachUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function mentionEachUser(
roleToBeTaggedObj: MentionEachUserOptions;
displayMessageObj?: MentionEachUserOptions;
channelId: number;
showroles?: DevFlag;
devtitle?: DevFlag;
dev?: DevFlag;
},
env: env,
Expand All @@ -26,7 +26,7 @@ export async function mentionEachUser(
const roleId = transformedArgument.roleToBeTaggedObj.value;
const msgToBeSent = transformedArgument?.displayMessageObj?.value;
const dev = transformedArgument?.dev?.value || false;
const showroles = transformedArgument?.showroles?.value || false;
const devtitle = transformedArgument?.devtitle?.value || false;
// optional chaining here only because display message obj is optional argument
const usersWithMatchingRole = filterUserByRoles(
getMembersInServerResponse as UserArray[],
Expand All @@ -38,7 +38,8 @@ export async function mentionEachUser(
message: msgToBeSent,
usersWithMatchingRole,
};
if (transformedArgument.showroles?.value === true) {

if (transformedArgument.devtitle?.value === true) {
let responseMessage = "";
if (usersWithMatchingRole.length === 0) {
responseMessage = `Sorry, no user found with <@&${roleId}> role.`;
Expand All @@ -50,7 +51,9 @@ export async function mentionEachUser(
responseMessage = `The users with <@&${roleId}> role are ${payload.usersWithMatchingRole}.`;
}
return discordTextResponse(responseMessage);
} else if (!dev || usersWithMatchingRole.length === 0) {
}

if (!dev || usersWithMatchingRole.length === 0) {
const responseData = checkDisplayType({
usersWithMatchingRole,
msgToBeSent,
Expand Down

0 comments on commit faba991

Please sign in to comment.