Skip to content

Commit

Permalink
created a new feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
RishiChaubey31 committed Oct 26, 2024
1 parent ac7add1 commit 51ff5f6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/constants/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export const MENTION_EACH = {
type: 5,
require: false,
},
{
name: "showroles",
description: "want to see extra details?",
type: 5,
require: false,
},
],
};

Expand Down
3 changes: 3 additions & 0 deletions src/controllers/baseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ 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"
) as unknown as DevFlag,
};
return await mentionEachUser(transformedArgument, env, ctx);
}
Expand Down
37 changes: 27 additions & 10 deletions src/controllers/mentionEachUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function mentionEachUser(
roleToBeTaggedObj: MentionEachUserOptions;
displayMessageObj?: MentionEachUserOptions;
channelId: number;
showroles?: DevFlag;
dev?: DevFlag;
},
env: env,
Expand All @@ -25,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 usersWithMatchingRole = filterUserByRoles(
getMembersInServerResponse as UserArray[],
roleId
Expand All @@ -36,21 +37,37 @@ export async function mentionEachUser(
message: msgToBeSent,
usersWithMatchingRole,
};

if (!dev || usersWithMatchingRole.length === 0) {
if (transformedArgument.showroles?.value === true) {
let responseMessage = "";
if (usersWithMatchingRole.length === 0) {
responseMessage = `Sorry, no user found with <@&${roleId}> role.`;
} else if (usersWithMatchingRole.length === 1) {
// Mention the single user by ID
responseMessage = `The user with <@&${roleId}> role is ${payload.usersWithMatchingRole}.`;
} else {
// Mention multiple users by their IDs
responseMessage = `The users with <@&${roleId}> role are ${payload.usersWithMatchingRole}.`;
}
return discordTextResponse(responseMessage);
} else if (!dev || usersWithMatchingRole.length === 0) {
const responseData = checkDisplayType({
usersWithMatchingRole,
msgToBeSent,
roleId,
});
return discordTextResponse(responseData);
} else {
let responseMessage = "";
if (usersWithMatchingRole.length === 1) {
responseMessage = `The user with <@&${roleId}> role is: ${payload.usersWithMatchingRole}`;
} else {
responseMessage = `The users with <@&${roleId}> role are: ${payload.usersWithMatchingRole} `;
}
return discordTextResponse(responseMessage);
// Regular dev flow to mention users
ctx.waitUntil(
mentionEachUserInMessage({
message: payload.message,
userIds: payload.usersWithMatchingRole,
channelId: payload.channelId,
env,
})
);
return discordTextResponse(
`Found ${usersWithMatchingRole.length} users with matched role, mentioning them shortly...`
);
}
}

0 comments on commit 51ff5f6

Please sign in to comment.