Misc: Move More Funcs To Utils
This commit is contained in:
parent
f5a3d4e89e
commit
675da92c3c
4 changed files with 32 additions and 30 deletions
|
|
@ -15,12 +15,10 @@ import { DonateButton, InviteButton } from "@components/settings/DonateButton";
|
|||
import { QuickAction, QuickActionCard } from "@components/settings/QuickAction";
|
||||
import { SpecialCard } from "@components/settings/SpecialCard";
|
||||
import { gitRemote } from "@shared/vencordUserAgent";
|
||||
import { DONOR_ROLE_ID, GUILD_ID, VC_DONOR_ROLE_ID, VC_GUILD_ID } from "@utils/constants";
|
||||
import { Margins } from "@utils/margins";
|
||||
import { identity, isEquicordPluginDev, isPluginDev } from "@utils/misc";
|
||||
import { identity, isEquicordDonor, isEquicordPluginDev, isPluginDev, isVencordDonor } from "@utils/misc";
|
||||
import { relaunch } from "@utils/native";
|
||||
import { Button, Flex, Forms, GuildMemberStore, React, Select, Switch, UserStore } from "@webpack/common";
|
||||
import BadgeAPI from "plugins/_api/badges";
|
||||
import { Button, Flex, Forms, React, Select, Switch, UserStore } from "@webpack/common";
|
||||
|
||||
import { openNotificationSettingsModal } from "./NotificationSettings";
|
||||
|
||||
|
|
@ -339,14 +337,4 @@ function DonateButtonComponent() {
|
|||
);
|
||||
}
|
||||
|
||||
function isVencordDonor(userId: string): boolean {
|
||||
const donorBadges = BadgeAPI.getDonorBadges(userId);
|
||||
return GuildMemberStore.getMember(VC_GUILD_ID, userId)?.roles.includes(VC_DONOR_ROLE_ID) || !!donorBadges;
|
||||
}
|
||||
|
||||
export function isEquicordDonor(userId: string): boolean {
|
||||
const donorBadges = BadgeAPI.getEquicordDonorBadges(userId);
|
||||
return GuildMemberStore.getMember(GUILD_ID, userId)?.roles.includes(DONOR_ROLE_ID) || !!donorBadges;
|
||||
}
|
||||
|
||||
export default wrapTab(EquicordSettings, "Equicord Settings");
|
||||
|
|
|
|||
|
|
@ -21,10 +21,9 @@ import "./fixDiscordBadgePadding.css";
|
|||
import { _getBadges, BadgePosition, BadgeUserArgs, ProfileBadge } from "@api/Badges";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { openContributorModal } from "@components/settings/tabs";
|
||||
import { isEquicordDonor } from "@components/settings/tabs/vencord";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import { copyWithToast, shouldShowContributorBadge, shouldShowEquicordContributorBadge } from "@utils/misc";
|
||||
import { copyWithToast, isEquicordDonor, shouldShowContributorBadge, shouldShowEquicordContributorBadge } from "@utils/misc";
|
||||
import definePlugin from "@utils/types";
|
||||
import { User } from "@vencord/discord-types";
|
||||
import { ContextMenuApi, Menu, Toasts, UserStore } from "@webpack/common";
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ import ErrorBoundary from "@components/ErrorBoundary";
|
|||
import { Flex } from "@components/Flex";
|
||||
import { Link } from "@components/Link";
|
||||
import { openUpdaterModal } from "@components/settings/tabs/updater";
|
||||
import { CONTRIB_ROLE_ID, Devs, DONOR_ROLE_ID, EQUIBOP_CONTRIB_ROLE_ID, EQUICORD_HELPERS, EQUICORD_TEAM, GUILD_ID, SUPPORT_CHANNEL_ID, SUPPORT_CHANNEL_IDS, VC_CONTRIB_ROLE_ID, VC_DONOR_ROLE_ID, VC_GUILD_ID, VC_REGULAR_ROLE_ID, VC_SUPPORT_CHANNEL_IDS, VENCORD_CONTRIB_ROLE_ID } from "@utils/constants";
|
||||
import { CONTRIB_ROLE_ID, Devs, DONOR_ROLE_ID, EQUIBOP_CONTRIB_ROLE_ID, EQUICORD_TEAM, GUILD_ID, SUPPORT_CHANNEL_ID, SUPPORT_CHANNEL_IDS, VC_CONTRIB_ROLE_ID, VC_DONOR_ROLE_ID, VC_GUILD_ID, VC_REGULAR_ROLE_ID, VC_SUPPORT_CHANNEL_IDS, VENCORD_CONTRIB_ROLE_ID } from "@utils/constants";
|
||||
import { sendMessage } from "@utils/discord";
|
||||
import { Logger } from "@utils/Logger";
|
||||
import { Margins } from "@utils/margins";
|
||||
import { isEquicordPluginDev, isPluginDev, tryOrElse } from "@utils/misc";
|
||||
import { isEquicordGuild, isEquicordPluginDev, isEquicordSupport, isPluginDev, isSupportChannel, tryOrElse } from "@utils/misc";
|
||||
import { relaunch } from "@utils/native";
|
||||
import { onlyOnce } from "@utils/onlyOnce";
|
||||
import { makeCodeblock } from "@utils/text";
|
||||
|
|
@ -219,14 +219,14 @@ export default definePlugin({
|
|||
name: "equicord-debug",
|
||||
description: "Send Equicord debug info",
|
||||
// @ts-ignore
|
||||
predicate: ctx => isPluginDev(UserStore.getCurrentUser()?.id) || isEquicordPluginDev(UserStore.getCurrentUser()?.id) || GUILD_ID === ctx?.guild?.id,
|
||||
predicate: ctx => isPluginDev(UserStore.getCurrentUser()?.id) || isEquicordPluginDev(UserStore.getCurrentUser()?.id) || isEquicordGuild(ctx?.guild?.id, true),
|
||||
execute: async () => ({ content: await generateDebugInfoMessage() })
|
||||
},
|
||||
{
|
||||
name: "equicord-plugins",
|
||||
description: "Send Equicord plugin list",
|
||||
// @ts-ignore
|
||||
predicate: ctx => isPluginDev(UserStore.getCurrentUser()?.id) || isEquicordPluginDev(UserStore.getCurrentUser()?.id) || GUILD_ID === ctx?.guild?.id,
|
||||
predicate: ctx => isPluginDev(UserStore.getCurrentUser()?.id) || isEquicordPluginDev(UserStore.getCurrentUser()?.id) || isEquicordGuild(ctx?.guild?.id, true),
|
||||
execute: () => {
|
||||
const pluginList = generatePluginList();
|
||||
return { content: typeof pluginList === "string" ? pluginList : "Unable to generate plugin list." };
|
||||
|
|
@ -328,11 +328,11 @@ export default definePlugin({
|
|||
renderMessageAccessory(props) {
|
||||
const buttons = [] as JSX.Element[];
|
||||
|
||||
const equicordSupport = GuildMemberStore.getMember(GUILD_ID, props.message.author.id)?.roles?.includes(EQUICORD_HELPERS);
|
||||
const equicordSupport = isEquicordSupport(props.message.author.id);
|
||||
|
||||
const shouldAddUpdateButton =
|
||||
!IS_UPDATER_DISABLED
|
||||
&& ((props.channel.id === SUPPORT_CHANNEL_ID && equicordSupport))
|
||||
&& ((isSupportChannel(props.channel.id) && equicordSupport))
|
||||
&& props.message.content?.includes("update");
|
||||
|
||||
if (shouldAddUpdateButton) {
|
||||
|
|
@ -357,7 +357,7 @@ export default definePlugin({
|
|||
);
|
||||
}
|
||||
|
||||
if (props.channel.id === SUPPORT_CHANNEL_ID && PermissionStore.can(PermissionsBits.SEND_MESSAGES, props.channel)) {
|
||||
if (isSupportChannel(props.channel.id) && PermissionStore.can(PermissionsBits.SEND_MESSAGES, props.channel)) {
|
||||
if (props.message.content.includes("/equicord-debug") || props.message.content.includes("/equicord-plugins")) {
|
||||
buttons.push(
|
||||
<Button
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@
|
|||
*/
|
||||
|
||||
import { ChannelStore, GuildMemberStore, Toasts } from "@webpack/common";
|
||||
import BadgeAPI from "plugins/_api/badges";
|
||||
|
||||
import { copyToClipboard } from "./clipboard";
|
||||
import { EQUICORD_HELPERS, EquicordDevsById, GUILD_ID, VencordDevsById } from "./constants";
|
||||
import { DONOR_ROLE_ID, EQUICORD_HELPERS, EquicordDevsById, GUILD_ID, SUPPORT_CHANNEL_ID, VC_DONOR_ROLE_ID, VC_GUILD_ID, VencordDevsById } from "./constants";
|
||||
|
||||
/**
|
||||
* Calls .join(" ") on the arguments
|
||||
|
|
@ -117,14 +118,28 @@ export function tryOrElse<T>(func: () => T, fallback: T): T {
|
|||
}
|
||||
}
|
||||
|
||||
export const isEquicordGuild = (id: string, isGuildId: boolean = false) => {
|
||||
export function isEquicordGuild(id: string, isGuildId: boolean = false): boolean {
|
||||
if (isGuildId) return id === GUILD_ID;
|
||||
|
||||
const channel = ChannelStore.getChannel(id);
|
||||
return channel.guild_id === GUILD_ID;
|
||||
};
|
||||
}
|
||||
|
||||
export const isEquicordSupport = (id: string) => {
|
||||
const member = GuildMemberStore.getMember(GUILD_ID, id);
|
||||
return member?.roles?.includes(EQUICORD_HELPERS);
|
||||
};
|
||||
export function isSupportChannel(channelId: string): boolean {
|
||||
return channelId === SUPPORT_CHANNEL_ID;
|
||||
}
|
||||
|
||||
export function isEquicordSupport(userId: string): boolean {
|
||||
const member = GuildMemberStore.getMember(GUILD_ID, userId);
|
||||
return member?.roles?.includes(EQUICORD_HELPERS) || false;
|
||||
}
|
||||
|
||||
export function isEquicordDonor(userId: string): boolean {
|
||||
const donorBadges = BadgeAPI.getEquicordDonorBadges(userId);
|
||||
return GuildMemberStore.getMember(GUILD_ID, userId)?.roles.includes(DONOR_ROLE_ID) || !!donorBadges;
|
||||
}
|
||||
|
||||
export function isVencordDonor(userId: string): boolean {
|
||||
const donorBadges = BadgeAPI.getDonorBadges(userId);
|
||||
return GuildMemberStore.getMember(VC_GUILD_ID, userId)?.roles.includes(VC_DONOR_ROLE_ID) || !!donorBadges;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue