Plugin

FavoriteEmojiFirst

Puts your favorite emoji first in the emoji autocomplete.

Emotes Customisation
index.ts
Download

Source

src/plugins/favEmojiFirst/index.ts
1/*
2 * FiveCord — a Discord client mod
3 * Copyright (c) 2025 FiveCord
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7import { Devs } from "@utils/constants";
8import definePlugin from "@utils/types";
9import { Emoji } from "@vencord/discord-types";
10import { EmojiStore } from "@webpack/common";
11
12interface EmojiAutocompleteState {
13 query?: {
14 type: string;
15 typeInfo: {
16 sentinel: string;
17 };
18 results: {
19 emojis: Emoji[] & { sliceTo?: number; };
20 };
21 };
22}
23
24export default definePlugin({
25 name: "FavoriteEmojiFirst",
26 authors: [Devs.Aria, Devs.Ven],
27 description: "Puts your favorite emoji first in the emoji autocomplete.",
28 tags: ["Emotes", "Customisation"],
29 patches: [
30 {
31 find: "renderResults({results:",
32 replacement: [
33 {
34 // https://regex101.com/r/N7kpLM/1
35 match: /let \i=.{1,100}renderResults\({results:(\i)\.query\.results,/,
36 replace: "$self.sortEmojis($1);$&"
37 },
38 ],
39 },
40
41 {
42 find: "numEmojiResults:",
43 replacement: [
44 // set maxCount to Infinity so our sortEmojis callback gets the entire list, not just the first 10
45 // and remove Discord's emojiResult slice, storing the endIndex on the array for us to use later
46 {
47 // https://regex101.com/r/x2mobQ/1
48 // searchEmojis(...,maxCount: stuff) ... endEmojis = emojis.slice(0, maxCount - gifResults.length)
49 match: /,maxCount:(\i)(.{1,500}\i)=(\i)\.slice\(0,(Math\.max\(\d+?,\i(?:-\i\.length){2}\))\)/,
50 // ,maxCount:Infinity ... endEmojis = (emojis.sliceTo = n, emojis)
51 replace: ",maxCount:Infinity$2=($3.sliceTo = $4, $3)"
52 }
53 ]
54 }
55 ],
56
57 sortEmojis({ query }: EmojiAutocompleteState) {
58 if (
59 query?.type !== "EMOJIS_AND_STICKERS"
60 || query.typeInfo?.sentinel !== ":"
61 || !query.results?.emojis?.length
62 ) return;
63
64 const emojiContext = EmojiStore.getDisambiguatedEmojiContext();
65
66 query.results.emojis = query.results.emojis.sort((a, b) => {
67 const aIsFavorite = emojiContext.isFavoriteEmojiWithoutFetchingLatest(a);
68 const bIsFavorite = emojiContext.isFavoriteEmojiWithoutFetchingLatest(b);
69
70 if (aIsFavorite && !bIsFavorite) return -1;
71
72 if (!aIsFavorite && bIsFavorite) return 1;
73
74 return 0;
75 }).slice(0, query.results.emojis.sliceTo ?? Infinity);
76 }
77});
78