Skip to content

Commit

Permalink
Revert "remove feature flag (#275)" (#281)
Browse files Browse the repository at this point in the history
This reverts commit b54d9c3.
  • Loading branch information
vinit717 authored Oct 20, 2024
1 parent b54d9c3 commit 28636d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/constants/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export const MENTION_EACH = {
type: 3,
require: false,
},
{
name: "dev",
description: "want to tag them individually?",
type: 5,
require: false,
},
],
};

Expand Down
9 changes: 5 additions & 4 deletions src/controllers/mentionEachUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -15,27 +16,27 @@ export async function mentionEachUser(
roleToBeTaggedObj: MentionEachUserOptions;
displayMessageObj?: MentionEachUserOptions;
channelId: number;
dev?: DevFlag;
},
env: env,
ctx: ExecutionContext
) {
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,
Expand Down
5 changes: 5 additions & 0 deletions src/typeDefinitions/filterUsersByRole.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ export type MentionEachUserOptions = {
type: number;
value: string;
};
export type DevFlag = {
name: string;
type: number;
value: boolean;
};
7 changes: 6 additions & 1 deletion tests/unit/handlers/mentionEachUser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -28,6 +28,11 @@ describe("Test mention each function", () => {
const response = mentionEachUser(
{
...onlyRoleToBeTagged,
dev: {
name: "dev",
type: 4,
value: true,
},
},
env,
ctx
Expand Down

0 comments on commit 28636d7

Please sign in to comment.