diff options
author | Minteck <contact@minteck.org> | 2022-07-13 23:34:21 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-07-13 23:34:21 +0200 |
commit | 7b5df4ca0a5bd6fcf033ef40563599593b156910 (patch) | |
tree | 56cb89f3900adde9da67e7558793a20fb40d7197 /core/ManagedChannelManager.ts | |
download | cooler-pony-7b5df4ca0a5bd6fcf033ef40563599593b156910.tar.gz cooler-pony-7b5df4ca0a5bd6fcf033ef40563599593b156910.tar.bz2 cooler-pony-7b5df4ca0a5bd6fcf033ef40563599593b156910.zip |
Initial commit
Diffstat (limited to 'core/ManagedChannelManager.ts')
-rw-r--r-- | core/ManagedChannelManager.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/core/ManagedChannelManager.ts b/core/ManagedChannelManager.ts new file mode 100644 index 0000000..538b345 --- /dev/null +++ b/core/ManagedChannelManager.ts @@ -0,0 +1,41 @@ +import {Message} from "discord.js"; +import {Welcome} from "./Welcome"; +import Fuse from "fuse.js"; +import {LogManager} from "./LogManager"; + +export class ManagedChannelManager { + public static handleMessage(message: Message): void { + if (message.author.id === global.client.user.id) return; + let data = global.data; + + let channels = data.managedChannels.map(i => i.channel); + if (channels.includes(message.channel.id)) { + let channel = data.managedChannels.find(i => i.channel === message.channel.id); + if (channel.user === message.author.id) { + let question = Welcome.questions[channel.question]; + + const fuse = new Fuse(question.response, { + includeScore: true + }) + + let results = fuse.search(message.content); + + if (results.length === 0) { + message.react("❌"); + return; + } + + LogManager.verbose("Question \"" + question.question + "\": response \"" + message.content + "\", score " + results[0].score.toFixed(5)); + + if (results[0].score < 0.5) { + message.react("✅"); + message.member.roles.add("996411960293859400"); + message.channel.delete(); + data.managedChannels.splice(data.managedChannels.indexOf(channel), 1); + } else { + message.react("❌"); + } + } + } + } +}
\ No newline at end of file |