2018-08-22 20:07:06 +02:00
|
|
|
exports.main = (Plugin, { Logger, Settings, Modals, BdMenu: { BdMenuItems }, CommonComponents, DiscordContextMenu, Autocomplete, Api }) => class extends Plugin {
|
2018-05-29 16:39:32 +02:00
|
|
|
async onstart() {
|
2018-03-09 01:46:56 +01:00
|
|
|
this.keybindEvent = this.keybindEvent.bind(this);
|
|
|
|
|
2018-08-22 14:19:15 +02:00
|
|
|
/**
|
|
|
|
* Array setting events.
|
|
|
|
*/
|
|
|
|
|
2018-05-29 16:39:32 +02:00
|
|
|
const arraySetting = this.settings.getSetting('default', 'array-1');
|
|
|
|
Logger.log('Array setting', arraySetting);
|
|
|
|
arraySetting.on('item-added', event => Logger.log('Item', event.item, 'was added to the array setting'));
|
|
|
|
arraySetting.on('item-updated', event => Logger.log('Item', event.item, 'of the array setting was updated', event));
|
|
|
|
arraySetting.on('item-removed', event => Logger.log('Item', event.item, 'removed from the array setting'));
|
2018-03-06 02:43:18 +01:00
|
|
|
|
2018-08-22 14:19:15 +02:00
|
|
|
/**
|
|
|
|
* Keybind setting events.
|
|
|
|
*/
|
|
|
|
|
2018-03-08 03:38:12 +01:00
|
|
|
const keybindSetting = this.settings.getSetting('default', 'keybind-1');
|
|
|
|
Logger.log('Keybind setting', keybindSetting);
|
2018-03-09 01:46:56 +01:00
|
|
|
keybindSetting.on('keybind-activated', this.keybindEvent);
|
2018-03-08 03:38:12 +01:00
|
|
|
|
2018-08-22 14:19:15 +02:00
|
|
|
/**
|
|
|
|
* Settings.
|
|
|
|
*/
|
|
|
|
|
2018-03-07 21:32:04 +01:00
|
|
|
const set = Settings.createSet({
|
|
|
|
text: this.name
|
|
|
|
});
|
2018-03-06 02:43:18 +01:00
|
|
|
const category = await set.addCategory({ id: 'default' });
|
|
|
|
|
|
|
|
const setting = await category.addSetting({
|
|
|
|
id: 'test',
|
|
|
|
type: 'text',
|
|
|
|
text: 'Enter some text',
|
|
|
|
multiline: true // Works better now
|
|
|
|
});
|
|
|
|
|
|
|
|
setting.on('setting-updated', event => Logger.log('Setting was changed to', event.value));
|
|
|
|
|
|
|
|
const scheme = await set.addScheme({
|
|
|
|
id: 'scheme-1',
|
|
|
|
name: 'Test scheme',
|
2018-08-06 03:48:16 +02:00
|
|
|
icon_path: 'scheme-icon.jpg',
|
2018-03-06 02:43:18 +01:00
|
|
|
settings: [{ category: 'default', settings: [{ id: 'test', value: 'Some\npresent\n\nmultiline\n\ntext' }] }]
|
|
|
|
});
|
2018-08-06 03:48:16 +02:00
|
|
|
scheme.setContentPath(__dirname);
|
2018-03-06 02:43:18 +01:00
|
|
|
|
|
|
|
set.on('settings-updated', async updatedSettings => {
|
|
|
|
Logger.log('Updated settings', updatedSettings);
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
|
|
set.setSaved();
|
2018-08-22 14:19:15 +02:00
|
|
|
});
|
2018-03-06 02:43:18 +01:00
|
|
|
|
2018-03-07 21:32:04 +01:00
|
|
|
const setting2 = await category.addSetting({
|
|
|
|
id: 'setting-2',
|
|
|
|
type: 'text',
|
|
|
|
text: 'Enter some text',
|
|
|
|
fullwidth: true
|
|
|
|
});
|
|
|
|
|
|
|
|
setting2.on('setting-updated', event => Logger.log('Setting 2 was changed to', event.value));
|
|
|
|
|
2018-08-22 14:19:15 +02:00
|
|
|
/**
|
|
|
|
* Menu items.
|
|
|
|
*/
|
|
|
|
|
2018-03-07 21:32:04 +01:00
|
|
|
this.menuItem = BdMenuItems.addSettingsSet('Plugins', set, 'Plugin 4');
|
|
|
|
|
|
|
|
this.menuItem2 = BdMenuItems.addVueComponent('Plugins', 'Also Plugin 4', {
|
2018-06-23 00:57:07 +02:00
|
|
|
template: `<settings-wrapper :headertext="plugin.name + ' custom menu panel'">
|
2018-03-07 21:32:04 +01:00
|
|
|
<p style="margin-top: 0; color: #f6f6f7;">Test</p>
|
2018-06-23 00:57:07 +02:00
|
|
|
</settings-wrapper>`,
|
|
|
|
components: {
|
|
|
|
SettingsWrapper: CommonComponents.SettingsWrapper
|
|
|
|
},
|
2018-03-07 21:32:04 +01:00
|
|
|
data() { return {
|
|
|
|
Api, plugin: Api.plugin
|
|
|
|
}; }
|
|
|
|
});
|
2018-08-22 14:19:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Discord context menus.
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.contextMenu = DiscordContextMenu.add([
|
|
|
|
{
|
|
|
|
text: 'Test',
|
|
|
|
onClick: () => Modals.basic('Test', 'Hello from Plugin 4')
|
|
|
|
}
|
|
|
|
]);
|
2018-08-22 20:07:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Autocomplete.
|
|
|
|
* This calls `acsearch` on the controller (the plugin object). You can add multiple autocomplete sets by passing another controller.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Autocomplete.add('|');
|
2018-05-29 16:39:32 +02:00
|
|
|
}
|
2018-03-07 21:32:04 +01:00
|
|
|
|
2018-05-29 16:39:32 +02:00
|
|
|
onstop() {
|
2018-03-09 01:46:56 +01:00
|
|
|
const keybindSetting = this.settings.getSetting('default', 'keybind-1');
|
|
|
|
keybindSetting.off('keybind-activated', this.keybindEvent);
|
|
|
|
|
2018-03-07 21:32:04 +01:00
|
|
|
BdMenuItems.removeAll();
|
2018-08-22 14:19:15 +02:00
|
|
|
DiscordContextMenu.removeAll();
|
2018-08-22 20:07:06 +02:00
|
|
|
Autocomplete.removeAll();
|
2018-05-29 16:39:32 +02:00
|
|
|
}
|
2018-03-09 01:46:56 +01:00
|
|
|
|
|
|
|
keybindEvent(event) {
|
|
|
|
Logger.log('Keybind pressed', event);
|
|
|
|
Modals.basic('Example Plugin 4', 'Test keybind activated.');
|
|
|
|
}
|
2018-08-22 20:07:06 +02:00
|
|
|
|
|
|
|
acsearch(sterm) {
|
|
|
|
// sterm is the text after the prefix
|
|
|
|
Logger.log('Searching for', sterm);
|
|
|
|
|
|
|
|
return {
|
|
|
|
title: ['Plugin 4 autocomplete'],
|
|
|
|
items: [
|
|
|
|
{key: 'Item 1', value: {replaceWith: 'Something to insert when selected'}},
|
|
|
|
{key: 'Item 2', value: {replaceWith: 'Something to insert when selected'}},
|
|
|
|
{key: 'Item 3', value: {replaceWith: 'Something to insert when selected'}},
|
|
|
|
{key: 'Item 4', value: {replaceWith: 'Something to insert when selected'}}
|
|
|
|
]
|
|
|
|
|
|
|
|
// `title` can also be an array - the second item will be white
|
|
|
|
// You can also add `type: 'imagetext'` here and add an `src` property to each item's value to show an image
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
get api() {
|
|
|
|
return Api;
|
|
|
|
}
|
2018-03-06 01:49:10 +01:00
|
|
|
};
|