Skip to content

Commit 521957a

Browse files
authored
Merge pull request RealDevSquad#158 from Real-Dev-Squad/develop
Dev to main sync
2 parents eb9e75d + f2b1f76 commit 521957a

File tree

5 files changed

+57
-38
lines changed

5 files changed

+57
-38
lines changed

src/constants/commands.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,39 +80,46 @@ export const USER = {
8080
],
8181
};
8282

83-
export const NOTIFY = {
84-
name: "notify",
85-
description: "notify the user",
83+
export const NOTIFY_OVERDUE = {
84+
name: "notify-overdue",
85+
description: "Notify the user about overdue tasks.",
8686
options: [
8787
{
88-
name: "type",
89-
description: "type of notification",
88+
name: "notify-overdue",
89+
description: "Select the number of days",
9090
type: 3,
9191
required: true,
9292
choices: [
9393
{
94-
name: "OVERDUE",
95-
value: "OVERDUE",
94+
name: "Already Overdue",
95+
value: "0",
9696
},
9797
{
98-
name: "ONBOARDING",
99-
value: "ONBOARDING",
98+
name: "In 1 Day",
99+
value: "1",
100+
},
101+
{
102+
name: "In 2 Days",
103+
value: "2",
100104
},
101105
],
102106
},
107+
],
108+
};
109+
110+
export const NOTIFY_ONBOARDING = {
111+
name: "notify-onboarding",
112+
description: "Notify the user about onboarding information.",
113+
options: [
103114
{
104-
name: "sub-type",
105-
description: "sub-type of notification",
115+
name: "notify-onboarding",
116+
description: "Select the number of days",
106117
type: 3,
107-
required: false,
118+
required: true,
108119
choices: [
109120
{
110-
name: "In 1 Day",
111-
value: "1",
112-
},
113-
{
114-
name: "In 2 Day",
115-
value: "2",
121+
name: "All Onboarding Users",
122+
value: "0",
116123
},
117124
{
118125
name: "> 7 Days",

src/controllers/baseHandler.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
MENTION_EACH,
2424
VERIFY,
2525
TASK,
26-
NOTIFY,
26+
NOTIFY_OVERDUE,
27+
NOTIFY_ONBOARDING,
2728
OOO,
2829
USER,
2930
} from "../constants/commands";
@@ -122,9 +123,13 @@ export async function baseHandler(
122123
const data = message.data?.options as Array<messageRequestDataOptions>;
123124
return await taskCommand(data[0].value);
124125
}
125-
case getCommandName(NOTIFY): {
126+
case getCommandName(NOTIFY_OVERDUE): {
126127
const data = message.data?.options as Array<messageRequestDataOptions>;
127-
return await notifyCommand(data);
128+
return await notifyCommand(data, true, false);
129+
}
130+
case getCommandName(NOTIFY_ONBOARDING): {
131+
const data = message.data?.options as Array<messageRequestDataOptions>;
132+
return await notifyCommand(data, false, true);
128133
}
129134
case getCommandName(OOO): {
130135
const data = message.data?.options as Array<messageRequestDataOptions>;

src/controllers/notifyCommand.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ import { fetchRdsData } from "../utils/fetchRdsData";
1313
import { createTaggableDiscordIds } from "../utils/createTaggableDiscordIds";
1414
import { extractDiscordIds } from "../utils/extractDiscordIds";
1515

16-
export async function notifyCommand(data: Array<{ value: string }>) {
17-
const typeValue = data[0].value;
18-
const daysValue = data[1]?.value;
16+
export async function notifyCommand(
17+
data: Array<{ value: string }>,
18+
overdue?: boolean,
19+
onboarding?: boolean
20+
) {
21+
const daysValue = data[0]?.value;
1922

2023
try {
21-
if (typeValue === "OVERDUE") {
24+
if (overdue) {
2225
const options = {
23-
isOverdue: true,
2426
days: daysValue,
27+
isOverdue: true,
2528
};
2629
const usersResponse = (await fetchRdsData(
2730
options
@@ -30,25 +33,25 @@ export async function notifyCommand(data: Array<{ value: string }>) {
3033
const formattedIds = createTaggableDiscordIds(discordIDs);
3134

3235
const message = `**Message:** ${
33-
daysValue
36+
Number(daysValue) > 0
3437
? OVERDUE_CUSTOM_MESSAGE.replace("{{days}}", daysValue)
3538
: OVERDUE_DEFAULT_MESSAGE
3639
}`;
3740

3841
const users = `**Developers:** ${formattedIds.join(", ")}`;
3942
const responseMessage = `${message}\n${users}`;
4043
return discordTextResponse(responseMessage);
41-
} else if (typeValue === "ONBOARDING") {
44+
} else if (onboarding) {
4245
const options = {
43-
isOnboarding: true,
4446
days: daysValue,
47+
isOnboarding: true,
4548
};
4649
const users = (await fetchRdsData(options)) as UserResponseType;
4750
const discordIDs = extractDiscordIds(users);
4851
const formattedIds = createTaggableDiscordIds(discordIDs);
4952

5053
const message = `**Message:** ${
51-
daysValue
54+
Number(daysValue) > 0
5255
? ONBOARDING_CUSTOM_MESSAGE.replace("{{days}}", daysValue)
5356
: ONBOARDING_DEFAULT_MESSAGE
5457
}`;

src/register.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
VERIFY,
55
LISTENING,
66
TASK,
7-
NOTIFY,
7+
NOTIFY_OVERDUE,
8+
NOTIFY_ONBOARDING,
89
OOO,
910
USER,
1011
} from "./constants/commands";
@@ -34,7 +35,8 @@ async function registerGuildCommands(
3435
TASK,
3536
OOO,
3637
USER,
37-
NOTIFY,
38+
NOTIFY_OVERDUE,
39+
NOTIFY_ONBOARDING,
3840
];
3941

4042
try {

src/utils/fetchRdsData.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ async function fetchRdsData(options = {}) {
2626
let url = RDS_BASE_API_URL;
2727

2828
if (isOnboarding) {
29-
url += days
30-
? `/users/search?state=ONBOARDING&time=${days}d`
31-
: `/users/search?state=ONBOARDING`;
29+
url +=
30+
Number(days) > 0
31+
? `/users/search?state=ONBOARDING&time=${days}d`
32+
: `/users/search?state=ONBOARDING`;
3233
} else if (isOverdue) {
33-
url += days
34-
? `/users?query=filterBy:overdue_tasks+days:${days}`
35-
: `/users?query=filterBy:overdue_tasks`;
34+
url +=
35+
Number(days) > 0
36+
? `/users?query=filterBy:overdue_tasks+days:${days}`
37+
: `/users?query=filterBy:overdue_tasks`;
3638
}
3739
const response = await fetch(url);
3840

0 commit comments

Comments
 (0)