BetterDiscordApp-v2/tests/plugins/Example/index.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

module.exports = (Plugin, Api, Vendor, Dependencies) => {
2018-01-16 02:45:23 +01:00
const { $, moment, _ } = Vendor;
const { Events, Logger } = Api;
2018-01-16 02:45:23 +01:00
2018-02-12 16:20:27 +01:00
return class extends Plugin {
2018-01-16 02:45:23 +01:00
onStart() {
2018-02-12 00:04:07 +01:00
Events.subscribe('TEST_EVENT', this.eventTest);
Logger.log('onStart');
Logger.log(`Plugin setting "default-0" value: ${this.getSetting('default-0')}`);
this.events.on('setting-updated', event => {
console.log('Received plugin setting update:', event);
});
this.events.on('settings-updated', event => {
console.log('Received plugin settings update:', event);
});
Logger.log(`Internal setting "core/default/test-setting" value: ${Api.Settings.get('core', 'default', 'test-setting')}`);
Events.subscribe('setting-updated', event => {
console.log('Received internal setting update:', event);
});
2018-02-13 17:26:20 +01:00
const exampleModule = new Dependencies['Example Module'];
2018-02-13 17:26:20 +01:00
Logger.log(`2+4=${exampleModule.add(2, 4)}`);
2018-01-31 09:32:20 +01:00
return true;
}
onStop() {
2018-02-12 00:04:07 +01:00
Events.unsubscribeAll();
Logger.log('onStop');
2018-02-13 18:07:51 +01:00
console.log(this.showSettingsModal());
2018-01-23 14:19:55 +01:00
return true;
2018-01-16 02:45:23 +01:00
}
2018-02-12 00:04:07 +01:00
eventTest(e) {
Logger.log(e);
}
2018-02-12 16:20:27 +01:00
2018-02-13 17:43:44 +01:00
get bridge() {
2018-02-12 23:49:44 +01:00
return {
test1: this.test1.bind(this),
test2: this.test2.bind(this)
};
}
test1() { return 'It works!'; }
test2() { return 'This works too!'; }
2018-02-12 16:20:27 +01:00
settingChanged(category, setting_id, value) {
if (!this.enabled) return;
Logger.log(`${category}/${setting_id} changed to ${value}`);
}
settingsChanged(settings) {
if (!this.enabled) return;
Logger.log([ 'Settings updated', settings ]);
}
2018-01-16 02:45:23 +01:00
}
2018-02-12 16:20:27 +01:00
}