From 30ac25607023752031aa98060cbf8a736109992d Mon Sep 17 00:00:00 2001 From: V Date: Sun, 24 Sep 2023 16:02:18 +0200 Subject: migrate all plugins to folders --- src/plugins/memberCount/index.tsx | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/plugins/memberCount/index.tsx (limited to 'src/plugins/memberCount') diff --git a/src/plugins/memberCount/index.tsx b/src/plugins/memberCount/index.tsx new file mode 100644 index 0000000..ecdb8af --- /dev/null +++ b/src/plugins/memberCount/index.tsx @@ -0,0 +1,116 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import ErrorBoundary from "@components/ErrorBoundary"; +import { Flex } from "@components/Flex"; +import { Devs } from "@utils/constants"; +import { getCurrentChannel } from "@utils/discord"; +import definePlugin from "@utils/types"; +import { findStoreLazy } from "@webpack"; +import { SelectedChannelStore, Tooltip, useStateFromStores } from "@webpack/common"; +import { FluxStore } from "@webpack/types"; + +const GuildMemberCountStore = findStoreLazy("GuildMemberCountStore") as FluxStore & { getMemberCount(guildId: string): number | null; }; +const ChannelMemberStore = findStoreLazy("ChannelMemberStore") as FluxStore & { + getProps(guildId: string, channelId: string): { groups: { count: number; id: string; }[]; }; +}; + +const sharedIntlNumberFormat = new Intl.NumberFormat(); +const numberFormat = (value: number) => sharedIntlNumberFormat.format(value); + +function MemberCount() { + const { id: channelId, guild_id: guildId } = useStateFromStores([SelectedChannelStore], () => getCurrentChannel()); + const { groups } = useStateFromStores( + [ChannelMemberStore], + () => ChannelMemberStore.getProps(guildId, channelId) + ); + const total = useStateFromStores( + [GuildMemberCountStore], + () => GuildMemberCountStore.getMemberCount(guildId) + ); + + if (total == null) + return null; + + const online = + (groups.length === 1 && groups[0].id === "unknown") + ? 0 + : groups.reduce((count, curr) => count + (curr.id === "offline" ? 0 : curr.count), 0); + + return ( + + + {props => ( +
+ + {numberFormat(online)} +
+ )} +
+ + {props => ( +
+ + {numberFormat(total)} +
+ )} +
+
+ ); +} + +export default definePlugin({ + name: "MemberCount", + description: "Shows the amount of online & total members in the server member list", + authors: [Devs.Ven, Devs.Commandtechno], + + patches: [{ + find: ".isSidebarVisible,", + replacement: { + match: /(var (\i)=\i\.className.+?children):\[(\i\.useMemo[^}]+"aria-multiselectable")/, + replace: "$1:[$2?.startsWith('members')?$self.render():null,$3" + } + }], + + render: ErrorBoundary.wrap(MemberCount, { noop: true }) +}); -- cgit