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): CopyStickerLinks #3191

Open
wants to merge 31 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
eeb5a61
init new thing
byeoon Dec 20, 2024
17faeb0
basically emote clone but not really
byeoon Jan 30, 2025
2671ed1
Merge branch 'Vendicated:main' into stickercopy
byeoon Jan 30, 2025
dc0aef3
feat(plugin): organized plugin more, added button that WORKS!
byeoon Jan 30, 2025
2c47b13
Actually works now, nice.
byeoon Jan 31, 2025
4175e46
hotfix: lowered resolution it can be 2k doesnt have to be 4k, takes u…
byeoon Jan 31, 2025
e04032e
Merge branch 'dev' into stickercopy
byeoon Jan 31, 2025
eeb8750
fix things as needed
byeoon Jan 31, 2025
3da8759
fix quotes
byeoon Jan 31, 2025
ed308e0
hotfix: update button name
byeoon Jan 31, 2025
ddb504a
Merge branch 'dev' into stickercopy
byeoon Jan 31, 2025
830129a
test
byeoon Jan 31, 2025
5662688
fix for the third time
byeoon Jan 31, 2025
2ecea2e
Merge branch 'dev' into stickercopy
byeoon Feb 2, 2025
52ff906
MessageDecorationsAPI: Fix bad vertical alignment
Nuckyz Feb 3, 2025
fede0e4
Merge branch 'dev' into stickercopy
byeoon Feb 3, 2025
b96d8d0
i hate force merging
byeoon Feb 5, 2025
1df4c4d
fix animated gifs i hope
byeoon Feb 5, 2025
6020e93
oopsie daisy
byeoon Feb 5, 2025
1302a1c
remove unneccesary type
byeoon Feb 5, 2025
113bd7c
Update src/plugins/copyStickerLinks/index.tsx
byeoon Feb 5, 2025
06bf35d
clean up my shitcode
byeoon Feb 5, 2025
bb3f8bd
Merge branch 'dev' into stickercopy
byeoon Feb 5, 2025
8ffd49d
Merge branch 'dev' into stickercopy
byeoon Feb 7, 2025
0f61bca
revert changes that broke the code
byeoon Feb 7, 2025
9454496
Merge branch 'stickercopy' of https://github.com/byeoon/byoncord into…
byeoon Feb 7, 2025
1195f99
fix: clean up unused / unneccesary code
byeoon Feb 7, 2025
e7b7ab7
switch to copyWithToast instead of showing toast + copying
byeoon Feb 7, 2025
961a14a
Merge branch 'dev' into stickercopy
byeoon Feb 7, 2025
a874555
Merge branch 'dev' into stickercopy
byeoon Feb 8, 2025
08c4d6f
remove a single period
byeoon Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/plugins/_api/messageDecorations/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@

/* Align vertically */
position: relative;
top: 0.2rem;
byeoon marked this conversation as resolved.
Show resolved Hide resolved
vertical-align: top;
top: 0.05rem;
height: 100%;
max-height: calc(1rem + 4px)
}
139 changes: 139 additions & 0 deletions src/plugins/copyStickerLinks/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2024 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/>.
*/

import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findStoreLazy } from "@webpack";
import { Clipboard, Constants, FluxDispatcher, Menu, React, RestAPI, Toasts } from "@webpack/common";
import { Promisable } from "type-fest";

const StickersStore = findStoreLazy("StickersStore");

interface Sticker {
t: "Sticker";
description: string;
format_type: number;
guild_id: string;
id: string;
name: string;
tags: string;
type: number;
}

type Data = Sticker;

const StickerExt = [, "png", "png", "json", "gif"] as const;

function getUrl(data: Data) {
if (data.format_type === 1 || data.format_type === 3)
return `https:${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.${StickerExt[data.format_type]}?size=4096&lossless=true`;

return `https://cdn.discordapp.com/stickers/${data.id}.${StickerExt[data.format_type]}?size=4096&lossless=true`;
}
byeoon marked this conversation as resolved.
Show resolved Hide resolved

async function fetchSticker(id: string) {
byeoon marked this conversation as resolved.
Show resolved Hide resolved
const cached = StickersStore.getStickerById(id);
if (cached) return cached;

const { body } = await RestAPI.get({
url: Constants.Endpoints.STICKER(id)
});

FluxDispatcher.dispatch({
type: "STICKER_FETCH_SUCCESS",
sticker: body
});

return body as Sticker;
}

function buildMenuItem(type: "Sticker", fetchData: () => Promisable<Omit<Sticker, "t">>) {
byeoon marked this conversation as resolved.
Show resolved Hide resolved
byeoon marked this conversation as resolved.
Show resolved Hide resolved
return (
<>
<Menu.MenuSeparator></Menu.MenuSeparator>

<Menu.MenuItem
id="copystickerurl"
key="copystickerurl"
label={"Copy URL"}
action={async () => {
const res = await fetchData();
const data = { t: type, ...res } as Sticker;
const url = getUrl(data);
Toasts.show({
message: "Link to sticker copied!",
type: Toasts.Type.SUCCESS,
id: Toasts.genId()
});
Clipboard.copy(url);
}
}
/>

<Menu.MenuItem
id="openstickerlink"
key="openstickerlink"
label={"Open URL"}
action={async () => {
const res = await fetchData();
const data = { t: type, ...res } as Sticker;
const url = getUrl(data);
VencordNative.native.openExternal(url);
}
}
/>
</>
);
}

const messageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => {
const { favoriteableId, favoriteableType } = props ?? {};
if (!favoriteableId) return;
const menuItem = (() => {
switch (favoriteableType) {
case "sticker":
const sticker = props.message.stickerItems.find(s => s.id === favoriteableId);
if (sticker?.format_type === 3) return;

return buildMenuItem("Sticker", () => fetchSticker(favoriteableId));
}
})();

if (menuItem)
findGroupChildrenByChildId("devmode-copy-id", children, true)?.push(menuItem);
byeoon marked this conversation as resolved.
Show resolved Hide resolved
};

const expressionPickerPatch: NavContextMenuPatchCallback = (children, props: { target: HTMLElement; }) => {
const { id, type } = props?.target?.dataset ?? {};
if (!id) return;

if (type === "sticker" && !props.target.className?.includes("lottieCanvas")) {
children.push(buildMenuItem("Sticker", () => fetchSticker(id)));
}
};

export default definePlugin({
name: "CopyStickerLinks",
description: "Adds the ability to copy and open sticker links to your browser.",
authors: [Devs.Byeoon],
contextMenus: {
"message": messageContextMenuPatch,
"expression-picker": expressionPickerPatch
}
});
2 changes: 1 addition & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "Sqaaakoi",
id: 259558259491340288n
},
Byron: {
Byeoon: {
name: "byeoon",
id: 1167275288036655133n
},
Expand Down