1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-10 18:06:22 +00:00

Merge branch 'main' into main

This commit is contained in:
Vexify4103 2024-12-04 18:46:06 +01:00 committed by GitHub
commit 5423c813a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 74 additions and 61 deletions

View file

@ -54,5 +54,5 @@ export function sendBotMessage(channelId: string, message: PartialDeep<Message>)
export function findOption<T>(args: Argument[], name: string): T & {} | undefined; export function findOption<T>(args: Argument[], name: string): T & {} | undefined;
export function findOption<T>(args: Argument[], name: string, fallbackValue: T): T & {}; export function findOption<T>(args: Argument[], name: string, fallbackValue: T): T & {};
export function findOption(args: Argument[], name: string, fallbackValue?: any) { 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;
} }

View file

@ -110,6 +110,7 @@ function registerSubCommands(cmd: Command, plugin: string) {
const subCmd = { const subCmd = {
...cmd, ...cmd,
...o, ...o,
options: o.options !== undefined ? o.options : undefined,
type: ApplicationCommandType.CHAT_INPUT, type: ApplicationCommandType.CHAT_INPUT,
name: `${cmd.name} ${o.name}`, name: `${cmd.name} ${o.name}`,
id: `${o.name}-${cmd.id}`, id: `${o.name}-${cmd.id}`,

View file

@ -23,11 +23,14 @@ export default definePlugin({
name: "MessagePopoverAPI", name: "MessagePopoverAPI",
description: "API to add buttons to message popovers.", description: "API to add buttons to message popovers.",
authors: [Devs.KingFish, Devs.Ven, Devs.Nuckyz], authors: [Devs.KingFish, Devs.Ven, Devs.Nuckyz],
patches: [{ patches: [
{
find: "#{intl::MESSAGE_UTILITIES_A11Y_LABEL}", find: "#{intl::MESSAGE_UTILITIES_A11Y_LABEL}",
replacement: { replacement: {
match: /\.jsx\)\((\i\.\i),\{label:\i\.\i\.string\(\i\.\i#{intl::MESSAGE_ACTION_REPLY}.{0,200}?"reply-self".{0,50}?\}\):null(?=,.+?message:(\i))/, match: /(?<=:null),(.{0,40}togglePopout:.+?}\))\]}\):null,(?<=\((\i\.\i),{label:.+?:null,(\i&&!\i)\?\(0,\i\.jsxs?\)\(\i\.Fragment.+?message:(\i).+?)/,
replace: "$&,Vencord.Api.MessagePopover._buildPopoverElements($1,$2)" replace: (_, ReactButton, ButtonComponent, showReactButton, message) => "" +
`]}):null,Vencord.Api.MessagePopover._buildPopoverElements(${ButtonComponent},${message}),${showReactButton}?${ReactButton}:null,`
} }
}], }
]
}); });

View file

@ -51,7 +51,7 @@ export default definePlugin({
{ {
find: "bitbucket.org", find: "bitbucket.org",
replacement: { replacement: {
match: /function \i\(\i\){(?=.{0,60}\.parse\(\i\))/, match: /function \i\(\i\){(?=.{0,30}pathname:\i)/,
replace: "$&return null;" replace: "$&return null;"
}, },
predicate: () => settings.store.file predicate: () => settings.store.file

View file

@ -19,6 +19,7 @@
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { isNonNullish } from "@utils/guards"; import { isNonNullish } from "@utils/guards";
import { Logger } from "@utils/Logger";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { Avatar, ChannelStore, Clickable, IconUtils, RelationshipStore, ScrollerThin, useMemo, UserStore } from "@webpack/common"; import { Avatar, ChannelStore, Clickable, IconUtils, RelationshipStore, ScrollerThin, useMemo, UserStore } from "@webpack/common";
@ -97,14 +98,32 @@ export default definePlugin({
}, },
{ {
find: 'section:"MUTUAL_FRIENDS"', find: 'section:"MUTUAL_FRIENDS"',
replacement: { replacement: [
match: /\.openUserProfileModal.+?\)}\)}\)(?<=(\(0,\i\.jsxs?\)\(\i\.\i,{className:(\i)\.divider}\)).+?)/, {
replace: "$&,$self.renderDMPageList({user: arguments[0].user, Divider: $1, listStyle: $2.list})" 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})`
} }
]
} }
], ],
getMutualGroupDms(userId: string) {
try {
return getMutualGroupDms(userId);
} catch (e) {
new Logger("MutualGroupDMs").error("Failed to get mutual group dms:", e);
}
return [];
},
pushSection(sections: any[], user: User) { pushSection(sections: any[], user: User) {
try {
if (isBotOrSelf(user) || sections[IS_PATCHED]) return; if (isBotOrSelf(user) || sections[IS_PATCHED]) return;
sections[IS_PATCHED] = true; sections[IS_PATCHED] = true;
@ -112,11 +131,13 @@ export default definePlugin({
section: "MUTUAL_GDMS", section: "MUTUAL_GDMS",
text: getMutualGDMCountText(user) 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; }) => { renderMutualGDMs: ErrorBoundary.wrap(({ user, onClose }: { user: User, onClose: () => void; }) => {
const mutualGDms = useMemo(() => getMutualGroupDms(user.id), [user.id]); const mutualGDms = useMemo(() => getMutualGroupDms(user.id), [user.id]);
const entries = renderClickableGDMs(mutualGDms, onClose); const entries = renderClickableGDMs(mutualGDms, onClose);
return ( 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); const mutualGDms = getMutualGroupDms(user.id);
if (mutualGDms.length === 0) return null; if (mutualGDms.length === 0) return null;
return ( return (
<> <>
{Divider} {hasDivider && Divider}
<ExpandableList <ExpandableList
listClassName={listStyle} listClassName={listStyle}
header={"Mutual Groups"} header={"Mutual Groups"}

View file

@ -20,9 +20,9 @@ import { addServerListElement, removeServerListElement, ServerListRenderPosition
import { Settings } from "@api/Settings"; import { Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { useForceUpdater } from "@utils/react";
import definePlugin, { OptionType } from "@utils/types"; 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 { const enum IndicatorType {
SERVER = 1 << 0, SERVER = 1 << 0,
@ -30,13 +30,24 @@ const enum IndicatorType {
BOTH = SERVER | FRIEND, BOTH = SERVER | FRIEND,
} }
let onlineFriends = 0; const UserGuildJoinRequestStore = findStoreLazy("UserGuildJoinRequestStore");
let guildCount = 0;
let forceUpdateFriendCount: () => void;
let forceUpdateGuildCount: () => void;
function FriendsIndicator() { 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 ( return (
<span id="vc-friendcount" style={{ <span id="vc-friendcount" style={{
@ -48,13 +59,19 @@ function FriendsIndicator() {
textTransform: "uppercase", textTransform: "uppercase",
textAlign: "center", textAlign: "center",
}}> }}>
{onlineFriends} online {onlineFriendsCount} online
</span> </span>
); );
} }
function ServersIndicator() { 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 ( return (
<span id="vc-guildcount" style={{ <span id="vc-guildcount" style={{
@ -71,24 +88,6 @@ function ServersIndicator() {
); );
} }
function handlePresenceUpdate() {
onlineFriends = 0;
const relations = RelationshipStore.getRelationships();
for (const id of Object.keys(relations)) {
const type = relations[id];
// FRIEND relationship type
if (type === 1 && PresenceStore.getStatus(id) !== "offline") {
onlineFriends += 1;
}
}
forceUpdateFriendCount?.();
}
function handleGuildUpdate() {
guildCount = GuildStore.getGuildCount();
forceUpdateGuildCount?.();
}
export default definePlugin({ export default definePlugin({
name: "ServerListIndicators", name: "ServerListIndicators",
description: "Add online friend count or server count in the server list", description: "Add online friend count or server count in the server list",
@ -117,18 +116,8 @@ export default definePlugin({
</ErrorBoundary>; </ErrorBoundary>;
}, },
flux: {
PRESENCE_UPDATES: handlePresenceUpdate,
GUILD_CREATE: handleGuildUpdate,
GUILD_DELETE: handleGuildUpdate,
},
start() { start() {
addServerListElement(ServerListRenderPosition.Above, this.renderIndicator); addServerListElement(ServerListRenderPosition.Above, this.renderIndicator);
handlePresenceUpdate();
handleGuildUpdate();
}, },
stop() { stop() {