diff --git a/src/events/discord.ts b/src/events/discord.ts index 5a61c3b..15b7f27 100644 --- a/src/events/discord.ts +++ b/src/events/discord.ts @@ -9,6 +9,7 @@ import { config } from "@/config" import { isMessageQuizQuestion } from "@/commands/fun/quiz/quiz" import { generateWithGoogle } from "@/utils/intelligence" import { backSpace } from "@/utils/textUtils" +import { detectFeur, generateResponse } from "@/utils/messageManager" client.on(Events.InteractionCreate, async (interaction) => { if (interaction.isCommand()) { @@ -88,4 +89,8 @@ client.on(Events.MessageCreate, async (message) => { logger.info(`Réponse de l'IA à <@${message.author.id}> dans <#${channelId}> : ${aiReponse}`) } } + + if(detectFeur(message.content)) { + message.channel.send(generateResponse()) + } }) diff --git a/src/utils/messageManager.ts b/src/utils/messageManager.ts new file mode 100644 index 0000000..9a5b90b --- /dev/null +++ b/src/utils/messageManager.ts @@ -0,0 +1,53 @@ +const quoiRegexs = [ + // Quoi + /quoi/, + /quoi\?/, + /quoi\ ?/, + /quoi\ ?\?/, + /quoi\ ?\?/, + + + // Koa + /koa/, + /koa\?/, + /koa\ ?/, + /koa\ ?\?/, + /koa\ ?\?/, +] + +export const possibleResponses = [ + { + response: "Feur.", + probability: 80 + }, + { + response: "coubeh.", + probability: 10 + }, + { + response: "drilatère.", + probability: 10 + } +] + + +export function detectFeur(message: string): boolean { + for (const regex of quoiRegexs) { + if (regex.test(message.toLowerCase())) { + return true + } + } + return false +} + +export function generateResponse(): string { + const random = Math.random() * 100 + let cumulativeProbability = 0 + for (const response of possibleResponses) { + cumulativeProbability += response.probability + if (random <= cumulativeProbability) { + return response.response + } + } + return "Feur." +} \ No newline at end of file