This repository has been archived by the owner on Oct 4, 2022. It is now read-only.
/
index.js
59 lines (46 loc) · 1.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { Plugin } = require('powercord/entities');
const { getModule, React } = require('powercord/webpack');
const { inject, uninject } = require('powercord/injector');
const ChannelUserCount = require('./ChannelUserCount.jsx');
const e = React.createElement;
class VoiceUserCount extends (
Plugin
) {
async startPlugin() {
this.patchChannelItem();
}
pluginWillUnload() {
uninject('voice-user-count');
}
async patchChannelItem() {
const ConnectedVoiceChannel = await getModule(m => m.default && m.default.displayName === 'ChannelItem');
const renderCount = (args, res) => {
if(!this.shouldApply(args)) {
return res;
}
const channelInfoElement = args[0].children[3];
const children = React.Children.toArray(channelInfoElement.props.children);
const ChannelUserCountElement = e(ChannelUserCount, { userCount: this.getUserCount(channelInfoElement)});
children.push(ChannelUserCountElement);
channelInfoElement.props.children = children;
return res;
};
inject('voice-user-count', ConnectedVoiceChannel, 'default', renderCount);
ConnectedVoiceChannel.default.displayName = 'ChannelItem';
}
shouldApply(args) {
const channel = args[0].channel;
const isVideo = args[0].children[0]?.props.video;
const users = args[0].children[3]?.props.children?.props?.voiceStates?.length;
return (
channel.isGuildVoice() &&
!channel.userLimit &&
!isVideo &&
users
)
}
getUserCount(channelInfo) {
return channelInfo.props.children?.props?.voiceStates?.length;
}
};
module.exports = VoiceUserCount;