feat: askai bot hints for followups (#10291)

This commit is contained in:
BestCodes
2026-07-06 20:27:44 -07:00
committed by GitHub
parent af2c765c82
commit f96f62d985
@@ -9,6 +9,48 @@ import { answerQuestion } from "../utils/ai";
import { buildServerContext } from "../utils/discord/server-context";
import { logger } from "../utils/logger";
async function shouldSendFollowUpHint(
message: OmitPartialGroupDMChannel<Message<boolean>>,
): Promise<boolean> {
try {
const thread = message.channel;
if (!thread.isThread()) return false;
const botId = message.client.user?.id || "";
const starterMessage = await thread.fetchStarterMessage().catch(() => null);
const messages = await thread.messages.fetch({ limit: 20 });
let hasOtherHumanMessages = false;
let botWasPingedOrRepliedTo = false;
for (const msg of messages.values()) {
if (msg.author.bot) continue;
if (starterMessage && msg.id === starterMessage.id) continue;
if (msg.id === message.id) continue;
hasOtherHumanMessages = true;
if (msg.mentions.has(botId)) {
botWasPingedOrRepliedTo = true;
}
if (msg.reference?.messageId && !botWasPingedOrRepliedTo) {
const referenced = await thread.messages
.fetch(msg.reference.messageId)
.catch(() => null);
if (referenced?.author.bot) {
botWasPingedOrRepliedTo = true;
}
}
}
return !hasOtherHumanMessages && !botWasPingedOrRepliedTo;
} catch {
return false;
}
}
export default {
event: Events.MessageCreate,
handler: async (
@@ -56,6 +98,13 @@ export default {
logger.verbose(
`Ignoring thread message from ${message.author.username} (not mentioned or replied to)`,
);
if (await shouldSendFollowUpHint(message)) {
await message.channel.send(
"To ask me a follow-up, please **reply to one of my messages** or **@mention me**. I won't see messages sent otherwise.",
);
}
return;
}