Plugin

ServerListIndicators

Add online friend count or server count in the server list

Servers Appearance
index.tsx
Download

Source

src/plugins/serverListIndicators/index.tsx
1/*
2 * FiveCord — a Discord client mod
3 * Copyright (c) 2025 FiveCord
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7import { addServerListElement, removeServerListElement, ServerListRenderPosition } from "@api/ServerList";
8import { definePluginSettings } from "@api/Settings";
9import ErrorBoundary from "@components/ErrorBoundary";
10import { Devs } from "@utils/constants";
11import definePlugin, { OptionType } from "@utils/types";
12import { findStoreLazy } from "@webpack";
13import { GuildStore, PresenceStore, RelationshipStore, useStateFromStores } from "@webpack/common";
14
15const enum IndicatorType {
16 SERVER = 1 << 0,
17 FRIEND = 1 << 1,
18 BOTH = SERVER | FRIEND,
19}
20
21const UserGuildJoinRequestStore = findStoreLazy("UserGuildJoinRequestStore");
22
23const settings = definePluginSettings({
24 mode: {
25 description: "Mode",
26 type: OptionType.SELECT,
27 options: [
28 { label: "Only online friend count", value: IndicatorType.FRIEND, default: true },
29 { label: "Only server count", value: IndicatorType.SERVER },
30 { label: "Both server and online friend counts", value: IndicatorType.BOTH },
31 ]
32 }
33});
34
35function FriendsIndicator() {
36 const onlineFriendsCount = useStateFromStores([RelationshipStore, PresenceStore], () => {
37 let count = 0;
38
39 const friendIds = RelationshipStore.getFriendIDs();
40 for (const id of friendIds) {
41 const status = PresenceStore.getStatus(id) ?? "offline";
42 if (status === "offline") {
43 continue;
44 }
45
46 count++;
47 }
48
49 return count;
50 });
51
52 return (
53 <span id="vc-friendcount" style={{
54 display: "inline-block",
55 width: "100%",
56 fontSize: "12px",
57 fontWeight: "600",
58 color: "var(--text-default)",
59 textTransform: "uppercase",
60 textAlign: "center",
61 }}>
62 {onlineFriendsCount} online
63 </span>
64 );
65}
66
67function ServersIndicator() {
68 const guildCount = useStateFromStores([GuildStore, UserGuildJoinRequestStore], () => {
69 const guildJoinRequests: string[] = UserGuildJoinRequestStore.computeGuildIds();
70 const guilds = GuildStore.getGuilds();
71
72 // Filter only pending guild join requests
73 return GuildStore.getGuildCount() + guildJoinRequests.filter(id => guilds[id] == null).length;
74 });
75
76 return (
77 <span id="vc-guildcount" style={{
78 display: "inline-block",
79 width: "100%",
80 fontSize: "12px",
81 fontWeight: "600",
82 color: "var(--text-default)",
83 textTransform: "uppercase",
84 textAlign: "center",
85 }}>
86 {guildCount} servers
87 </span>
88 );
89}
90
91export default definePlugin({
92 name: "ServerListIndicators",
93 description: "Add online friend count or server count in the server list",
94 tags: ["Servers", "Appearance"],
95 authors: [Devs.dzshn],
96 dependencies: ["ServerListAPI"],
97 settings,
98
99 renderIndicator: () => {
100 const { mode } = settings.store;
101 return <ErrorBoundary noop>
102 <div style={{ marginBottom: "4px" }}>
103 {!!(mode & IndicatorType.FRIEND) && <FriendsIndicator />}
104 {!!(mode & IndicatorType.SERVER) && <ServersIndicator />}
105 </div>
106 </ErrorBoundary>;
107 },
108
109 start() {
110 addServerListElement(ServerListRenderPosition.Above, this.renderIndicator);
111 },
112
113 stop() {
114 removeServerListElement(ServerListRenderPosition.Above, this.renderIndicator);
115 }
116});
117