Plugin
ServerListIndicators
Add online friend count or server count in the server list
1
/*2
* FiveCord — a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import { addServerListElement, removeServerListElement, ServerListRenderPosition } from "@api/ServerList";8
import { definePluginSettings } from "@api/Settings";9
import ErrorBoundary from "@components/ErrorBoundary";10
import { Devs } from "@utils/constants";11
import definePlugin, { OptionType } from "@utils/types";12
import { findStoreLazy } from "@webpack";13
import { GuildStore, PresenceStore, RelationshipStore, useStateFromStores } from "@webpack/common";14
15
const enum IndicatorType {16
SERVER = 1 << 0,17
FRIEND = 1 << 1,18
BOTH = SERVER | FRIEND,19
}20
21
const UserGuildJoinRequestStore = findStoreLazy("UserGuildJoinRequestStore");22
23
const 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
35
function 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} online63
</span>64
);65
}66
67
function 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 requests73
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} servers87
</span>88
);89
}90
91
export 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