-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.js
More file actions
164 lines (145 loc) · 6.91 KB
/
Copy pathcommands.js
File metadata and controls
164 lines (145 loc) · 6.91 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
const { ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder,
EmbedBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const taskManager = require('./taskManager');
const { buildTaskListEmbed, buildDoneEmbed } = require('./embedBuilder');
const commands = {
// /tasklist — posts or refreshes the persistent task board + done board
tasklist: {
data: {
name: 'tasklist',
description: '📋 Post the live task board + done board in this channel',
},
async execute(interaction) {
await interaction.deferReply();
const guildId = interaction.guild.id;
const guildData = taskManager.getGuildTasks(guildId);
const settings = taskManager.getGuildSettings(guildId);
// Delete old main board
if (guildData.listMessageId && guildData.listChannelId) {
try {
const oldCh = await interaction.guild.channels.fetch(guildData.listChannelId);
const oldMsg = await oldCh.messages.fetch(guildData.listMessageId);
await oldMsg.delete();
} catch {}
}
// Delete old done board
if (guildData.doneMessageId && guildData.doneChannelId) {
try {
const oldCh = await interaction.guild.channels.fetch(guildData.doneChannelId);
const oldMsg = await oldCh.messages.fetch(guildData.doneMessageId);
await oldMsg.delete();
} catch {}
}
// Post done board first (so main board appears below it, i.e. more recent)
const doneEmbed = buildDoneEmbed(guildData.tasks || [], settings);
const doneMsg = await interaction.channel.send({ embeds: [doneEmbed] });
taskManager.setDoneMessage(guildId, doneMsg.id, interaction.channel.id);
// Post main board
const { embeds, components } = buildTaskListEmbed(guildData, settings);
const msg = await interaction.editReply({ embeds, components });
taskManager.setListMessage(guildId, msg.id, interaction.channel.id);
}
},
// /addtask — quick add without UI
addtask: {
data: {
name: 'addtask',
description: '➕ Quickly add a task',
options: [
{ name: 'title', description: 'Task title', type: 3, required: true },
{ name: 'description', description: 'Task description', type: 3, required: false },
{ name: 'assignees', description: 'Mention users (e.g. @User1 @User2)', type: 3, required: false },
{ name: 'deadline', description: 'Deadline (YYYY-MM-DD or YYYY-MM-DD HH:MM)', type: 3, required: false },
{ name: 'reminder', description: 'Daily reminder until deadline?', type: 5, required: false },
]
},
async execute(interaction) {
const title = interaction.options.getString('title');
const description = interaction.options.getString('description') || '';
const assigneeStr = interaction.options.getString('assignees') || '';
const deadlineStr = interaction.options.getString('deadline') || '';
const reminder = interaction.options.getBoolean('reminder') || false;
const assignees = [...assigneeStr.matchAll(/<@!?(\d+)>/g)].map(m => m[1]);
let deadline = null;
if (deadlineStr) {
const d = new Date(deadlineStr);
if (!isNaN(d)) deadline = d.toISOString();
}
const guildId = interaction.guild.id;
taskManager.addTask(guildId, { title, description, assignees, deadline, reminder });
await updateListMessage(interaction.guild);
await interaction.reply({ content: `✅ Task **"${title}"** added!`, ephemeral: true });
}
},
// /settings
settings: {
data: {
name: 'settings',
description: '⚙️ Configure timezone, working hours & display options',
},
async execute(interaction) {
await showSettingsPanel(interaction);
}
}
};
async function showSettingsPanel(interaction) {
const guildId = interaction.guild.id;
const s = taskManager.getGuildSettings(guildId);
const dayNames = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
const workDaysStr = (s.workDays || [1,2,3,4,5]).map(d => dayNames[d]).join(', ');
const embed = new EmbedBuilder()
.setTitle('⚙️ TaskBot Settings')
.setColor(0xEB459E)
.addFields(
{ name: '🌍 Timezone', value: s.timezone, inline: true },
{ name: '🕘 Work Hours', value: `${s.workStart} – ${s.workEnd}`, inline: true },
{ name: '📅 Work Days', value: workDaysStr, inline: true },
{ name: '📊 Progress Bar', value: `${s.barLength ?? 16} blocks`, inline: true },
{ name: '✅ Done preview', value: `${s.donePreviewCount ?? 3} on main board`, inline: true },
{ name: '📋 Done board size', value: `${s.doneListShowCount ?? 10} tasks`, inline: true },
)
.setFooter({ text: 'Reminders only fire during working hours · members can set personal timezone' });
const row1 = new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId('settings:timezone').setLabel('🌍 Timezone').setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('settings:hours').setLabel('🕘 Work Hours').setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('settings:days').setLabel('📅 Work Days').setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('settings:display').setLabel('📊 Display').setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setCustomId('settings:mytz').setLabel('👤 My Timezone').setStyle(ButtonStyle.Secondary),
);
const opts = { embeds: [embed], components: [row1], ephemeral: true };
if (interaction.replied || interaction.deferred) {
await interaction.editReply(opts);
} else {
await interaction.reply(opts);
}
}
async function updateListMessage(guild) {
const guildId = guild.id;
const guildData = taskManager.getGuildTasks(guildId);
const settings = taskManager.getGuildSettings(guildId);
// Update main board
if (guildData.listMessageId && guildData.listChannelId) {
try {
const channel = await guild.channels.fetch(guildData.listChannelId);
const msg = await channel.messages.fetch(guildData.listMessageId);
const { embeds, components } = buildTaskListEmbed(guildData, settings);
await msg.edit({ embeds, components });
} catch (e) {
console.error('Could not update main board:', e.message);
}
}
// Update done board
if (guildData.doneMessageId && guildData.doneChannelId) {
try {
const channel = await guild.channels.fetch(guildData.doneChannelId);
const msg = await channel.messages.fetch(guildData.doneMessageId);
const doneEmbed = buildDoneEmbed(guildData.tasks || [], settings);
await msg.edit({ embeds: [doneEmbed] });
} catch (e) {
console.error('Could not update done board:', e.message);
}
}
}
module.exports = commands;
module.exports.showSettingsPanel = showSettingsPanel;
module.exports.updateListMessage = updateListMessage;