Plugin

FavoriteEmojiFirst

Puts your favorite emoji first in the emoji autocomplete.

Emotes Customisation
index.ts
Download

Source

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