This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
157 lines (137 loc) · 3.94 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const { Plugin } = require("powercord/entities");
const { uninject } = require("powercord/injector");
const Settings = require("./components/settings/Settings");
const { InjectionIDs } = require("./Constants");
require("./utils/bootstrap");
const i18n = require("./i18n");
module.exports = class PinDMs extends Plugin {
/**
* Start the plugin
*/
async startPlugin() {
// Default settings handler
this.DEFAULT_SETTINGS = {
friendList: {
sortoptions: true,
mutualguilds: true,
showtotal: true,
},
// Updated settings
general: {
pinIcon: true,
unreadAmount: true,
channelAmount: true,
},
recentOrder: {
channelList: false,
guildList: false,
},
pindms: {
dmCategories: {},
serverlist: [],
},
};
powercord.api.i18n.loadAllStrings(i18n);
// Register settings menu for PinDMs
powercord.api.settings.registerSettings("pindms", {
category: this.entityID,
label: "PinDMs",
render: Settings,
});
// Handle CSS
this.loadStylesheet("style.scss");
await this.start();
}
async start() {
this.instances = {};
for (const settingKey of Object.keys(this.DEFAULT_SETTINGS)) {
let newCfg;
const cfg = this.settings.get(settingKey);
if (cfg) {
newCfg = Object.assign(this.DEFAULT_SETTINGS[settingKey], cfg);
} else {
newCfg = this.DEFAULT_SETTINGS[settingKey];
}
this.settings.set(settingKey, newCfg);
}
/*
* 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
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("pindms");
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[PinDMs]", "color: #ffeb3b", ...data);
}
};