diff options
author | V <vendicated@riseup.net> | 2023-04-22 03:18:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-22 01:18:19 +0000 |
commit | 63fc354d483b86857bbee7f540c66ba614fc0f1f (patch) | |
tree | 6ebe100e5ff63254adfdb0c44cb473dcc339cf35 /src/plugins/moyai.ts | |
parent | c6f0c84935db37e2a18578a081404d84292fe36a (diff) | |
download | Vencord-63fc354d483b86857bbee7f540c66ba614fc0f1f.tar.gz Vencord-63fc354d483b86857bbee7f540c66ba614fc0f1f.tar.bz2 Vencord-63fc354d483b86857bbee7f540c66ba614fc0f1f.zip |
feat: auto-managed flux subscriptions via plugin.flux (#959)
Diffstat (limited to 'src/plugins/moyai.ts')
-rw-r--r-- | src/plugins/moyai.ts | 66 |
1 files changed, 28 insertions, 38 deletions
diff --git a/src/plugins/moyai.ts b/src/plugins/moyai.ts index 146ac3f..b32bd99 100644 --- a/src/plugins/moyai.ts +++ b/src/plugins/moyai.ts @@ -21,7 +21,7 @@ import { makeRange } from "@components/PluginSettings/components/SettingSliderCo import { Devs } from "@utils/constants"; import { sleep } from "@utils/misc"; import definePlugin, { OptionType } from "@utils/types"; -import { FluxDispatcher, SelectedChannelStore, UserStore } from "@webpack/common"; +import { SelectedChannelStore, UserStore } from "@webpack/common"; import { Message, ReactionEmoji } from "discord-types/general"; interface IMessageCreate { @@ -80,50 +80,40 @@ export default definePlugin({ description: "🗿🗿🗿🗿🗿🗿🗿🗿", settings, - async onMessage(e: IMessageCreate) { - if (e.optimistic || e.type !== "MESSAGE_CREATE") return; - if (e.message.state === "SENDING") return; - if (settings.store.ignoreBots && e.message.author?.bot) return; - if (!e.message.content) return; - if (e.channelId !== SelectedChannelStore.getChannelId()) return; + flux: { + async MESSAGE_CREATE({ optimistic, type, message, channelId }: IMessageCreate) { + if (optimistic || type !== "MESSAGE_CREATE") return; + if (message.state === "SENDING") return; + if (settings.store.ignoreBots && message.author?.bot) return; + if (!message.content) return; + if (channelId !== SelectedChannelStore.getChannelId()) return; - const moyaiCount = getMoyaiCount(e.message.content); + const moyaiCount = getMoyaiCount(message.content); - for (let i = 0; i < moyaiCount; i++) { - boom(); - await sleep(300); - } - }, + for (let i = 0; i < moyaiCount; i++) { + boom(); + await sleep(300); + } + }, - onReaction(e: IReactionAdd) { - if (e.optimistic || e.type !== "MESSAGE_REACTION_ADD") return; - if (settings.store.ignoreBots && UserStore.getUser(e.userId)?.bot) return; - if (e.channelId !== SelectedChannelStore.getChannelId()) return; - - const name = e.emoji.name.toLowerCase(); - if (name !== MOYAI && !name.includes("moyai") && !name.includes("moai")) return; - - boom(); - }, + MESSAGE_REACTION_ADD({ optimistic, type, channelId, userId, emoji }: IReactionAdd) { + if (optimistic || type !== "MESSAGE_REACTION_ADD") return; + if (settings.store.ignoreBots && UserStore.getUser(userId)?.bot) return; + if (channelId !== SelectedChannelStore.getChannelId()) return; - onVoiceChannelEffect(e: IVoiceChannelEffectSendEvent) { - if (!e.emoji?.name) return; - const name = e.emoji.name.toLowerCase(); - if (name !== MOYAI && !name.includes("moyai") && !name.includes("moai")) return; + const name = emoji.name.toLowerCase(); + if (name !== MOYAI && !name.includes("moyai") && !name.includes("moai")) return; - boom(); - }, + boom(); + }, - start() { - FluxDispatcher.subscribe("MESSAGE_CREATE", this.onMessage); - FluxDispatcher.subscribe("MESSAGE_REACTION_ADD", this.onReaction); - FluxDispatcher.subscribe("VOICE_CHANNEL_EFFECT_SEND", this.onVoiceChannelEffect); - }, + VOICE_CHANNEL_EFFECT_SEND({ emoji }: IVoiceChannelEffectSendEvent) { + if (!emoji?.name) return; + const name = emoji.name.toLowerCase(); + if (name !== MOYAI && !name.includes("moyai") && !name.includes("moai")) return; - stop() { - FluxDispatcher.unsubscribe("MESSAGE_CREATE", this.onMessage); - FluxDispatcher.unsubscribe("MESSAGE_REACTION_ADD", this.onReaction); - FluxDispatcher.unsubscribe("VOICE_CHANNEL_EFFECT_SEND", this.onVoiceChannelEffect); + boom(); + } } }); |