Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): Add BetterGifSend #2850

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
21 changes: 21 additions & 0 deletions src/plugins/betterGifSend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# BetterGifSend

This plugin adds configuration options regarding the GIF picker visibility/send behavior

## Configuration Options

### GIF picker visibility after selection

- Close after sending (Default)
- Always open
- Stay open with SHIFT

### GIF selection behavior

- Send immediately (Default)
- Insert into chatbox (also known as GifPaste)
- Insert into chatbox with SHIFT

### Clear Reply Context (Toggle, Enabled by default)

- Clears the reply context after selecting a single GIF
102 changes: 102 additions & 0 deletions src/plugins/betterGifSend/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import { insertTextIntoChatInputBox } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { ExpressionPickerStore, FluxDispatcher, MessageActions, SelectedChannelStore } from "@webpack/common";

interface Gif {
url: string;
}

const settings = definePluginSettings({
closeBehavior: {
type: OptionType.SELECT,
default: "Close",
description: "Choose how the GIF Picker behaves after clicking a GIF",
restartNeeded: false,
options: [
{ value: "Close", label: "Close immediately" },
{ value: "Open", label: "Always keep open" },
{ value: "ShiftOpen", label: "Keep open if SHIFT is held" }
]
},
sendBehavior: {
type: OptionType.SELECT,
default: "Send",
description: "Choose how GIF selection is handled",
restartNeeded: false,
options: [
{ value: "Send", label: "Send immediately" },
{ value: "Insert", label: "Insert into chatbox (GifPaste behavior)" },
{ value: "InsertWithShift", label: "Insert link if SHIFT is held" }
]
},
clearReply: {
type: OptionType.BOOLEAN,
default: true,
description: "Clear the reply context after sending a singular GIF",
restartNeeded: false
}
});

const PendingReplyStore = findByPropsLazy("getPendingReply");

let shiftHeld = false;

function handleShift(event: KeyboardEvent): void {
if (event.key === "Shift") {
shiftHeld = event.type === "keydown";
}
}

export default definePlugin({
name: "BetterGifSend",
description: "Change GIF picker visibility and send (paste/insert) behavior",
authors: [Devs.Ven, Devs.rya, Devs.iilwy],
patches: [{
find: '"handleSelectGIF",',
replacement: {
match: /"handleSelectGIF",(\i)=>\{/,
replace: '"handleSelectGIF",$1=>{if (!this.props.className) return $self.handleSelect($1);'
}
}],

start(): void {
document.addEventListener("keydown", handleShift);
document.addEventListener("keyup", handleShift);
},

stop(): void {
document.removeEventListener("keydown", handleShift);
document.removeEventListener("keyup", handleShift);
},

handleSelect(gif?: Gif): void {
if (!gif) return;

const channel = SelectedChannelStore.getChannelId();
const { sendBehavior, closeBehavior } = settings.store;

if (sendBehavior === "Insert" || (sendBehavior === "InsertWithShift" && shiftHeld)) {
insertTextIntoChatInputBox(gif.url + " ");
} else {
const reply = PendingReplyStore.getPendingReply(channel);
MessageActions.sendMessage(channel, { content: gif.url }, void 0, true, MessageActions.getSendMessageOptionsForReply(reply));
if (settings.store.clearReply && reply) {
FluxDispatcher.dispatch({ type: "DELETE_PENDING_REPLY", channelId: channel });
}
}

if (closeBehavior === "Close" || (closeBehavior === "ShiftOpen" && !shiftHeld)) {
ExpressionPickerStore.closeExpressionPicker();
}
},
settings
});
43 changes: 0 additions & 43 deletions src/plugins/gifPaste/index.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,14 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "RamziAH",
id: 1279957227612147747n,
},
rya: {
name: "ryanamay",
id: 1262793452236570667n
},
iilwy: {
name: "iminlikewithyou",
id: 971202946895339550n
},
} satisfies Record<string, Dev>);

// iife so #__PURE__ works correctly
Expand Down