add a base for content config object
This commit is contained in:
parent
a37bccfbb2
commit
b1f4fb637e
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* BetterDiscord Content Config Utility
|
||||
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
||||
* All rights reserved.
|
||||
* https://betterdiscord.net
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
|
||||
export default class ContentConfig {
|
||||
|
||||
constructor(data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
map(cb) {
|
||||
return this.data.map(cb);
|
||||
}
|
||||
|
||||
strip() {
|
||||
return this.map(cat => ({
|
||||
category: cat.category,
|
||||
settings: cat.settings.map(setting => ({
|
||||
id: setting.id, value: setting.value
|
||||
}))
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
|
@ -17,6 +17,10 @@ import {
|
|||
} from '../structs/socketstructs';
|
||||
|
||||
|
||||
/**
|
||||
* Discord socket event hook
|
||||
* @extends {EventListener}
|
||||
*/
|
||||
export default class extends EventListener {
|
||||
|
||||
bindings() {
|
||||
|
@ -29,14 +33,16 @@ export default class extends EventListener {
|
|||
];
|
||||
}
|
||||
|
||||
hook() {
|
||||
hook() {}
|
||||
|
||||
}
|
||||
|
||||
get eventsModule() {
|
||||
|
||||
}
|
||||
get eventsModule() {}
|
||||
|
||||
/**
|
||||
* Discord emit overload
|
||||
* @param {any} e
|
||||
* @param {any} action
|
||||
* @param {any} data
|
||||
*/
|
||||
emit(e, action, data) {
|
||||
switch (e) {
|
||||
case 'dispatch':
|
||||
|
@ -44,6 +50,11 @@ export default class extends EventListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit callback
|
||||
* @param {any} e Event Action
|
||||
* @param {any} d Event Args
|
||||
*/
|
||||
dispatch(e, d) {
|
||||
|
||||
Events.emit('raw-event', { type: e, data: d });
|
||||
|
@ -77,6 +88,9 @@ export default class extends EventListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All known socket actions
|
||||
*/
|
||||
get actions() {
|
||||
return {
|
||||
READY: 'READY', // Socket ready
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
import { FileUtils } from 'common';
|
||||
import { Modals } from 'ui';
|
||||
import { EventEmitter } from 'events';
|
||||
import ContentConfig from './contentconfig';
|
||||
import { SettingUpdatedEvent, SettingsUpdatedEvent } from 'structs';
|
||||
|
||||
class PluginEvents {
|
||||
|
@ -108,20 +109,12 @@ export default class Plugin {
|
|||
}
|
||||
|
||||
async saveConfiguration() {
|
||||
window.testConfig = new ContentConfig(this.pluginConfig);
|
||||
try {
|
||||
const config = new ContentConfig(this.pluginConfig).strip();
|
||||
await FileUtils.writeFile(`${this.pluginPath}/user.config.json`, JSON.stringify({
|
||||
enabled: this.enabled,
|
||||
config: this.pluginConfig.map(category => {
|
||||
return {
|
||||
category: category.category,
|
||||
settings: category.settings.map(setting => {
|
||||
return {
|
||||
id: setting.id,
|
||||
value: setting.value
|
||||
};
|
||||
})
|
||||
};
|
||||
})
|
||||
config
|
||||
}));
|
||||
} catch (err) {
|
||||
throw err;
|
||||
|
|
Loading…
Reference in New Issue