From 9338b92b1a3b68308950a20f0d694901e4c39e2a Mon Sep 17 00:00:00 2001 From: Sofia Date: Sat, 14 Jan 2023 14:47:12 -0300 Subject: [PATCH] feat(SilentTyping): add toggle command and icon (#398) Co-authored-by: Ven Co-authored-by: Justice Almanzar --- src/plugins/invisibleChat/index.tsx | 5 +- src/plugins/silentTyping.ts | 33 -------- src/plugins/silentTyping.tsx | 118 ++++++++++++++++++++++++++++ src/webpack/common.tsx | 1 + 4 files changed, 120 insertions(+), 37 deletions(-) delete mode 100644 src/plugins/silentTyping.ts create mode 100644 src/plugins/silentTyping.tsx diff --git a/src/plugins/invisibleChat/index.tsx b/src/plugins/invisibleChat/index.tsx index e2f776957..519a9a6e0 100644 --- a/src/plugins/invisibleChat/index.tsx +++ b/src/plugins/invisibleChat/index.tsx @@ -21,14 +21,11 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import { getStegCloak } from "@utils/dependencies"; import definePlugin from "@utils/types"; -import { findByPropsLazy } from "@webpack"; -import { Button, ButtonLooks, ChannelStore, FluxDispatcher, Tooltip } from "@webpack/common"; +import { Button, ButtonLooks, ButtonWrapperClasses, ChannelStore, FluxDispatcher, Tooltip } from "@webpack/common"; import { buildDecModal } from "./components/DecryptionModal"; import { buildEncModal } from "./components/EncryptionModal"; -const ButtonWrapperClasses = findByPropsLazy("buttonWrapper", "buttonContent"); - let steggo: any; function PopOverIcon() { diff --git a/src/plugins/silentTyping.ts b/src/plugins/silentTyping.ts deleted file mode 100644 index 8680a8667..000000000 --- a/src/plugins/silentTyping.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ - -import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; - -export default definePlugin({ - name: "SilentTyping", - authors: [Devs.Ven], - description: "Hide that you are typing", - patches: [{ - find: "startTyping:", - replacement: { - match: /startTyping:.+?,stop/, - replace: "startTyping:()=>{},stop" - } - }] -}); diff --git a/src/plugins/silentTyping.tsx b/src/plugins/silentTyping.tsx new file mode 100644 index 000000000..442be3927 --- /dev/null +++ b/src/plugins/silentTyping.tsx @@ -0,0 +1,118 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; +import { definePluginSettings } from "@api/settings"; +import ErrorBoundary from "@components/ErrorBoundary"; +import { Devs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { Button, ButtonLooks, ButtonWrapperClasses, FluxDispatcher, React, Tooltip } from "@webpack/common"; + +const settings = definePluginSettings({ + showIcon: { + type: OptionType.BOOLEAN, + default: false, + description: "Show an icon for toggling the plugin", + restartNeeded: true, + }, + isEnabled: { + type: OptionType.BOOLEAN, + description: "Toggle functionality", + default: true, + } +}); + +function SilentTypingToggle() { + const { isEnabled } = settings.use(["isEnabled"]); + const toggle = () => settings.store.isEnabled = !settings.store.isEnabled; + + return ( + + {(tooltipProps: any) => ( +
+ +
+ )} +
+ ); +} + +export default definePlugin({ + name: "SilentTyping", + authors: [Devs.Ven, Devs.dzshn], + description: "Hide that you are typing", + patches: [ + { + find: "startTyping:", + replacement: { + match: /startTyping:.+?,stop/, + replace: "startTyping:$self.startTyping,stop" + } + }, + { + find: ".activeCommandOption", + predicate: () => settings.store.showIcon, + replacement: { + match: /\i=\i\.activeCommand,\i=\i\.activeCommandOption,.{1,133}(.)=\[\];/, + replace: "$&;$1.push($self.chatBarIcon());", + } + }, + ], + dependencies: ["CommandsAPI"], + settings, + commands: [{ + name: "silenttype", + description: "Toggle whether you're hiding that you're typing or not.", + inputType: ApplicationCommandInputType.BUILT_IN, + options: [ + { + name: "value", + description: "whether to hide or not that you're typing (default is toggle)", + required: false, + type: ApplicationCommandOptionType.BOOLEAN, + }, + ], + execute: async (args, ctx) => { + settings.store.isEnabled = !!findOption(args, "value", !settings.store.isEnabled); + sendBotMessage(ctx.channel.id, { + content: settings.store.isEnabled ? "Silent typing enabled!" : "Silent typing disabled!", + }); + }, + }], + + async startTyping(channelId: string) { + if (settings.store.isEnabled) return; + FluxDispatcher.dispatch({ type: "TYPING_START_LOCAL", channelId }); + }, + + chatBarIcon: ErrorBoundary.wrap(SilentTypingToggle, { noop: true }), +}); diff --git a/src/webpack/common.tsx b/src/webpack/common.tsx index 2a7d587ea..855b887b5 100644 --- a/src/webpack/common.tsx +++ b/src/webpack/common.tsx @@ -79,6 +79,7 @@ export let Router: any; export let TextInput: any; export let Text: (props: TextProps) => JSX.Element; export const TextArea = findByCodeLazy("handleSetRef", "textArea") as React.ComponentType>; +export const ButtonWrapperClasses = findByPropsLazy("buttonWrapper", "buttonContent") as Record; export const Select = LazyComponent(() => findByCode("optionClassName", "popoutPosition", "autoFocus", "maxVisibleItems")); export const Slider = LazyComponent(() => findByCode("closestMarkerIndex", "stickToMarkers"));