Skip to content

Commit 51ff5f6

Browse files
created a new feature flag
1 parent ac7add1 commit 51ff5f6

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

src/constants/commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export const MENTION_EACH = {
5050
type: 5,
5151
require: false,
5252
},
53+
{
54+
name: "showroles",
55+
description: "want to see extra details?",
56+
type: 5,
57+
require: false,
58+
},
5359
],
5460
};
5561

src/controllers/baseHandler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export async function baseHandler(
7575
displayMessageObj: data.find((item) => item.name === "message"),
7676
channelId: message.channel_id,
7777
dev: data.find((item) => item.name === "dev") as unknown as DevFlag,
78+
showroles: data.find(
79+
(item) => item.name === "showroles"
80+
) as unknown as DevFlag,
7881
};
7982
return await mentionEachUser(transformedArgument, env, ctx);
8083
}

src/controllers/mentionEachUser.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export async function mentionEachUser(
1616
roleToBeTaggedObj: MentionEachUserOptions;
1717
displayMessageObj?: MentionEachUserOptions;
1818
channelId: number;
19+
showroles?: DevFlag;
1920
dev?: DevFlag;
2021
},
2122
env: env,
@@ -25,7 +26,7 @@ export async function mentionEachUser(
2526
const roleId = transformedArgument.roleToBeTaggedObj.value;
2627
const msgToBeSent = transformedArgument?.displayMessageObj?.value;
2728
const dev = transformedArgument?.dev?.value || false;
28-
29+
const showroles = transformedArgument?.showroles?.value || false;
2930
const usersWithMatchingRole = filterUserByRoles(
3031
getMembersInServerResponse as UserArray[],
3132
roleId
@@ -36,21 +37,37 @@ export async function mentionEachUser(
3637
message: msgToBeSent,
3738
usersWithMatchingRole,
3839
};
39-
40-
if (!dev || usersWithMatchingRole.length === 0) {
40+
if (transformedArgument.showroles?.value === true) {
41+
let responseMessage = "";
42+
if (usersWithMatchingRole.length === 0) {
43+
responseMessage = `Sorry, no user found with <@&${roleId}> role.`;
44+
} else if (usersWithMatchingRole.length === 1) {
45+
// Mention the single user by ID
46+
responseMessage = `The user with <@&${roleId}> role is ${payload.usersWithMatchingRole}.`;
47+
} else {
48+
// Mention multiple users by their IDs
49+
responseMessage = `The users with <@&${roleId}> role are ${payload.usersWithMatchingRole}.`;
50+
}
51+
return discordTextResponse(responseMessage);
52+
} else if (!dev || usersWithMatchingRole.length === 0) {
4153
const responseData = checkDisplayType({
4254
usersWithMatchingRole,
4355
msgToBeSent,
4456
roleId,
4557
});
4658
return discordTextResponse(responseData);
4759
} else {
48-
let responseMessage = "";
49-
if (usersWithMatchingRole.length === 1) {
50-
responseMessage = `The user with <@&${roleId}> role is: ${payload.usersWithMatchingRole}`;
51-
} else {
52-
responseMessage = `The users with <@&${roleId}> role are: ${payload.usersWithMatchingRole} `;
53-
}
54-
return discordTextResponse(responseMessage);
60+
// Regular dev flow to mention users
61+
ctx.waitUntil(
62+
mentionEachUserInMessage({
63+
message: payload.message,
64+
userIds: payload.usersWithMatchingRole,
65+
channelId: payload.channelId,
66+
env,
67+
})
68+
);
69+
return discordTextResponse(
70+
`Found ${usersWithMatchingRole.length} users with matched role, mentioning them shortly...`
71+
);
5572
}
5673
}

0 commit comments

Comments
 (0)