Respond to Discord replies to the bot without requiring its name
This commit is contained in:
1 parent
bfeefc261f
commit
177878fabe
1 file changed
+13
-1
@@ -115,6 +115,16 @@ function markActiveAiConversation(userId, channelId) {
|
|||||||
activeAiConversations.set(userId, { channelId: channelId, expiresAt: Date.now() + AI_ACTIVE_CONVO_MS });
|
activeAiConversations.set(userId, { channelId: channelId, expiresAt: Date.now() + AI_ACTIVE_CONVO_MS });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isReplyToBot(message) {
|
||||||
|
if (!message.reference || !message.reference.messageId) return false;
|
||||||
|
try {
|
||||||
|
const refMessage = await message.channel.messages.fetch(message.reference.messageId);
|
||||||
|
return refMessage.author.id === client.user.id;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getAiHistory(userId) {
|
function getAiHistory(userId) {
|
||||||
const entry = aiHistories.get(userId);
|
const entry = aiHistories.get(userId);
|
||||||
if (!entry) return [];
|
if (!entry) return [];
|
||||||
@@ -1609,7 +1619,9 @@ client.on("messageCreate", async (message) => {
|
|||||||
} else if (lower === "!help") {
|
} else if (lower === "!help") {
|
||||||
await handleHelp(message);
|
await handleHelp(message);
|
||||||
} else if (!content.startsWith("!") && AI_ENABLED &&
|
} else if (!content.startsWith("!") && AI_ENABLED &&
|
||||||
(TRIGGER_MENTION.test(content) || isActiveAiConversation(message.author.id, message.channelId))) {
|
(TRIGGER_MENTION.test(content) ||
|
||||||
|
isActiveAiConversation(message.author.id, message.channelId) ||
|
||||||
|
await isReplyToBot(message))) {
|
||||||
if (canUseAI(message.author.id)) {
|
if (canUseAI(message.author.id)) {
|
||||||
try {
|
try {
|
||||||
const history = getAiHistory(message.author.id);
|
const history = getAiHistory(message.author.id);
|
||||||
|
|||||||
Reference in new issue
Block a user