@@ -16,6 +16,7 @@ export async function mentionEachUser(
16
16
roleToBeTaggedObj : MentionEachUserOptions ;
17
17
displayMessageObj ?: MentionEachUserOptions ;
18
18
channelId : number ;
19
+ showroles ?: DevFlag ;
19
20
dev ?: DevFlag ;
20
21
} ,
21
22
env : env ,
@@ -25,7 +26,7 @@ export async function mentionEachUser(
25
26
const roleId = transformedArgument . roleToBeTaggedObj . value ;
26
27
const msgToBeSent = transformedArgument ?. displayMessageObj ?. value ;
27
28
const dev = transformedArgument ?. dev ?. value || false ;
28
-
29
+ const showroles = transformedArgument ?. showroles ?. value || false ;
29
30
const usersWithMatchingRole = filterUserByRoles (
30
31
getMembersInServerResponse as UserArray [ ] ,
31
32
roleId
@@ -36,21 +37,37 @@ export async function mentionEachUser(
36
37
message : msgToBeSent ,
37
38
usersWithMatchingRole,
38
39
} ;
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 ) {
41
53
const responseData = checkDisplayType ( {
42
54
usersWithMatchingRole,
43
55
msgToBeSent,
44
56
roleId,
45
57
} ) ;
46
58
return discordTextResponse ( responseData ) ;
47
59
} 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
+ ) ;
55
72
}
56
73
}
0 commit comments