cord-bot 1.1.1 → 1.1.2
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/src/bot.ts +17 -2
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -130,19 +130,33 @@ client.on(Events.MessageCreate, async (message: Message) => {
|
|
|
130
130
|
|
|
131
131
|
log(`New mention from ${message.author.tag}`);
|
|
132
132
|
|
|
133
|
-
//
|
|
133
|
+
// Post status message in channel, then create thread from it
|
|
134
|
+
// This allows us to update the status message later (Processing... → Done)
|
|
135
|
+
let statusMessage;
|
|
134
136
|
let thread;
|
|
135
137
|
try {
|
|
138
|
+
// Post status message in the channel
|
|
139
|
+
statusMessage = await (message.channel as TextChannel).send('🤖 Processing...');
|
|
140
|
+
|
|
136
141
|
// Generate thread name from message content
|
|
137
142
|
const rawText = message.content.replace(/<@!?\d+>/g, '').trim();
|
|
138
143
|
const threadName = rawText.length > 50
|
|
139
144
|
? rawText.slice(0, 47) + '...'
|
|
140
145
|
: rawText || 'New conversation';
|
|
141
146
|
|
|
142
|
-
thread
|
|
147
|
+
// Create thread from the status message
|
|
148
|
+
thread = await statusMessage.startThread({
|
|
143
149
|
name: threadName,
|
|
144
150
|
autoArchiveDuration: ThreadAutoArchiveDuration.OneDay,
|
|
145
151
|
});
|
|
152
|
+
|
|
153
|
+
// Copy the original message content into the thread for context
|
|
154
|
+
// (excluding the bot mention and the status message)
|
|
155
|
+
const originalMessages = await message.channel.messages.fetch({ limit: 10 });
|
|
156
|
+
const userMessage = originalMessages.find(m => m.id === message.id);
|
|
157
|
+
if (userMessage) {
|
|
158
|
+
await thread.send(`**${message.author.tag}:** ${rawText}`);
|
|
159
|
+
}
|
|
146
160
|
} catch (error) {
|
|
147
161
|
log(`Failed to create thread: ${error}`);
|
|
148
162
|
await message.reply('Failed to start thread. Try again?');
|
|
@@ -153,6 +167,7 @@ client.on(Events.MessageCreate, async (message: Message) => {
|
|
|
153
167
|
const sessionId = crypto.randomUUID();
|
|
154
168
|
|
|
155
169
|
// Store the thread → session mapping
|
|
170
|
+
// Note: thread.id === statusMessage.id because thread was created from that message
|
|
156
171
|
db.run(
|
|
157
172
|
'INSERT INTO threads (thread_id, session_id) VALUES (?, ?)',
|
|
158
173
|
[thread.id, sessionId]
|