diff --git a/src/middleware/Logger.js b/src/middleware/Logger.js index 900d37a..56a3573 100644 --- a/src/middleware/Logger.js +++ b/src/middleware/Logger.js @@ -4,7 +4,6 @@ const path = require('path'); const fs = require('fs'); const Util = require('../Util.js'); -const { runInThisContext } = require('vm'); const Constants = { Types: [ diff --git a/src/structure/DiscordClient.js b/src/structure/DiscordClient.js index 4d2968d..4f99ef1 100644 --- a/src/structure/DiscordClient.js +++ b/src/structure/DiscordClient.js @@ -1,7 +1,7 @@ const { Client } = require('discord.js'); const { Logger, Intercom, EventHooker, LocaleLoader, Registry, Dispatcher, Resolver } = require('./client/'); -const { Observer, Command } = require('./interfaces/'); +const { Observer, Command, Setting } = require('./interfaces/'); const StorageManager = require('./storage/StorageManager.js'); const { DefaultGuild } = require('../constants/'); diff --git a/src/structure/components/commands/administration/SettingCommand.js b/src/structure/components/commands/administration/SettingCommand.js new file mode 100644 index 0000000..61f004e --- /dev/null +++ b/src/structure/components/commands/administration/SettingCommand.js @@ -0,0 +1,96 @@ +const { InteractionCollector } = require('discord.js'); + +const { SlashCommand, CommandOption } = require('../../../interfaces/'); + +class SettingCommand extends SlashCommand { + + constructor(client) { + + super(client, { + name: 'setting', + description: "[DEV] Invoke to display a settings menu.", + module: 'administration', + options: [ + new CommandOption({ + name: 'category', + description: "Select a category to view settings for.", + type: 'STRING', + choices: [ + { + name: 'Administration', + value: 'administrator' + }, + { + name: 'Moderation', + value: 'moderation' + }, + { + name: 'Utility', + value: 'utility' + } + ], + required: true + }) + ] + }); + + } + + async execute(thing, options) { + + const settings = this.client.registry.components + .filter((c) => c._type === 'setting' && c.module.name === options.category.value) + + if(settings.size === 0) { + return thing.reply({ content: "Could not find any settings in that category." }); + } + + const selectMenu = { + type: 'SELECT_MENU', + custom_id: 'setting', //eslint-disable-line camelcase + placeholder: 'Settings', + options: settings.map((s) => { + return { + label: s.display, + value: s.name, + description: s.description, + emoji: s.emoji + }; + }) + }; + + const message = await thing.reply({ + content: 'Choose a setting.', + components: [ + { + type: 'ACTION_ROW', + components: [ + selectMenu + ] + } + ] + }); + + new InteractionCollector(this.client, { + channel: thing.channel, + message + }).on('collect', (interaction) => { + if(interaction.componentType === 'SELECT_MENU' && interaction.customId === 'setting') { + const setting = this.client.registry.components.get(`setting:${interaction.values[0]}`); + return setting.takeItFromHere(thing, selectMenu); + } + }) + + + + + + + + // console.log(this.module); + + } + +} + +module.exports = SettingCommand; \ No newline at end of file diff --git a/src/structure/components/commands/administration/SettingsCommand.js b/src/structure/components/commands/administration/SettingsCommand.js index efd6fb4..982875b 100644 --- a/src/structure/components/commands/administration/SettingsCommand.js +++ b/src/structure/components/commands/administration/SettingsCommand.js @@ -9,12 +9,99 @@ class SettingsCommand extends SlashCommand { module: 'administration', options: [ new CommandOption({ - name: 'category', - description: "Select a category to view settings for.", + name: 'moderation', + description: '', type: 'SUB_COMMAND_GROUP', options: [ new CommandOption({ - type: 'SUB_COMMAND' + name: 'wordfilter', + description: '', + type: 'SUB_COMMAND', + options: [ + new CommandOption({ + name: 'option', + description: '', + required: true, + type: 'STRING', + choices: [{ + name: 'fuzzy', value: 'fuzzy' + }, { + name: 'explicit', value: 'explicit' + }, { + name: 'regex', value: 'regex' + }] + }), + new CommandOption({ + name: 'value', + description: '', + required: true, + type: 'STRING' + }), + new CommandOption({ + name: 'method', + description: '', + required: false, + type: 'STRING', + choices: [{ + name: 'add', + value: 'add' + }, { + name: 'delete', + value: 'delete' + }, { + name: 'set', + value: 'set' + }, { + name: 'reset', + value: 'reset' + }] + }) + ] + }), + new CommandOption({ + name: 'linkfilter', + description: '', + type: 'SUB_COMMAND', + options: [ + new CommandOption({ + name: 'option', + description: '', + required: true, + type: 'STRING', + choices: [{ + name: 'fuzzy', value: 'fuzzy' + }, { + name: 'explicit', value: 'explicit' + }, { + name: 'regex', value: 'regex' + }] + }), + new CommandOption({ + name: 'method', + description: '', + required: false, + type: 'STRING', + choices: [{ + name: 'add', + value: 'add' + }, { + name: 'delete', + value: 'delete' + }, { + name: 'set', + value: 'set' + }, { + name: 'reset', + value: 'reset' + }] + }), + new CommandOption({ + name: 'value', + description: '', + required: false, + type: 'STRING' + }) + ] }) ] }) @@ -23,6 +110,11 @@ class SettingsCommand extends SlashCommand { }); } + // /settings moderation mute method:role submethod:something more value:something + // / settings moderation mute method: length value: something + + // / settings moderation wordfilter option: fuzzy method: add value: word1 word2 word3 + async execute(thing, options) { diff --git a/src/structure/components/settings/moderation/MuteSetting.js b/src/structure/components/settings/moderation/MuteSetting.js index cbd737c..7a0dd52 100644 --- a/src/structure/components/settings/moderation/MuteSetting.js +++ b/src/structure/components/settings/moderation/MuteSetting.js @@ -6,7 +6,91 @@ class MuteSetting extends Setting { super(client, { name: 'mute', - description: 'uhhhhh' + description: 'Assign a mute role or configure mute type.', + module: 'moderation', + display: 'Mute', + emoji: { + name: 'muted', + id: '853709118988353556' + } + }); + + } + + async takeItFromHere(thing, selectMenu) { + + // console.log(message); + + selectMenu.options.find((o) => o.value === this.name).default = true; + + thing.interaction.editReply({ + components: [ + { + type: 'ACTION_ROW', + components: [ + selectMenu + ] + }, + { + type: 'ACTION_ROW', + components: [ + { + type: 'BUTTON', + label: 'Mute Type', + custom_id: 'null', + style: 'SECONDARY', + disabled: true + }, + { + type: 'BUTTON', + label: 'Addition', + custom_id: '0', + style: 'SUCCESS' + }, + { + type: 'BUTTON', + label: 'Mutually Exclusive', + custom_id: '1', + style: 'SECONDARY' + }, + { + type: 'BUTTON', + label: 'Subtraction', + custom_id: '2', + style: 'SECONDARY' + }, + ] + }, + { + type: 'ACTION_ROW', + components: [ + // { + // type: 'BUTTON', + // label: 'Mute Role', + // custom_id: 'null', + // style: 'PRIMARY', + // disabled: true + // }, + { + type: 'SELECT_MENU', + custom_id: 'role', + placeholder: 'Role', + options: thing.guild.roles.cache.map((r) => { + return { + label: r.name, + value: r.id, + emoji: { + name: 'role', + id: '743563678292639794' + } + }; + }), + minValues: 1, + maxValues: thing.guild.roles.cache.size + } + ] + } + ] }); } diff --git a/src/structure/components/settings/moderation/WordFilterSetting.js b/src/structure/components/settings/moderation/WordFilterSetting.js new file mode 100644 index 0000000..d9e9fba --- /dev/null +++ b/src/structure/components/settings/moderation/WordFilterSetting.js @@ -0,0 +1,26 @@ +const { Setting } = require('../../../interfaces/'); + +class WordFilterSetting extends Setting { + + constructor(client) { + + super(client, { + name: 'wordfilter', + description: 'Configure words for the word filter, etc.', + module: 'moderation', + display: 'Word Filter', + emoji: { + name: 'news', + id: '741725913171099810' + } + }); + + } + + async execute(thing, options) { + + } + +} + +module.exports = WordFilterSetting; \ No newline at end of file diff --git a/src/structure/interfaces/Setting.js b/src/structure/interfaces/Setting.js index b7e03a6..5d1d3cb 100644 --- a/src/structure/interfaces/Setting.js +++ b/src/structure/interfaces/Setting.js @@ -17,6 +17,9 @@ class Setting extends Component { this.description = options.description || ""; + this.display = options.display || options.name; + this.emoji = options.emoji || {}; + } } diff --git a/src/structure/interfaces/Thing.js b/src/structure/interfaces/Thing.js index 56803b3..ee8f777 100644 --- a/src/structure/interfaces/Thing.js +++ b/src/structure/interfaces/Thing.js @@ -23,7 +23,7 @@ class Thing { // delete options.emoji; } - this._pending = this.interaction.reply(options); + this._pending = await this.interaction.reply(options); return this._pending; }