diff --git a/src/equicordplugins/ingtoninator/index.ts b/src/equicordplugins/ingtoninator/index.ts deleted file mode 100644 index 2b8a06f3..00000000 --- a/src/equicordplugins/ingtoninator/index.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Vencord, a Discord client mod - * Copyright (c) 2025 Vendicated and contributors - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -import { addMessagePreSendListener, MessageSendListener, removeMessagePreSendListener } from "@api/MessageEvents"; -import { EquicordDevs } from "@utils/constants"; -import definePlugin from "@utils/types"; - -const isLegal = (word: string) => { - if (word.startsWith("<@")) return false; - if (/^https?:\/\//i.test(word)) return false; - return true; -}; - -const handleMessage: MessageSendListener = (channelId, message) => { - if (!message.content || !message.content.trim()) return; - - const words = message.content.trim().split(/\s+/); - if (words.length === 0) return; - - let index = -1; - let attempts = 0; - do { - index = Math.floor(Math.random() * words.length); - attempts++; - } while (!isLegal(words[index]) && attempts < words.length * 2); - - if (isLegal(words[index])) { - const word = words[index]; - words[index] = word === word.toUpperCase() ? word + "INGTON" : word + "ington"; - } - - message.content = words.join(" "); -}; - -export default definePlugin({ - name: "Ingtoninator", - description: "Suffixes 'ington' to a random word in your message", - authors: [EquicordDevs.zyqunix], - start() { - addMessagePreSendListener(handleMessage); - }, - stop() { - removeMessagePreSendListener(handleMessage); - } -}); diff --git a/src/equicordplugins/ingtoninator/index.tsx b/src/equicordplugins/ingtoninator/index.tsx new file mode 100644 index 00000000..20093be0 --- /dev/null +++ b/src/equicordplugins/ingtoninator/index.tsx @@ -0,0 +1,101 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2025 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { addChatBarButton, ChatBarButton, ChatBarButtonFactory, removeChatBarButton } from "@api/ChatButtons"; +import { addMessagePreSendListener, removeMessagePreSendListener } from "@api/MessageEvents"; +import { definePluginSettings } from "@api/Settings"; +import { EquicordDevs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { React } from "@webpack/common"; + +const settings = definePluginSettings({ + showIcon: { + type: OptionType.BOOLEAN, + default: true, + description: "Show a button to toggle the Ingtoninator plugin", + restartNeeded: true + }, + isEnabled: { + type: OptionType.BOOLEAN, + default: true, + description: "Enable or disable the Ingtoninator" + } +}); + +const isLegal = (word: string) => { + if (word.startsWith("<@")) return false; + if (/^https?:\/\//i.test(word)) return false; + if (word.length < 4) return false; + + return true; +}; + +const ingtonize = (word: string) => { + return word.endsWith("ton") ? word + "ton" : word + "ington"; +}; + +const handleMessage = ((channelId, message) => { + if (!settings.store.isEnabled) return; + if (!message.content || !message.content.trim()) return; + + const words = message.content.trim().split(/\s+/); + if (words.length === 0) return; + + let index = -1; + let attempts = 0; + do { + index = Math.floor(Math.random() * words.length); + attempts++; + } while (!isLegal(words[index]) && attempts < words.length * 2); + + if (isLegal(words[index])) { + const word = words[index]; + words[index] = word.endsWith("ing") + ? (word === word.toUpperCase() ? word + "TON" : word + "ton") + : word; + } + + message.content = words.join(" "); +}); + +const IngtoninatorButton: ChatBarButtonFactory = ({ isMainChat }) => { + const { isEnabled, showIcon } = settings.use(["isEnabled", "showIcon"]); + const toggle = () => settings.store.isEnabled = !settings.store.isEnabled; + + if (!isMainChat || !showIcon) return null; + + return ( + + {isEnabled ? ( + + + + ) : ( + + + + )} + + ); +}; + +export default definePlugin({ + name: "Ingtoninator", + description: "Suffixes 'ington' to a random word in your message", + authors: [EquicordDevs.zyqunix], + settings, + start() { + addChatBarButton("Ingtoninator", IngtoninatorButton); + addMessagePreSendListener(handleMessage); + }, + stop() { + removeChatBarButton("Ingtoninator"); + removeMessagePreSendListener(handleMessage); + } +});