-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (56 loc) · 1.68 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
60
61
62
63
64
65
66
67
68
69
import BaseModule from './structures/BaseModule.js'
import { delay } from '@/src/util/Util.js'
export default class Presence extends BaseModule {
/**
* @param {Main} main
*/
constructor(main) {
super(main);
this.register(Presence, {
name: 'presence',
events: [
{
name: 'ready',
call: '_startInterval'
}
]
});
}
/**
* This method evaluates a config presence string to something with dynamic values
* @private
* @param {string} string String to be evaluated
*/
_presenceStringEval(string) {
const matches = string.match(/(?<=\$\{).*?(?=\})/g);
for (const key of (matches ? matches : [])) {
string = string.replace('${'+ key + '}', this.presenceValues[key]);
}
return string;
}
async _startInterval() {
this._updatePresenceValues();
for (const presence of this.activities) {
const { type } = presence;
const name = this._presenceStringEval(presence.name);
this._m.user.setPresence({ activities: [ { name, type } ] });
await delay(this.switch_interval);
}
this._startInterval();
}
/**
* @private
*/
_updatePresenceValues() {
const count = this.globalStorage.get('serverCount');
this.presenceValues.serverCount = count ? count : 'unknown';
}
init() {
Object.assign(this, this.config.presence_settings);
this.presenceValues = {
version: this._m.version,
serverCount: 1
};
return true;
}
}