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