Skip to content

Commit 0848aaf

Browse files
authored
Merge pull request #262 from Real-Dev-Squad/develop
Sync dev to main
2 parents 33901a2 + 7b8c44d commit 0848aaf

File tree

16 files changed

+229
-29
lines changed

16 files changed

+229
-29
lines changed

config/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
STAGING_RDS_TRACKING_CHANNEL_URL,
1212
RDS_STATUS_SITE_URL,
1313
RDS_STAGING_STATUS_SITE_URL,
14+
RDS_DASHBOARD_SITE_URL,
15+
RDS_STAGING_DASHBOARD_SITE_URL,
1416
} from "../src/constants/urls";
1517
import {
1618
DISCORD_PROFILE_SERVICE_HELP_GROUP,
@@ -26,13 +28,15 @@ const config = (env: env) => {
2628
TRACKING_CHANNEL_URL: RDS_TRACKING_CHANNEL_URL,
2729
PROFILE_SERVICE_HELP_GROUP_ID: DISCORD_PROFILE_SERVICE_HELP_GROUP,
2830
RDS_STATUS_SITE_URL: RDS_STATUS_SITE_URL,
31+
DASHBOARD_SITE_URL: RDS_DASHBOARD_SITE_URL,
2932
},
3033
staging: {
3134
RDS_BASE_API_URL: RDS_BASE_STAGING_API_URL,
3235
VERIFICATION_SITE_URL: STAGING_VERIFICATION_SITE_URL,
3336
TRACKING_CHANNEL_URL: STAGING_RDS_TRACKING_CHANNEL_URL,
3437
PROFILE_SERVICE_HELP_GROUP_ID: DISCORD_PROFILE_SERVICE_STAGING_HELP_GROUP,
3538
RDS_STATUS_SITE_URL: RDS_STAGING_STATUS_SITE_URL,
39+
DASHBOARD_SITE_URL: RDS_STAGING_DASHBOARD_SITE_URL,
3640
},
3741
default: {
3842
RDS_BASE_API_URL: RDS_BASE_DEVELOPMENT_API_URL,
@@ -41,6 +45,7 @@ const config = (env: env) => {
4145
PROFILE_SERVICE_HELP_GROUP_ID:
4246
DISCORD_PROFILE_SERVICE_DEVELOPMENT_HELP_GROUP,
4347
RDS_STATUS_SITE_URL: RDS_STATUS_SITE_URL,
48+
DASHBOARD_SITE_URL: RDS_DASHBOARD_SITE_URL,
4449
},
4550
};
4651

src/constants/commands.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ export const VERIFY = {
99
"Generate a link with user specific token to link with RDS backend.",
1010
};
1111

12+
export const GROUP_INVITE = {
13+
name: "group-invite",
14+
description: "Send group invite link for the user.",
15+
options: [
16+
{
17+
name: "name",
18+
description: "User to send group invite link",
19+
type: 6,
20+
required: true,
21+
},
22+
{
23+
name: "role",
24+
description: "Role you want to invite to the user",
25+
type: 8,
26+
required: true,
27+
},
28+
],
29+
};
30+
1231
export const MENTION_EACH = {
1332
name: "mention-each",
1433
description: "mention each user with this role",

src/constants/responses.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ export const FAILED_TO_FETCH_TASKS = `Failed to fetch tasks for **{{assignee}}**
6565
export const USER_NOT_FOUND = `User Not Found`;
6666
export const USER_STATUS_NOT_FOUND = "No Status Found";
6767

68+
export const FAILED_TO_FETCH_DISCORD_GUILD_ROLE =
69+
"Failed to fetch discord guild role";
70+
6871
export const OVERDUE_DEFAULT_MESSAGE = "You have overdue tasks.";
6972
export const OVERDUE_CUSTOM_MESSAGE =
7073
"Please be aware that you currently have tasks that are overdue or due within the next {{days}} day. If you require additional time to complete these tasks, kindly submit an extension request.";

src/constants/urls.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ export const DEVELOPMENT_RDS_TRACKING_CHANNEL_URL =
2222
export const RDS_STATUS_SITE_URL = "https://status.realdevsquad.com";
2323
export const RDS_STAGING_STATUS_SITE_URL =
2424
"https://staging-status.realdevsquad.com";
25+
26+
export const RDS_DASHBOARD_SITE_URL = "https://dashboard.realdevsquad.com";
27+
export const RDS_STAGING_DASHBOARD_SITE_URL =
28+
"https://staging-dashboard.realdevsquad.com";

src/controllers/baseHandler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
OOO,
2929
USER,
3030
REMOVE,
31+
GROUP_INVITE,
3132
} from "../constants/commands";
3233
import { updateNickName } from "../utils/updateNickname";
3334
import { discordEphemeralResponse } from "../utils/discordEphemeralResponse";
@@ -42,6 +43,7 @@ import {
4243
} from "../constants/responses";
4344
import { DevFlag } from "../typeDefinitions/filterUsersByRole";
4445
import { kickEachUser } from "./kickEachUser";
46+
import { groupInvite } from "./groupInvite";
4547

4648
export async function baseHandler(
4749
message: discordMessageRequest,
@@ -159,6 +161,12 @@ export async function baseHandler(
159161
) as unknown as DevFlag;
160162
return await userCommand(data[0].value, env, dev);
161163
}
164+
165+
case getCommandName(GROUP_INVITE): {
166+
const data = message.data?.options as Array<messageRequestDataOptions>;
167+
168+
return await groupInvite(data[0].value, data[1].value, env);
169+
}
162170
default: {
163171
return commandNotFound();
164172
}

src/controllers/groupInvite.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import config from "../../config/config";
2+
import { env } from "../typeDefinitions/default.types";
3+
import { discordTextResponse } from "../utils/discordResponse";
4+
import * as DiscordGroups from "../utils/fetchDiscordGroupById";
5+
import JSONResponse from "../utils/JsonResponse";
6+
7+
export async function groupInvite(
8+
userId: string,
9+
roleId: string,
10+
env: env
11+
): Promise<JSONResponse> {
12+
const group = await DiscordGroups.fetchDiscordGroupById(roleId, env);
13+
14+
if (!group.name.startsWith("group-")) {
15+
return discordTextResponse(`<@&${roleId}> is not a valid group.`);
16+
}
17+
18+
const groupName = group.name.replace(/^group-/, "").replace(/-/g, " ");
19+
const encodedGroupName = encodeURIComponent(groupName);
20+
21+
return discordTextResponse(
22+
`<@${userId}> join the group <@&${roleId}> via the link below:\n ${
23+
config(env).DASHBOARD_SITE_URL
24+
}/groups/?dev=true&name=${encodedGroupName}`
25+
);
26+
}

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ router.get("/ankush", async (request, env, ctx: ExecutionContext) => {
6666
ctx.waitUntil(send(env));
6767

6868
const url = config(env).TRACKING_CHANNEL_URL;
69-
70-
return new JSONResponse(`CURRENT_ENVIRONMENT: ${env.CURRENT_ENVIRONMENT}, tracking url - ${url}`, { status: 200 });
71-
});
7269

70+
return new JSONResponse(
71+
`CURRENT_ENVIRONMENT: ${env.CURRENT_ENVIRONMENT}, tracking url - ${url}`,
72+
{ status: 200 }
73+
);
74+
});
7375

7476
router.post("/", async (request, env, ctx: ExecutionContext) => {
7577
const message: discordMessageRequest = await request.json();

src/register.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
OOO,
1010
USER,
1111
REMOVE,
12+
GROUP_INVITE,
1213
} from "./constants/commands";
1314
import { config } from "dotenv";
1415
import { DISCORD_BASE_URL } from "./constants/urls";
@@ -39,6 +40,7 @@ async function registerGuildCommands(
3940
NOTIFY_OVERDUE,
4041
NOTIFY_ONBOARDING,
4142
REMOVE,
43+
GROUP_INVITE,
4244
];
4345

4446
try {

src/typeDefinitions/default.types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface environment {
77
}
88

99
export interface variables {
10+
DASHBOARD_SITE_URL: string;
1011
RDS_BASE_API_URL: string;
1112
VERIFICATION_SITE_URL: string;
1213
TRACKING_CHANNEL_URL: string;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type DiscordGuildRole = {
2+
name: string;
3+
id: string;
4+
};

0 commit comments

Comments
 (0)