-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
141 lines (126 loc) · 3.87 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const { Plugin } = require('powercord/entities');
const { uninject } = require('powercord/injector');
const Settings = require('./Settings');
const { InjectionIDs } = require('./Constants');
module.exports = class BetterFriends extends Plugin {
/**
* Start the plugin
*/
async startPlugin () {
// Default settings handler
this.DEFAULT_SETTINGS = {
favfriends: [],
notifsounds: {},
infomodal: true,
displaystar: true,
statuspopup: true
};
// Register settings menu for BetterFriends
powercord.api.settings.registerSettings('betterfriends', {
category: this.entityID,
label: 'Better Friends',
render: Settings
});
// Handle CSS
this.loadStylesheet('style.scss');
// Constants
this.FRIEND_DATA = {
statusStorage: {},
lastMessageID: {}
};
await this.start();
}
async start () {
this.instances = {};
this.FAV_FRIENDS = this.settings.get('favfriends');
if (!this.FAV_FRIENDS) {
this.FAV_FRIENDS = [];
for (const setting of Object.keys(this.DEFAULT_SETTINGS)) {
if (this.DEFAULT_SETTINGS[setting] === undefined && !this.FAV_FRIENDS) { /* eslint-disable-line */ /* I know this is bad practice, hopefully I'll find a better solution soon */
this.settings.set(this.settings.get(setting, this.DEFAULT_SETTINGS[setting]));
}
}
}
/*
* Modules
* Handled by the module resolver outside of `startPlugin`.
* All modules are created by Nevulo#0007 unless stated otherwise. Contributors will be listed as well
*/
// Store each of the modules above into this object where we can load them later
this.MODULES = require('./modules');
for (const module of Object.keys(this.MODULES)) {
this.MODULES[module] = this.MODULES[module].bind(this);
}
// Unload all modules if this user has no favorite friends
if (this.FAV_FRIENDS && this.FAV_FRIENDS.length > 0) {
await this.load();
}
}
/*
* Module Resolver + Handler
* Handles the loading and unloading of all modules.
*/
/**
* Load one or multiple modules
* When no module is specified, all modules are loaded by default.
* @param {String} specific Pass a specific module name to load only that module
*/
load (specific) {
if (specific) {
this.MODULES[specific]();
} else {
for (const load of Object.keys(this.MODULES)) {
this.MODULES[load]();
}
}
}
/**
* Unload one or multiple modules
* When no module is specified, the entire plugin is unloaded from Powercord.
* @param {String} specific Pass a specific module name to unload only that module
*/
unload (specific) {
if (specific) {
for (const injection of InjectionIDs[specific]) {
uninject(injection);
}
} else {
this.log('Plugin stopped');
for (const unload of Object.keys(this.MODULES)) {
for (const injection of (InjectionIDs[unload] || [])) {
uninject(injection);
}
}
}
}
pluginWillUnload () {
powercord.api.settings.unregisterSettings('betterfriends');
this.unload();
}
/**
* Reload (unload and then load) one or multiple modules
* When no module is specified, the entire plugin will reload
* @param {String} specific Pass a specific module name to reload only that module
*/
async reload (...specific) {
if (specific && specific.length) {
for (const mod of specific) {
this.log(`Reloading module '${mod}'`);
this.unload(mod);
this.load(mod);
}
} else {
this.log('Reloading all modules');
this.unload();
await this.start();
}
}
/**
* Log a string or data to the developer console
* Overwrites the normal Powercord .log method.
* @param {any} data Data to log
*/
log (data) {
console.log('%c[ Better Friends ]', 'color: #ffeb3b', data);
}
};