-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectHandlers.js
More file actions
69 lines (60 loc) · 2.96 KB
/
Copy pathselectHandlers.js
File metadata and controls
69 lines (60 loc) · 2.96 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { UserSelectMenuBuilder, ActionRowBuilder } = require('discord.js');
const taskManager = require('./taskManager');
const { updateListMessage } = require('./commands');
const { buildTaskDetailEmbed } = require('./embedBuilder');
const handlers = {
taskSelect: async (interaction, [action]) => {
// Value format: "action:taskId"
const value = interaction.values[0];
const [act, taskId] = value.split(':');
const guildId = interaction.guild.id;
if (act === 'complete') {
const task = taskManager.getTask(guildId, taskId);
if (!task) return interaction.reply({ content: '❌ Task not found.', ephemeral: true });
taskManager.updateTask(guildId, taskId, { done: true, completedAt: new Date().toISOString() });
await updateListMessage(interaction.guild);
await interaction.update({ content: `✅ **"${task.title}"** marked as complete!`, components: [], embeds: [] });
}
if (act === 'delete') {
const task = taskManager.getTask(guildId, taskId);
if (!task) return interaction.reply({ content: '❌ Task not found.', ephemeral: true });
taskManager.deleteTask(guildId, taskId);
await updateListMessage(interaction.guild);
await interaction.update({ content: `🗑️ **"${task.title}"** deleted.`, components: [], embeds: [] });
}
if (act === 'edit') {
const buttonHandlers = require('./buttonHandlers');
await buttonHandlers.editTask(interaction, ['detail', taskId]);
}
if (act === 'view') {
const task = taskManager.getTask(guildId, taskId);
if (!task) return interaction.reply({ content: '❌ Task not found.', ephemeral: true });
await interaction.update({ content: '', embeds: [buildTaskDetailEmbed(task)], components: [] });
}
if (act === 'assign') {
const task = taskManager.getTask(guildId, taskId);
if (!task) return interaction.reply({ content: '❌ Task not found.', ephemeral: true });
const select = new UserSelectMenuBuilder()
.setCustomId(`assignMembers:${taskId}`)
.setPlaceholder('Select members to assign…')
.setMinValues(0)
.setMaxValues(10);
await interaction.update({
content: `👥 Select members to assign to **"${task.title}"**:`,
components: [new ActionRowBuilder().addComponents(select)],
embeds: [],
});
}
},
assignMembers: async (interaction, [taskId]) => {
const guildId = interaction.guild.id;
const userIds = [...interaction.users.keys()];
const task = taskManager.getTask(guildId, taskId);
if (!task) return interaction.reply({ content: '❌ Task not found.', ephemeral: true });
taskManager.updateTask(guildId, taskId, { assignees: userIds });
await updateListMessage(interaction.guild);
const names = userIds.length ? userIds.map(id => `<@${id}>`).join(', ') : 'nobody';
await interaction.update({ content: `👥 **"${task.title}"** assigned to ${names}`, components: [], embeds: [] });
},
};
module.exports = handlers;