diff --git a/src/constants/commands.ts b/src/constants/commands.ts index f98b138..47a83d6 100644 --- a/src/constants/commands.ts +++ b/src/constants/commands.ts @@ -44,6 +44,12 @@ export const MENTION_EACH = { type: 3, require: false, }, + { + name: "dev", + description: "want to tag them individually?", + type: 5, + require: false, + }, ], }; diff --git a/src/controllers/mentionEachUser.ts b/src/controllers/mentionEachUser.ts index c02812b..ebe6360 100644 --- a/src/controllers/mentionEachUser.ts +++ b/src/controllers/mentionEachUser.ts @@ -6,6 +6,7 @@ import { env } from "../typeDefinitions/default.types"; import { UserArray, MentionEachUserOptions, + DevFlag, } from "../typeDefinitions/filterUsersByRole"; import { mentionEachUserInMessage } from "../utils/guildRole"; import { checkDisplayType } from "../utils/checkDisplayType"; @@ -15,6 +16,7 @@ export async function mentionEachUser( roleToBeTaggedObj: MentionEachUserOptions; displayMessageObj?: MentionEachUserOptions; channelId: number; + dev?: DevFlag; }, env: env, ctx: ExecutionContext @@ -22,20 +24,19 @@ export async function mentionEachUser( const getMembersInServerResponse = await getMembersInServer(env); const roleId = transformedArgument.roleToBeTaggedObj.value; const msgToBeSent = transformedArgument?.displayMessageObj?.value; - + const dev = transformedArgument?.dev?.value || false; + // optional chaining here only because display message obj is optional argument const usersWithMatchingRole = filterUserByRoles( getMembersInServerResponse as UserArray[], roleId ); - const payload = { channelId: transformedArgument.channelId, roleId: roleId, message: msgToBeSent, usersWithMatchingRole, }; - - if (usersWithMatchingRole.length === 0) { + if (!dev || usersWithMatchingRole.length === 0) { const responseData = checkDisplayType({ usersWithMatchingRole, msgToBeSent, diff --git a/src/typeDefinitions/filterUsersByRole.d.ts b/src/typeDefinitions/filterUsersByRole.d.ts index 4d42fd2..a54fd74 100644 --- a/src/typeDefinitions/filterUsersByRole.d.ts +++ b/src/typeDefinitions/filterUsersByRole.d.ts @@ -10,3 +10,8 @@ export type MentionEachUserOptions = { type: number; value: string; }; +export type DevFlag = { + name: string; + type: number; + value: boolean; +}; diff --git a/tests/unit/handlers/mentionEachUser.test.ts b/tests/unit/handlers/mentionEachUser.test.ts index 5224f90..dc23bc2 100644 --- a/tests/unit/handlers/mentionEachUser.test.ts +++ b/tests/unit/handlers/mentionEachUser.test.ts @@ -19,7 +19,7 @@ describe("Test mention each function", () => { expect(response).toBeInstanceOf(Promise); }); - it("should run without displayMessageObj argument", async () => { + it("should run without displayMessageObj argument in dev mode", async () => { const env = { BOT_PUBLIC_KEY: "xyz", DISCORD_GUILD_ID: "123", @@ -28,6 +28,11 @@ describe("Test mention each function", () => { const response = mentionEachUser( { ...onlyRoleToBeTagged, + dev: { + name: "dev", + type: 4, + value: true, + }, }, env, ctx