mirror of
https://github.com/Equicord/Equicord.git
synced 2025-01-18 05:13:29 -05:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
cad4b9a1ab
5 changed files with 71 additions and 55 deletions
|
@ -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, 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;
|
||||
}
|
||||
|
|
|
@ -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}`,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
<ExpandableList
|
||||
listClassName={listStyle}
|
||||
header={"Mutual Groups"}
|
||||
|
|
|
@ -23,9 +23,9 @@ import { definePluginSettings } from "@api/Settings";
|
|||
import { classNameFactory } from "@api/Styles";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { Devs, EquicordDevs } from "@utils/constants";
|
||||
import { useForceUpdater } from "@utils/react";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { GuildStore, PresenceStore, RelationshipStore, Tooltip } from "@webpack/common";
|
||||
import { findStoreLazy } from "@webpack";
|
||||
import { GuildStore, PresenceStore, RelationshipStore, Tooltip, useStateFromStores } from "@webpack/common";
|
||||
|
||||
const enum IndicatorType {
|
||||
SERVER = 1 << 0,
|
||||
|
@ -33,13 +33,28 @@ const enum IndicatorType {
|
|||
BOTH = SERVER | FRIEND,
|
||||
}
|
||||
|
||||
let onlineFriends = 0;
|
||||
|
||||
let onlineFriendsCount = 0;
|
||||
let guildCount = 0;
|
||||
let forceUpdateFriendCount: () => void;
|
||||
let forceUpdateGuildCount: () => void;
|
||||
|
||||
const UserGuildJoinRequestStore = findStoreLazy("UserGuildJoinRequestStore");
|
||||
|
||||
function FriendsIndicator() {
|
||||
forceUpdateFriendCount = useForceUpdater();
|
||||
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 (
|
||||
<div id="vc-friendcount">
|
||||
|
@ -59,7 +74,7 @@ function FriendsIndicator() {
|
|||
</path>
|
||||
</svg>
|
||||
}
|
||||
<span id="vc-friendcount-text">{onlineFriends}</span>
|
||||
<span id="vc-friendcount-text">{onlineFriendsCount}</span>
|
||||
{!!settings.store.useCompact &&
|
||||
<span id="vc-friendcount-text-compact">Friends</span>
|
||||
}
|
||||
|
@ -68,7 +83,13 @@ function FriendsIndicator() {
|
|||
}
|
||||
|
||||
function ServersIndicator() {
|
||||
forceUpdateGuildCount = useForceUpdater();
|
||||
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 (
|
||||
<div id="vc-guildcount">
|
||||
|
@ -96,24 +117,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 const settings = definePluginSettings({
|
||||
mode: {
|
||||
description: "Mode",
|
||||
|
@ -146,13 +149,13 @@ export default definePlugin({
|
|||
// switch is simply better
|
||||
switch (mode) {
|
||||
case IndicatorType.BOTH:
|
||||
text = `${onlineFriends} Friends, ${guildCount} Servers`;
|
||||
text = `${onlineFriendsCount} Friends, ${guildCount} Servers`;
|
||||
break;
|
||||
case IndicatorType.FRIEND:
|
||||
text = `${onlineFriends} Friends`;
|
||||
text = `${onlineFriendsCount} Friends`;
|
||||
break;
|
||||
case IndicatorType.SERVER:
|
||||
text = `${onlineFriends} Friends, ${guildCount} Servers`;
|
||||
text = `${onlineFriendsCount} Friends, ${guildCount} Servers`;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -177,16 +180,8 @@ export default definePlugin({
|
|||
</ErrorBoundary>;
|
||||
},
|
||||
|
||||
flux: {
|
||||
PRESENCE_UPDATES: handlePresenceUpdate,
|
||||
GUILD_CREATE: handleGuildUpdate,
|
||||
GUILD_DELETE: handleGuildUpdate,
|
||||
},
|
||||
|
||||
start() {
|
||||
addServerListElement(ServerListRenderPosition.Above, this.renderIndicator);
|
||||
handlePresenceUpdate();
|
||||
handleGuildUpdate();
|
||||
},
|
||||
|
||||
stop() {
|
||||
|
|
Loading…
Reference in a new issue