-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathassigneeSelectInteraction.ts
More file actions
46 lines (39 loc) · 1.24 KB
/
assigneeSelectInteraction.ts
File metadata and controls
46 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { ItemService } from "@src/items/services";
import { UserSelectMenuInteraction } from "discord.js";
import { UserService } from "@src/items/services/UserService";
export async function assigneeSelectInteraction(
interaction: UserSelectMenuInteraction,
): Promise<void> {
const match = interaction.customId.match(/^issue:assignee:select:(.+)$/);
if (!match) {
throw new Error("Invalid customId format");
}
const githubIssueId = match[1];
const selectedUserId = interaction.values[0];
const userResult = await UserService.findUserByDiscordID(selectedUserId);
if (userResult.err) {
await interaction.reply({
content: "❌ You don’t appear to be linked to a GitHub account.",
ephemeral: true,
});
return;
}
// Find the GitHub ID using the selected Discord ID
const githubId = userResult.val.githubId;
const result = await ItemService.updateAssignee({
itemId: githubIssueId,
assigneeId: githubId,
});
if (result.err) {
await interaction.reply({
content:
"❌ Failed to update assignee. Cannot assign to Draft Issues (yet).",
ephemeral: true,
});
return;
}
await interaction.update({
content: `**Assigned**: <@${selectedUserId}>`,
components: [],
});
}