module.exports = (Plugin, Api, Vendor, Dependencies) => { const { $, _ } = Vendor; const { Events, Logger, InternalSettings, CssUtils } = Api; return class extends Plugin { get api() { return Api; } async onStart() { await this.injectStyles(); Events.subscribe('TEST_EVENT', this.eventTest); Logger.log('onStart'); Logger.log(`Plugin setting "default-0" value: ${this.settings.get('default-0')}`); this.on('setting-updated', event => { console.log('Received plugin setting update:', event); }); this.on('settings-updated', event => { console.log('Received plugin settings update:', event); }); this.settings.on('setting-updated', event => { Logger.log(`Setting ${event.category.id}/${event.setting.id} changed from ${event.old_value} to ${event.value}:`, event); }); // this.settings.categories.find(c => c.id === 'default').settings.find(s => s.id === 'default-5') this.settings.getSetting('default', 'default-0').on('setting-updated', async event => { Logger.log(`Some feature ${event.value ? 'enabled' : 'disabled'}`); }); this.settings.on('settings-updated', async event => { await this.injectStyles(); Logger.log('Settings updated:', event, 'Waiting before saving complete...'); await new Promise(resolve => setTimeout(resolve, 5000)); Logger.log('Done'); }); Logger.log(`Internal setting "core/default/test-setting" value: ${InternalSettings.get('core', 'default', 'test-setting')}`); Events.subscribe('setting-updated', event => { console.log('Received internal setting update:', event); }); const exampleModule = new Dependencies['Example Module']; Logger.log(`2+4=${exampleModule.add(2, 4)}`); return true; } async injectStyles() { const scss = await CssUtils.getConfigAsSCSS() + `.layer-kosS71 .guilds-wrapper + * { &::before { content: 'Example plugin stuff (test radio setting #{$default-5} selected)'; display: block; padding: 10px 40px; color: #eee; background-color: #202225; text-align: center; font-size: 14px; } }`; Logger.log('Plugin SCSS:', scss); await CssUtils.injectSass(scss); } onStop() { CssUtils.deleteAllStyles(); Events.unsubscribeAll(); Logger.log('onStop'); console.log(this.showSettingsModal()); return true; } onUnload(reload) { Logger.log('Unloading plugin'); delete require.cache[require.resolve('./component')]; } eventTest(e) { Logger.log(e); } get bridge() { return { test1: this.test1.bind(this), test2: this.test2.bind(this) }; } test1() { return 'It works!'; } test2() { return 'This works too!'; } settingChanged(event) { if (!this.enabled) return; Logger.log(`${event.category_id}/${event.setting_id} changed to ${event.value}`); } settingsChanged(event) { if (!this.enabled) return; Logger.log([ 'Settings updated', event.updatedSettings ]); } get settingscomponent() { const plugin = this; return this._settingscomponent ? this._settingscomponent : this._settingscomponent = { template: "