diff --git a/client/src/modules/contentconfig.js b/client/src/modules/contentconfig.js new file mode 100644 index 00000000..b5c23cca --- /dev/null +++ b/client/src/modules/contentconfig.js @@ -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 + })) + })); + } + +} diff --git a/client/src/modules/eventhook.js b/client/src/modules/eventhook.js index 7b5f8ca8..399fa6ac 100644 --- a/client/src/modules/eventhook.js +++ b/client/src/modules/eventhook.js @@ -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 diff --git a/client/src/modules/plugin.js b/client/src/modules/plugin.js index c4ae5c9d..75a2566a 100644 --- a/client/src/modules/plugin.js +++ b/client/src/modules/plugin.js @@ -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;