cord-bot 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/cord/SKILL.md +10 -0
- package/src/bot.ts +44 -0
package/package.json
CHANGED
package/skills/cord/SKILL.md
CHANGED
|
@@ -340,6 +340,16 @@ cord buttons 123456789 "Delete all archived items older than 30 days?" \
|
|
|
340
340
|
|
|
341
341
|
---
|
|
342
342
|
|
|
343
|
+
## Auto-Complete Behavior
|
|
344
|
+
|
|
345
|
+
When a user adds a ✅ reaction to the **last message** in a thread, Cord automatically:
|
|
346
|
+
1. Detects the reaction
|
|
347
|
+
2. Updates the thread starter message to "✅ Done"
|
|
348
|
+
|
|
349
|
+
This provides a quick way for users to signal "conversation complete" without explicit commands.
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
343
353
|
## HTTP API
|
|
344
354
|
|
|
345
355
|
For advanced use cases (webhooks, external scripts), see [HTTP-API.md](./HTTP-API.md).
|
package/src/bot.ts
CHANGED
|
@@ -29,6 +29,7 @@ const client = new Client({
|
|
|
29
29
|
GatewayIntentBits.Guilds,
|
|
30
30
|
GatewayIntentBits.GuildMessages,
|
|
31
31
|
GatewayIntentBits.MessageContent,
|
|
32
|
+
GatewayIntentBits.GuildMessageReactions,
|
|
32
33
|
],
|
|
33
34
|
});
|
|
34
35
|
|
|
@@ -176,6 +177,49 @@ client.on(Events.MessageCreate, async (message: Message) => {
|
|
|
176
177
|
});
|
|
177
178
|
});
|
|
178
179
|
|
|
180
|
+
// =========================================================================
|
|
181
|
+
// REACTION HANDLER: ✅ on last message marks thread as done
|
|
182
|
+
// =========================================================================
|
|
183
|
+
client.on(Events.MessageReactionAdd, async (reaction, user) => {
|
|
184
|
+
// Ignore bot reactions
|
|
185
|
+
if (user.bot) return;
|
|
186
|
+
|
|
187
|
+
// Only handle ✅ reactions
|
|
188
|
+
if (reaction.emoji.name !== '✅') return;
|
|
189
|
+
|
|
190
|
+
// Only handle reactions in threads
|
|
191
|
+
const channel = reaction.message.channel;
|
|
192
|
+
if (!channel.isThread()) return;
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
const thread = channel;
|
|
196
|
+
const parentChannelId = thread.parentId;
|
|
197
|
+
if (!parentChannelId) return;
|
|
198
|
+
|
|
199
|
+
// Check if this is the last message in the thread
|
|
200
|
+
const messages = await thread.messages.fetch({ limit: 1 });
|
|
201
|
+
const lastMessage = messages.first();
|
|
202
|
+
|
|
203
|
+
if (!lastMessage || lastMessage.id !== reaction.message.id) {
|
|
204
|
+
// Reaction is not on the last message, ignore
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
log(`✅ reaction on last message in thread ${thread.id}`);
|
|
209
|
+
|
|
210
|
+
// Update thread starter message to "Done"
|
|
211
|
+
// The thread ID equals the starter message ID (thread was created from that message)
|
|
212
|
+
const parentChannel = await client.channels.fetch(parentChannelId);
|
|
213
|
+
if (parentChannel?.isTextBased()) {
|
|
214
|
+
const starterMessage = await (parentChannel as TextChannel).messages.fetch(thread.id);
|
|
215
|
+
await starterMessage.edit('✅ Done');
|
|
216
|
+
log(`Thread ${thread.id} marked as Done`);
|
|
217
|
+
}
|
|
218
|
+
} catch (error) {
|
|
219
|
+
log(`Failed to mark thread done: ${error}`);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
179
223
|
// Start the bot
|
|
180
224
|
const token = process.env.DISCORD_BOT_TOKEN;
|
|
181
225
|
if (!token) {
|