2023-01-14 12:47:12 -05:00
|
|
|
/*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-02-06 10:29:47 -05:00
|
|
|
import { addChatBarButton, ChatBarButton, removeChatBarButton } from "@api/ChatButtons";
|
2023-01-14 12:47:12 -05:00
|
|
|
import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands";
|
2024-05-11 16:49:00 -04:00
|
|
|
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
|
2023-05-05 19:36:00 -04:00
|
|
|
import { definePluginSettings } from "@api/Settings";
|
2023-01-14 12:47:12 -05:00
|
|
|
import { Devs } from "@utils/constants";
|
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
2024-05-11 16:49:00 -04:00
|
|
|
import { FluxDispatcher, Menu, React } from "@webpack/common";
|
2023-01-14 12:47:12 -05:00
|
|
|
|
|
|
|
const settings = definePluginSettings({
|
|
|
|
showIcon: {
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
default: false,
|
|
|
|
description: "Show an icon for toggling the plugin",
|
|
|
|
restartNeeded: true,
|
|
|
|
},
|
2024-05-11 16:49:00 -04:00
|
|
|
contextMenu: {
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
description: "Add option to toggle the functionality in the chat input context menu",
|
|
|
|
default: true
|
|
|
|
},
|
2023-01-14 12:47:12 -05:00
|
|
|
isEnabled: {
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
description: "Toggle functionality",
|
|
|
|
default: true,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-06 12:12:09 -05:00
|
|
|
const SilentTypingToggle: ChatBarButton = ({ isMainChat }) => {
|
2024-02-06 10:29:47 -05:00
|
|
|
const { isEnabled, showIcon } = settings.use(["isEnabled", "showIcon"]);
|
2023-01-14 12:47:12 -05:00
|
|
|
const toggle = () => settings.store.isEnabled = !settings.store.isEnabled;
|
|
|
|
|
2024-02-06 10:29:47 -05:00
|
|
|
if (!isMainChat || !showIcon) return null;
|
2023-03-28 12:56:12 -04:00
|
|
|
|
2023-01-14 12:47:12 -05:00
|
|
|
return (
|
2024-02-06 10:29:47 -05:00
|
|
|
<ChatBarButton
|
|
|
|
tooltip={isEnabled ? "Disable Silent Typing" : "Enable Silent Typing"}
|
|
|
|
onClick={toggle}
|
|
|
|
>
|
|
|
|
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
|
|
|
|
<path fill="currentColor" d="M528 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h480c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM128 180v-40c0-6.627-5.373-12-12-12H76c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm-336 96v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm-336 96v-40c0-6.627-5.373-12-12-12H76c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm288 0v-40c0-6.627-5.373-12-12-12H172c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h232c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12z" />
|
|
|
|
{isEnabled && <path d="M13 432L590 48" stroke="var(--red-500)" stroke-width="72" stroke-linecap="round" />}
|
|
|
|
</svg>
|
|
|
|
</ChatBarButton>
|
2023-01-14 12:47:12 -05:00
|
|
|
);
|
2024-02-06 10:29:47 -05:00
|
|
|
};
|
2023-01-14 12:47:12 -05:00
|
|
|
|
2024-05-11 16:49:00 -04:00
|
|
|
|
|
|
|
const ChatBarContextCheckbox: NavContextMenuPatchCallback = children => {
|
|
|
|
const { isEnabled, contextMenu } = settings.use(["isEnabled", "contextMenu"]);
|
|
|
|
if (!contextMenu) return;
|
|
|
|
|
|
|
|
const group = findGroupChildrenByChildId("submit-button", children);
|
|
|
|
|
|
|
|
if (!group) return;
|
|
|
|
|
|
|
|
const idx = group.findIndex(c => c?.props?.id === "submit-button");
|
|
|
|
|
|
|
|
group.splice(idx + 1, 0,
|
|
|
|
<Menu.MenuCheckboxItem
|
|
|
|
id="vc-silent-typing"
|
|
|
|
label="Enable Silent Typing"
|
|
|
|
checked={isEnabled}
|
|
|
|
action={() => settings.store.isEnabled = !settings.store.isEnabled}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-01-14 12:47:12 -05:00
|
|
|
export default definePlugin({
|
|
|
|
name: "SilentTyping",
|
2024-05-11 16:49:00 -04:00
|
|
|
authors: [Devs.Ven, Devs.Rini, Devs.ImBanana],
|
2023-01-14 12:47:12 -05:00
|
|
|
description: "Hide that you are typing",
|
2024-02-06 10:29:47 -05:00
|
|
|
dependencies: ["CommandsAPI", "ChatInputButtonAPI"],
|
|
|
|
settings,
|
2024-05-11 16:49:00 -04:00
|
|
|
contextMenus: {
|
|
|
|
"textarea-context": ChatBarContextCheckbox
|
|
|
|
},
|
2023-01-14 12:47:12 -05:00
|
|
|
patches: [
|
|
|
|
{
|
2023-10-25 11:34:23 -04:00
|
|
|
find: '.dispatch({type:"TYPING_START_LOCAL"',
|
2023-01-14 12:47:12 -05:00
|
|
|
replacement: {
|
2023-10-25 11:34:23 -04:00
|
|
|
match: /startTyping\(\i\){.+?},stop/,
|
2023-01-14 12:47:12 -05:00
|
|
|
replace: "startTyping:$self.startTyping,stop"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
],
|
2024-02-06 10:29:47 -05:00
|
|
|
|
2023-01-14 12:47:12 -05:00
|
|
|
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 });
|
|
|
|
},
|
|
|
|
|
2024-02-06 10:29:47 -05:00
|
|
|
start: () => addChatBarButton("SilentTyping", SilentTypingToggle),
|
|
|
|
stop: () => removeChatBarButton("SilentTyping"),
|
2023-01-14 12:47:12 -05:00
|
|
|
});
|