Skip to content

Commit

Permalink
vote channel threads and reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatCats committed Nov 1, 2024
1 parent 0109cc1 commit 4b94836
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib/db/models/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ class ConfigSchema {
return Array.from(mapped.get(type)?.values() ?? [])
}

static onCache(event: "add" | "delete", type: string, listener: (doc: Config) => unknown) {
Config.cache.on(event, (doc) => {
if (doc.type === type) {
listener(doc)
}
})
return this
}

@Prop({ type: String, required: true })
type!: string

Expand Down
20 changes: 20 additions & 0 deletions src/modules/vote-channels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Emojis } from "@Constants"
import { Events } from "discord.js"
import { BotListener, Config } from "lib"

const VOTE_CHANNELS = Config.declareType("Vote Channels")
const channels: Map<string, Set<string>> = new Map()

Config.onCache("add", VOTE_CHANNELS, (doc) => channels.set(doc.guildId, new Set(doc.value.split(","))))
Config.onCache("delete", VOTE_CHANNELS, (doc) => channels.delete(doc.guildId))

BotListener(Events.MessageCreate, async (bot, message) => {
if (!message.author.bot || !message.inGuild() || message.channel.isThread()) return
if (!channels.get(message.guildId)?.has(message.channelId)) return

await Promise.all([
message.startThread({ name: "Discussion" }),
message.react(Emojis.thumbsup),
message.react(Emojis.thumbdown),
])
})

0 comments on commit 4b94836

Please sign in to comment.