This repository has been archived by the owner on Aug 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (77 loc) · 2.37 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
/* eslint-disable object-property-newline,no-use-before-define */
const { Plugin } = require('powercord/entities');
const { React, getModule } = require('powercord/webpack');
const SettingsView = getModule((m) => m?.displayName === 'SettingsView', false);
const { getUserSettingsSections } = getModule([ 'getUserSettingsSections' ], false);
module.exports = class ChatSettings extends Plugin {
async startPlugin () {
this.loadStylesheet('style.css');
this.genSections();
this.registerCommand();
}
pluginWillUnload () {
powercord.api.commands.unregisterCommand('settings');
}
genSections () {
if (powercord.initialized) {
this.sections = getArray();
} else {
this.sections = [];
powercord.once('loaded', () => {
this.sections = getArray();
});
}
function getArray () {
return [
...getUserSettingsSections({}),
...Object.values(powercord.api.settings.tabs)
.map(({ label, render }) => ({
element: render,
section: (typeof label === 'function') ? label() : label,
label: (typeof label === 'function') ? label() : label
}))
]
.filter(({ element }) => element);
}
}
registerCommand () {
powercord.api.commands.registerCommand({
command: 'settings',
label: 'Chat Settings',
usage: '{c} [ tab ]',
description: 'Opens the settings tab directly in the chat',
executor: this.getSettings.bind(this),
autocomplete: this.autocomplete.bind(this)
});
}
getSettings (args) {
const { section } = this.sections
.find(({ label }) => (label.toLowerCase() === args.join(' ').toLowerCase()));
if (!section) {
return false;
}
return {
result: {
type: 'component',
title: React.createElement('div', {
className: 'chat-settings-container',
children: React.createElement(SettingsView, {
section,
sections: this.sections
})
})
}
};
}
autocomplete (args) {
const tab = args.join(' ').toLowerCase();
return {
commands: this.sections
.filter(({ label, section }) => (
label.toLowerCase().includes(tab) && section !== 'My Account' // crash after opening settings
))
.map(({ label }) => ({ command: label })),
header: 'Settings tabs'
};
}
};