Plugin
SilentTyping
Hide that you are typing
1
/*2
* FiveCord — a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import { ChatBarButton, ChatBarButtonFactory } from "@api/ChatButtons";8
import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands";9
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";10
import { definePluginSettings } from "@api/Settings";11
import { Devs } from "@utils/constants";12
import definePlugin, { IconComponent, OptionType } from "@utils/types";13
import { FluxDispatcher, Menu, React } from "@webpack/common";14
15
const settings = definePluginSettings({16
showIcon: {17
type: OptionType.BOOLEAN,18
default: false,19
description: "Show an icon for toggling the plugin",20
restartNeeded: true,21
},22
contextMenu: {23
type: OptionType.BOOLEAN,24
description: "Add option to toggle the functionality in the chat input context menu",25
default: true26
},27
isEnabled: {28
type: OptionType.BOOLEAN,29
description: "Toggle functionality",30
default: true,31
}32
});33
34
function SilentTypingEnabledIcon() {35
return (36
<SilentTypingIcon>37
<mask id="silent-typing-msg-mask">38
<path fill="#fff" d="M0 0h24v24H0Z"></path>39
<path stroke="#000" strokeWidth="5.99068" d="M0 24 24 0" transform="translate(-2, -3)"></path>40
</mask>41
<path fill="var(--status-danger)" d="m21.178 1.70703 1.414 1.414L4.12103 21.593l-1.414-1.415L21.178 1.70703Z" />42
</SilentTypingIcon>43
);44
}45
46
const SilentTypingIcon: IconComponent = ({ height = 20, width = 20, className, children }) => {47
return (48
<svg49
width={width}50
height={height}51
className={className}52
viewBox="0 0 24 24"53
style={{ scale: "1.2" }}54
>55
<path fill="currentColor" mask="url(#silent-typing-msg-mask)" d="M18.333 15.556H1.667a1.667 1.667 0 0 1 -1.667 -1.667v-10a1.667 1.667 0 0 1 1.667 -1.667h16.667a1.667 1.667 0 0 1 1.667 1.667v10a1.667 1.667 0 0 1 -1.667 1.667M4.444 6.25V4.861a0.417 0.417 0 0 0 -0.417 -0.417H2.639a0.417 0.417 0 0 0 -0.417 0.417V6.25a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m3.333 0V4.861a0.417 0.417 0 0 0 -0.417 -0.417H5.973a0.417 0.417 0 0 0 -0.417 0.417V6.25a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m3.333 0V4.861a0.417 0.417 0 0 0 -0.417 -0.417h-1.389a0.417 0.417 0 0 0 -0.417 0.417V6.25a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m3.333 0V4.861a0.417 0.417 0 0 0 -0.417 -0.417h-1.389a0.417 0.417 0 0 0 -0.417 0.417V6.25a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m3.333 0V4.861a0.417 0.417 0 0 0 -0.417 -0.417h-1.389a0.417 0.417 0 0 0 -0.417 0.417V6.25a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m-11.667 3.333V8.194a0.417 0.417 0 0 0 -0.417 -0.417H4.306a0.417 0.417 0 0 0 -0.417 0.417V9.583a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m3.333 0V8.194a0.417 0.417 0 0 0 -0.417 -0.417H7.639a0.417 0.417 0 0 0 -0.417 0.417V9.583a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m3.333 0V8.194a0.417 0.417 0 0 0 -0.417 -0.417h-1.389a0.417 0.417 0 0 0 -0.417 0.417V9.583a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m3.333 0V8.194a0.417 0.417 0 0 0 -0.417 -0.417h-1.389a0.417 0.417 0 0 0 -0.417 0.417V9.583a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m-11.667 3.333v-1.389a0.417 0.417 0 0 0 -0.417 -0.417H2.639a0.417 0.417 0 0 0 -0.417 0.417V12.917a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417m10 0v-1.389a0.417 0.417 0 0 0 -0.417 -0.417H5.973a0.417 0.417 0 0 0 -0.417 0.417V12.917a0.417 0.417 0 0 0 0.417 0.417h8.056a0.417 0.417 0 0 0 0.417 -0.417m3.333 0v-1.389a0.417 0.417 0 0 0 -0.417 -0.417h-1.389a0.417 0.417 0 0 0 -0.417 0.417V12.917a0.417 0.417 0 0 0 0.417 0.417h1.389a0.417 0.417 0 0 0 0.417 -0.417" transform="translate(2, 3)" />56
{children}57
</svg>58
);59
};60
61
const SilentTypingToggle: ChatBarButtonFactory = ({ isMainChat }) => {62
const { isEnabled, showIcon } = settings.use(["isEnabled", "showIcon"]);63
const toggle = () => settings.store.isEnabled = !settings.store.isEnabled;64
65
if (!isMainChat || !showIcon) return null;66
67
return (68
<ChatBarButton69
tooltip={isEnabled ? "Disable Silent Typing" : "Enable Silent Typing"}70
onClick={toggle}71
>72
{isEnabled ? <SilentTypingEnabledIcon /> : <SilentTypingIcon />}73
</ChatBarButton>74
);75
};76
77
78
const ChatBarContextCheckbox: NavContextMenuPatchCallback = children => {79
const { isEnabled, contextMenu } = settings.use(["isEnabled", "contextMenu"]);80
if (!contextMenu) return;81
82
const group = findGroupChildrenByChildId("submit-button", children);83
84
if (!group) return;85
86
const idx = group.findIndex(c => c?.props?.id === "submit-button");87
88
group.splice(idx + 1, 0,89
<Menu.MenuCheckboxItem90
id="vc-silent-typing"91
label="Enable Silent Typing"92
checked={isEnabled}93
action={() => settings.store.isEnabled = !settings.store.isEnabled}94
/>95
);96
};97
98
99
export default definePlugin({100
name: "SilentTyping",101
authors: [Devs.Ven, Devs.Rini, Devs.ImBanana],102
description: "Hide that you are typing",103
tags: ["Chat", "Privacy"],104
settings,105
106
contextMenus: {107
"textarea-context": ChatBarContextCheckbox108
},109
110
patches: [111
{112
find: 039;.dispatch({type:"TYPING_START_LOCAL"039;,113
replacement: {114
match: /startTyping\(\i\){.+?},stop/,115
replace: "startTyping:$self.startTyping,stop"116
}117
},118
],119
120
commands: [{121
name: "silenttype",122
description: "Toggle whether you039;re hiding that you039;re typing or not.",123
inputType: ApplicationCommandInputType.BUILT_IN,124
options: [125
{126
name: "value",127
description: "Whether to hide or not that you039;re typing (default is toggle)",128
required: false,129
type: ApplicationCommandOptionType.BOOLEAN,130
},131
],132
execute: async (args, ctx) => {133
settings.store.isEnabled = !!findOption(args, "value", !settings.store.isEnabled);134
sendBotMessage(ctx.channel.id, {135
content: settings.store.isEnabled ? "Silent typing enabled!" : "Silent typing disabled!",136
});137
},138
}],139
140
async startTyping(channelId: string) {141
if (settings.store.isEnabled) return;142
FluxDispatcher.dispatch({ type: "TYPING_START_LOCAL", channelId });143
},144
145
chatBarButton: {146
icon: SilentTypingIcon,147
render: SilentTypingToggle148
}149
});150