diff --git a/index.ts b/index.ts index 85cda64..5260e11 100644 --- a/index.ts +++ b/index.ts @@ -43,6 +43,7 @@ client.on("messageCreate", async (message) => { if (message.channel.type != ChannelType.GuildText) return; if (message.content == "die") process.exit(1); + // "adapted" from https://github.com/ryanccn/blahaj/blob/main/src/chat.ts await message.channel.sendTyping(); @@ -51,11 +52,18 @@ client.on("messageCreate", async (message) => { message.channel.sendTyping(); }, 5000); + const recieved = Date.now(); + + await new Promise((resolve) => setTimeout(() => resolve(), 1500)); + try { const msgs = await message.channel.messages.fetch({ after: SnowflakeUtil.generate({ timestamp: Date.now() - 5 * 60 * 1000, }).toString(), + before: SnowflakeUtil.generate({ + timestamp: recieved + 500, + }).toString(), }); const context = [ @@ -94,10 +102,17 @@ client.on("messageCreate", async (message) => { .then(({ data }) => !data.results[0].flagged); if (isAppropriate) { - await message.channel.send({ - content: responseMessage.content, - allowedMentions: { parse: ["users"] }, - }); + try { + await message.reply({ + content: responseMessage.content, + allowedMentions: { parse: ["users"] }, + }); + } catch { + await message.channel.send({ + content: responseMessage.content, + allowedMentions: { parse: ["users"] }, + }); + } } else { await message.channel.send({ embeds: [