From 0ac80ce9d180bbdaf4d3863f4a249f3b165072df Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sun, 1 Dec 2024 00:10:08 -0300 Subject: [PATCH 1/6] MessagePopoverAPI: Add buttons after quick reactions --- src/plugins/_api/messagePopover.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/plugins/_api/messagePopover.ts b/src/plugins/_api/messagePopover.ts index 21e5accde..0133d0c64 100644 --- a/src/plugins/_api/messagePopover.ts +++ b/src/plugins/_api/messagePopover.ts @@ -23,11 +23,14 @@ export default definePlugin({ name: "MessagePopoverAPI", description: "API to add buttons to message popovers.", authors: [Devs.KingFish, Devs.Ven, Devs.Nuckyz], - patches: [{ - find: "#{intl::MESSAGE_UTILITIES_A11Y_LABEL}", - replacement: { - match: /\.jsx\)\((\i\.\i),\{label:\i\.\i\.string\(\i\.\i#{intl::MESSAGE_ACTION_REPLY}.{0,200}?"reply-self".{0,50}?\}\):null(?=,.+?message:(\i))/, - replace: "$&,Vencord.Api.MessagePopover._buildPopoverElements($1,$2)" + patches: [ + { + find: "#{intl::MESSAGE_UTILITIES_A11Y_LABEL}", + replacement: { + match: /(?<=:null),(.{0,40}togglePopout:.+?}\))\]}\):null,(?<=\((\i\.\i),{label:.+?:null,(\i&&!\i)\?\(0,\i\.jsxs?\)\(\i\.Fragment.+?message:(\i).+?)/, + replace: (_, ReactButton, ButtonComponent, showReactButton, message) => "" + + `]}):null,Vencord.Api.MessagePopover._buildPopoverElements(${ButtonComponent},${message}),${showReactButton}?${ReactButton}:null,` + } } - }], + ] }); From d70e0f27dcdaca24443d57b319fee2c0a8997501 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Mon, 2 Dec 2024 20:39:54 -0300 Subject: [PATCH 2/6] ServerListIndicators: Account for pending clans count --- src/plugins/serverListIndicators/index.tsx | 63 +++++++++------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/src/plugins/serverListIndicators/index.tsx b/src/plugins/serverListIndicators/index.tsx index 96833d8f3..7648bc2d0 100644 --- a/src/plugins/serverListIndicators/index.tsx +++ b/src/plugins/serverListIndicators/index.tsx @@ -20,9 +20,9 @@ import { addServerListElement, removeServerListElement, ServerListRenderPosition import { Settings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; -import { useForceUpdater } from "@utils/react"; import definePlugin, { OptionType } from "@utils/types"; -import { GuildStore, PresenceStore, RelationshipStore } from "@webpack/common"; +import { findStoreLazy } from "@webpack"; +import { GuildStore, PresenceStore, RelationshipStore, useStateFromStores } from "@webpack/common"; const enum IndicatorType { SERVER = 1 << 0, @@ -30,13 +30,24 @@ const enum IndicatorType { BOTH = SERVER | FRIEND, } -let onlineFriends = 0; -let guildCount = 0; -let forceUpdateFriendCount: () => void; -let forceUpdateGuildCount: () => void; +const UserGuildJoinRequestStore = findStoreLazy("UserGuildJoinRequestStore"); function FriendsIndicator() { - forceUpdateFriendCount = useForceUpdater(); + const onlineFriendsCount = useStateFromStores([RelationshipStore, PresenceStore], () => { + let count = 0; + + const friendIds = RelationshipStore.getFriendIDs(); + for (const id of friendIds) { + const status = PresenceStore.getStatus(id) ?? "offline"; + if (status === "offline") { + continue; + } + + count++; + } + + return count; + }); return ( - {onlineFriends} online + {onlineFriendsCount} online ); } function ServersIndicator() { - forceUpdateGuildCount = useForceUpdater(); + const guildCount = useStateFromStores([GuildStore, UserGuildJoinRequestStore], () => { + const guildJoinRequests: string[] = UserGuildJoinRequestStore.computeGuildIds(); + const guilds = GuildStore.getGuilds(); + + // Filter only pending guild join requests + return GuildStore.getGuildCount() + guildJoinRequests.filter(id => guilds[id] == null).length; + }); return ( ; }, - flux: { - PRESENCE_UPDATES: handlePresenceUpdate, - GUILD_CREATE: handleGuildUpdate, - GUILD_DELETE: handleGuildUpdate, - }, - - start() { addServerListElement(ServerListRenderPosition.Above, this.renderIndicator); - - handlePresenceUpdate(); - handleGuildUpdate(); }, stop() { From 3f61fe722dfa92b467c907b14237767877ef6ed1 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:51:29 -0300 Subject: [PATCH 3/6] AlwaysTrust: Fix disabling suspicious file popup --- src/plugins/alwaysTrust/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/alwaysTrust/index.ts b/src/plugins/alwaysTrust/index.ts index 7484a619c..0c89ae116 100644 --- a/src/plugins/alwaysTrust/index.ts +++ b/src/plugins/alwaysTrust/index.ts @@ -51,7 +51,7 @@ export default definePlugin({ { find: "bitbucket.org", replacement: { - match: /function \i\(\i\){(?=.{0,60}\.parse\(\i\))/, + match: /function \i\(\i\){(?=.{0,30}pathname:\i)/, replace: "$&return null;" }, predicate: () => settings.store.file From dd87f360d74f61b4532b523dc47cd734b6ffeb05 Mon Sep 17 00:00:00 2001 From: Etorix <92535668+EtorixDev@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:13:27 -0800 Subject: [PATCH 4/6] CommandsAPI: Fix spread overwriting omitted subcommand options (#3057) --- src/api/Commands/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/Commands/index.ts b/src/api/Commands/index.ts index e5803ba02..2b7a4de6c 100644 --- a/src/api/Commands/index.ts +++ b/src/api/Commands/index.ts @@ -110,6 +110,7 @@ function registerSubCommands(cmd: Command, plugin: string) { const subCmd = { ...cmd, ...o, + options: o.options !== undefined ? o.options : undefined, type: ApplicationCommandType.CHAT_INPUT, name: `${cmd.name} ${o.name}`, id: `${o.name}-${cmd.id}`, From 66286240820c132a8aa98bcaa2e9c7c2535ca403 Mon Sep 17 00:00:00 2001 From: Etorix <92535668+EtorixDev@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:16:13 -0800 Subject: [PATCH 5/6] CommandHelpers: Make findOption use nullish coalescing (#3047) --- src/api/Commands/commandHelpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/Commands/commandHelpers.ts b/src/api/Commands/commandHelpers.ts index 4ae022c59..ac1dafc98 100644 --- a/src/api/Commands/commandHelpers.ts +++ b/src/api/Commands/commandHelpers.ts @@ -54,5 +54,5 @@ export function sendBotMessage(channelId: string, message: PartialDeep) export function findOption(args: Argument[], name: string): T & {} | undefined; export function findOption(args: Argument[], name: string, fallbackValue: T): T & {}; export function findOption(args: Argument[], name: string, fallbackValue?: any) { - return (args.find(a => a.name === name)?.value || fallbackValue) as any; + return (args.find(a => a.name === name)?.value ?? fallbackValue) as any; } From df454ca95218dc32ef1521e5836f38c76bb24a61 Mon Sep 17 00:00:00 2001 From: Sqaaakoi Date: Tue, 3 Dec 2024 13:30:56 +1100 Subject: [PATCH 6/6] MutualGroupDMs: Fix in DM sidebar when no mutual friends/servers (#2976) --- src/plugins/mutualGroupDMs/index.tsx | 52 +++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/plugins/mutualGroupDMs/index.tsx b/src/plugins/mutualGroupDMs/index.tsx index a4f690af1..080a79891 100644 --- a/src/plugins/mutualGroupDMs/index.tsx +++ b/src/plugins/mutualGroupDMs/index.tsx @@ -19,6 +19,7 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import { isNonNullish } from "@utils/guards"; +import { Logger } from "@utils/Logger"; import definePlugin from "@utils/types"; import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; import { Avatar, ChannelStore, Clickable, IconUtils, RelationshipStore, ScrollerThin, useMemo, UserStore } from "@webpack/common"; @@ -87,7 +88,7 @@ export default definePlugin({ replacement: [ { match: /\i\.useEffect.{0,100}(\i)\[0\]\.section/, - replace: "$self.pushSection($1, arguments[0].user);$&" + replace: "$self.pushSection($1,arguments[0].user);$&" }, { match: /\(0,\i\.jsx\)\(\i,\{items:\i,section:(\i)/, @@ -97,26 +98,46 @@ export default definePlugin({ }, { find: 'section:"MUTUAL_FRIENDS"', - replacement: { - match: /\.openUserProfileModal.+?\)}\)}\)(?<=(\(0,\i\.jsxs?\)\(\i\.\i,{className:(\i)\.divider}\)).+?)/, - replace: "$&,$self.renderDMPageList({user: arguments[0].user, Divider: $1, listStyle: $2.list})" - } + replacement: [ + { + match: /\i\|\|\i(?=\?\(0,\i\.jsxs?\)\(\i\.\i\.Overlay,)/, + replace: "$&||$self.getMutualGroupDms(arguments[0].user.id).length>0" + }, + { + match: /\.openUserProfileModal.+?\)}\)}\)(?<=,(\i)&&(\i)&&(\(0,\i\.jsxs?\)\(\i\.\i,{className:(\i)\.divider}\)).+?)/, + replace: (m, hasMutualGuilds, hasMutualFriends, Divider, classes) => "" + + `${m},$self.renderDMPageList({user:arguments[0].user,hasDivider:${hasMutualGuilds}||${hasMutualFriends},Divider:${Divider},listStyle:${classes}.list})` + } + ] } ], - pushSection(sections: any[], user: User) { - if (isBotOrSelf(user) || sections[IS_PATCHED]) return; + getMutualGroupDms(userId: string) { + try { + return getMutualGroupDms(userId); + } catch (e) { + new Logger("MutualGroupDMs").error("Failed to get mutual group dms:", e); + } - sections[IS_PATCHED] = true; - sections.push({ - section: "MUTUAL_GDMS", - text: getMutualGDMCountText(user) - }); + return []; + }, + + pushSection(sections: any[], user: User) { + try { + if (isBotOrSelf(user) || sections[IS_PATCHED]) return; + + sections[IS_PATCHED] = true; + sections.push({ + section: "MUTUAL_GDMS", + text: getMutualGDMCountText(user) + }); + } catch (e) { + new Logger("MutualGroupDMs").error("Failed to push mutual group dms section:", e); + } }, renderMutualGDMs: ErrorBoundary.wrap(({ user, onClose }: { user: User, onClose: () => void; }) => { const mutualGDms = useMemo(() => getMutualGroupDms(user.id), [user.id]); - const entries = renderClickableGDMs(mutualGDms, onClose); return ( @@ -138,14 +159,13 @@ export default definePlugin({ ); }), - renderDMPageList: ErrorBoundary.wrap(({ user, Divider, listStyle }: { user: User, Divider: JSX.Element, listStyle: string; }) => { + renderDMPageList: ErrorBoundary.wrap(({ user, hasDivider, Divider, listStyle }: { user: User, hasDivider: boolean, Divider: JSX.Element, listStyle: string; }) => { const mutualGDms = getMutualGroupDms(user.id); if (mutualGDms.length === 0) return null; - return ( <> - {Divider} + {hasDivider && Divider}