feat(plugin): Signature (#99)

* add signature plugin

* fix lint?

---------

Co-authored-by: thororen1234 <thororen1234@users.noreply.github.com>
This commit is contained in:
KrystalSkull 2024-11-20 17:17:29 -05:00 committed by GitHub
parent ce6d090e73
commit 026befec32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 151 additions and 0 deletions

View file

@ -121,6 +121,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
- SekaiStickers by MaiKokain
- ServerSearch by camila314
- ShowBadgesInChat by Inbestigator & KrystalSkull
- Signature by KrystalSkull
- SidebarChat by Joona
- Slap by Korbo
- SoundBoardLogger by Moxxie, fres, echo, maintained by thororen

View file

@ -0,0 +1,150 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { addChatBarButton, ChatBarButton, removeChatBarButton } from "@api/ChatButtons";
import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands";
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
import { MessageEvents } from "@api/index";
import { definePluginSettings, migratePluginSettings } from "@api/Settings";
import { EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { Menu, React } from "@webpack/common";
// Big thank you too slientTyping
const settings = definePluginSettings(
{
name: {
type: OptionType.STRING,
description: "The signature that will be added to the end of your messages",
default: "a chronic discord user"
},
showIcon: {
type: OptionType.BOOLEAN,
default: true,
description: "Show an icon for toggling the plugin in the chat bar",
restartNeeded: true,
},
contextMenu: {
type: OptionType.BOOLEAN,
description: "Add option to toggle the functionality in the chat input context menu",
default: true
},
isEnabled: {
type: OptionType.BOOLEAN,
description: "Toggle functionality",
default: true,
},
});
const SignatureToggle: ChatBarButton = ({ isMainChat }) => {
const { isEnabled, showIcon } = settings.use(["isEnabled", "showIcon"]);
const toggle = () => settings.store.isEnabled = !settings.store.isEnabled;
if (!isMainChat || !showIcon) return null;
return (
<ChatBarButton
tooltip={isEnabled ? "Disable Signature" : "Enable Signature"}
onClick={toggle}
>
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 21.333">
<path fill="currentColor" mask="url(#signature-msg-mask)" d="M2 4.621a.5.5 0 0 1 .854-.353l6.01 6.01c.126.126.17.31.15.487a2 2 0 1 0 1.751-1.751a.59.59 0 0 1-.487-.15l-6.01-6.01A.5.5 0 0 1 4.62 2H11a9 9 0 0 1 8.468 12.054l2.24 2.239a1 1 0 0 1 0 1.414l-4 4a1 1 0 0 1-1.415 0l-2.239-2.239A9 9 0 0 1 2 11z" />
{isEnabled && (
<>
<mask id="signature-msg-mask"> <path fill="#fff" d="M0 0h24v24H0Z"></path>
<path stroke="#000" strokeWidth="5.99068" d="M0 24 24 0"></path> </mask>
<path fill="var(--status-danger)" d="m21.178 1.70703 1.414 1.414L4.12103 21.593l-1.414-1.415L21.178 1.70703Z" />
</>
)}
</svg>
</ChatBarButton>
);
};
// Big thank you @thororen (discord) who helped me write this const
const handleMessage = ((channelId, msg) => { if (!settings.store.isEnabled) return ""; return msg.content = textProcessing(msg.content); });
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-Signature"
label="Enable Signature"
checked={isEnabled}
action={() => settings.store.isEnabled = !settings.store.isEnabled}
/>
);
};
// This is usless for the normal user but is helpful for development since I decided to rework to plugin
migratePluginSettings("Signature", "SentVia");
export default definePlugin({
name: "Signature",
description: "Automated fingerprint/end text",
authors: [
EquicordDevs.KrystalSkull
],
dependencies: ["MessageEventsAPI", "ChatInputButtonAPI"],
start: () => {
if (settings.store.isEnabled) true;
addChatBarButton("Signature", SignatureToggle);
// @ts-ignore
MessageEvents.addPreSendListener(handleMessage);
},
stop: () => {
if (settings.store.isEnabled) false;
removeChatBarButton("Signature");
// @ts-ignore
MessageEvents.removePreSendListener(handleMessage);
},
settings,
contextMenus: {
"textarea-context": ChatBarContextCheckbox
},
commands: [{
name: "Signature",
description: "Toggle your signature",
inputType: ApplicationCommandInputType.BUILT_IN,
options: [
{
name: "value",
description: "Toggle your signature (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 ? "Signature enabled!" : "Signature disabled!",
});
},
}],
});
// text processing injection processor
function textProcessing(input: string) {
return `${input}\n> ${settings.store.name}`;
}