-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttonHandlers.js
More file actions
188 lines (169 loc) · 9.84 KB
/
Copy pathbuttonHandlers.js
File metadata and controls
188 lines (169 loc) · 9.84 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const {
ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder,
StringSelectMenuBuilder, StringSelectMenuOptionBuilder,
ButtonBuilder, ButtonStyle, EmbedBuilder
} = require('discord.js');
const taskManager = require('./taskManager');
const { updateListMessage, showSettingsPanel } = require('./commands');
const { buildTaskDetailEmbed } = require('./embedBuilder');
// Helper: build task picker select menu
function taskPicker(tasks, action, placeholder) {
const options = tasks.slice(0, 25).map((t, i) =>
new StringSelectMenuOptionBuilder()
.setLabel(`${i + 1}. ${t.title.slice(0, 80)}`)
.setValue(`${action}:${t.id}`)
.setDescription(t.deadline ? `Due: ${t.deadline.slice(0, 10)}` : 'No deadline')
);
return new StringSelectMenuBuilder()
.setCustomId(`taskSelect:${action}`)
.setPlaceholder(placeholder)
.addOptions(options);
}
const handlers = {
// ─── Add Task ─────────────────────────────────────────────────────────────
addTask: async (interaction, [_sub]) => {
const modal = new ModalBuilder()
.setCustomId('addTaskModal:new')
.setTitle('➕ Add New Task');
modal.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('title').setLabel('Task Title').setStyle(TextInputStyle.Short).setRequired(true).setMaxLength(80)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('description').setLabel('Description (optional)').setStyle(TextInputStyle.Paragraph).setRequired(false).setMaxLength(500)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('assignees').setLabel('Assign to (user IDs or @mentions)').setStyle(TextInputStyle.Short).setRequired(false).setPlaceholder('e.g. @John @Maria or 123456789,987654321')
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('deadline').setLabel('Deadline (YYYY-MM-DD or YYYY-MM-DD HH:MM)').setStyle(TextInputStyle.Short).setRequired(false).setPlaceholder('2025-12-31 17:00')
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('reminder').setLabel('Daily reminder? (yes/no)').setStyle(TextInputStyle.Short).setRequired(false).setPlaceholder('yes')
)
);
await interaction.showModal(modal);
},
// ─── Complete Task ─────────────────────────────────────────────────────────
completeTask: async (interaction, [sub]) => {
if (sub === 'pick') {
const { tasks } = taskManager.getGuildTasks(interaction.guild.id);
const open = tasks.filter(t => !t.done);
if (!open.length) return interaction.reply({ content: 'No open tasks!', ephemeral: true });
const select = taskPicker(open, 'complete', 'Select a task to complete…');
const row = new ActionRowBuilder().addComponents(select);
await interaction.reply({ content: '✅ Which task is done?', components: [row], ephemeral: true });
}
},
// ─── Edit Task ─────────────────────────────────────────────────────────────
editTask: async (interaction, [sub, taskId]) => {
if (sub === 'pick') {
const { tasks } = taskManager.getGuildTasks(interaction.guild.id);
const open = tasks.filter(t => !t.done);
if (!open.length) return interaction.reply({ content: 'No open tasks!', ephemeral: true });
const select = taskPicker(open, 'edit', 'Select a task to edit…');
const row = new ActionRowBuilder().addComponents(select);
await interaction.reply({ content: '✏️ Which task do you want to edit?', components: [row], ephemeral: true });
} else if (taskId) {
const task = taskManager.getTask(interaction.guild.id, taskId);
if (!task) return interaction.reply({ content: 'Task not found.', ephemeral: true });
const modal = new ModalBuilder()
.setCustomId(`editTaskModal:${taskId}`)
.setTitle('✏️ Edit Task');
modal.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('title').setLabel('Task Title').setStyle(TextInputStyle.Short).setRequired(true).setValue(task.title)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('description').setLabel('Description').setStyle(TextInputStyle.Paragraph).setRequired(false).setValue(task.description || '')
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('assignees').setLabel('Assign to (user IDs, comma separated)').setStyle(TextInputStyle.Short).setRequired(false).setValue((task.assignees || []).join(','))
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('deadline').setLabel('Deadline (YYYY-MM-DD HH:MM)').setStyle(TextInputStyle.Short).setRequired(false).setValue(task.deadline ? task.deadline.slice(0, 16).replace('T', ' ') : '')
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('reminder').setLabel('Daily reminder? (yes/no)').setStyle(TextInputStyle.Short).setRequired(false).setValue(task.reminder ? 'yes' : 'no')
)
);
await interaction.showModal(modal);
}
},
// ─── Delete Task ───────────────────────────────────────────────────────────
deleteTask: async (interaction, [sub]) => {
if (sub === 'pick') {
const { tasks } = taskManager.getGuildTasks(interaction.guild.id);
const open = tasks.filter(t => !t.done);
if (!open.length) return interaction.reply({ content: 'No tasks to delete!', ephemeral: true });
const select = taskPicker(open, 'delete', 'Select a task to delete…');
const row = new ActionRowBuilder().addComponents(select);
await interaction.reply({ content: '🗑️ Which task do you want to delete?', components: [row], ephemeral: true });
}
},
// ─── Settings ─────────────────────────────────────────────────────────────
settings: async (interaction, [sub]) => {
if (sub === 'open') {
await showSettingsPanel(interaction);
return;
}
if (sub === 'timezone') {
const modal = new ModalBuilder().setCustomId('settingsModal:timezone').setTitle('🌍 Set Server Timezone');
modal.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('timezone').setLabel('Timezone (e.g. Europe/Berlin, America/New_York)').setStyle(TextInputStyle.Short).setRequired(true).setPlaceholder('UTC')
)
);
await interaction.showModal(modal);
}
if (sub === 'hours') {
const s = taskManager.getGuildSettings(interaction.guild.id);
const modal = new ModalBuilder().setCustomId('settingsModal:hours').setTitle('🕘 Set Working Hours');
modal.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('workStart').setLabel('Work Start (HH:MM in 24h)').setStyle(TextInputStyle.Short).setRequired(true).setValue(s.workStart)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('workEnd').setLabel('Work End (HH:MM in 24h)').setStyle(TextInputStyle.Short).setRequired(true).setValue(s.workEnd)
)
);
await interaction.showModal(modal);
}
if (sub === 'days') {
const s = taskManager.getGuildSettings(interaction.guild.id);
const modal = new ModalBuilder().setCustomId('settingsModal:days').setTitle('📅 Set Work Days');
modal.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('workDays').setLabel('Work days (0=Sun,1=Mon,...6=Sat, comma sep)').setStyle(TextInputStyle.Short).setRequired(true).setValue((s.workDays || [1,2,3,4,5]).join(','))
)
);
await interaction.showModal(modal);
}
if (sub === 'display') {
const s = taskManager.getGuildSettings(interaction.guild.id);
const modal = new ModalBuilder().setCustomId('settingsModal:display').setTitle('📊 Display Settings');
modal.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('barLength').setLabel('Progress bar length (blocks, 8–24)').setStyle(TextInputStyle.Short).setRequired(true).setValue(String(s.barLength ?? 16))
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('donePreviewCount').setLabel('Completed tasks shown on main board (1–10)').setStyle(TextInputStyle.Short).setRequired(true).setValue(String(s.donePreviewCount ?? 3))
),
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('doneListShowCount').setLabel('Max tasks shown on done board (5–50)').setStyle(TextInputStyle.Short).setRequired(true).setValue(String(s.doneListShowCount ?? 10))
)
);
await interaction.showModal(modal);
}
if (sub === 'mytz') {
const modal = new ModalBuilder().setCustomId('settingsModal:mytz').setTitle('👤 My Personal Timezone');
modal.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder().setCustomId('timezone').setLabel('Your timezone (e.g. Asia/Tokyo)').setStyle(TextInputStyle.Short).setRequired(true).setPlaceholder('UTC')
)
);
await interaction.showModal(modal);
}
},
};
module.exports = handlers;