From b20618ad559d822f9cb671338f05e56a1669409b Mon Sep 17 00:00:00 2001 From: Navy Date: Thu, 21 May 2020 11:51:44 +0300 Subject: [PATCH 1/2] Random bs --- storage/providers/Mariadb.js | 2 +- storage/providers/Mongodb.js | 10 +++++----- .../client/components/commands/developer/Evaluate.js | 4 ++-- structure/client/components/commands/utility/User.js | 2 +- structure/client/components/inhibitors/Throttle.js | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/storage/providers/Mariadb.js b/storage/providers/Mariadb.js index c8e8dd2..bfdd8dc 100644 --- a/storage/providers/Mariadb.js +++ b/storage/providers/Mariadb.js @@ -28,7 +28,7 @@ class MariaDBProvider extends Provider { connection.on('close', data => { // this.manager.logger.log('MariaDB connection closed.', data); - }) + }); }); diff --git a/storage/providers/Mongodb.js b/storage/providers/Mongodb.js index a936917..f80655f 100644 --- a/storage/providers/Mongodb.js +++ b/storage/providers/Mongodb.js @@ -42,7 +42,7 @@ class MongoDBProvider extends Provider { if (!this._initialized) return { error: true, message: 'MongoDB not connected' }; if (!this[request.type]) return { error: true, message: `Invalid request type, got '${request.type}'` }; - if (!request.collection && request.type !== 'stats') return { error: true, message: `You must specify a collection to query!` }; + if (!request.collection && request.type !== 'stats') return { error: true, message: 'You must specify a collection to query!' }; return this[request.type](request); @@ -64,11 +64,11 @@ class MongoDBProvider extends Provider { this.db.stats(options, (error, stats) => { - if (err) return reject(err); + if (error) return reject(error); else { let { db, collections, objects, averageSize: avgObjSize, dataSize } = stats; - return resolve({ db, collections, objects, averageSize, dataSize }); + return resolve({ db, collections, objects, averageSize: avgObjSize, dataSize }); } @@ -81,8 +81,8 @@ class MongoDBProvider extends Provider { if (err) return reject(err); else { - let { index: ns, size, count, averageSize: avgObjSize } = stats; - return resolve({ index, size, count, averageSize }); + let { ns, size, count, averageSize: avgObjSize } = stats; + return resolve({ index: ns, size, count, averageSize: avgObjSize }); } diff --git a/structure/client/components/commands/developer/Evaluate.js b/structure/client/components/commands/developer/Evaluate.js index f0676b4..abdf517 100644 --- a/structure/client/components/commands/developer/Evaluate.js +++ b/structure/client/components/commands/developer/Evaluate.js @@ -25,13 +25,13 @@ class Evaluate extends Command { name: 'log', type: 'BOOLEAN', types: ['FLAG'], - description: "Logs the output in the console." + description: 'Logs the output in the console.' }, { name: 'hide', type: 'BOOLEAN', types: ['FLAG'], - description: "Hides the output from the channel." + description: 'Hides the output from the channel.' } ], showUsage: true diff --git a/structure/client/components/commands/utility/User.js b/structure/client/components/commands/utility/User.js index b1e354d..fa65a31 100644 --- a/structure/client/components/commands/utility/User.js +++ b/structure/client/components/commands/utility/User.js @@ -8,7 +8,7 @@ class UserCommand extends Command { super(client, { name: 'user', module: 'utility', - description: "Display information about user.", + description: 'Display information about user.', guildOnly: true, arguments: [ { diff --git a/structure/client/components/inhibitors/Throttle.js b/structure/client/components/inhibitors/Throttle.js index 543dadd..f52ae18 100644 --- a/structure/client/components/inhibitors/Throttle.js +++ b/structure/client/components/inhibitors/Throttle.js @@ -1,7 +1,7 @@ const { Inhibitor } = require('../../../interfaces/'); const { stripIndents } = require('common-tags'); -class GuildOnly extends Inhibitor { +class Throttle extends Inhibitor { constructor(client) { @@ -47,4 +47,4 @@ class GuildOnly extends Inhibitor { } -module.exports = GuildOnly; \ No newline at end of file +module.exports = Throttle; \ No newline at end of file From 132cbf2891439858201f6b9c918decaa253fda21 Mon Sep 17 00:00:00 2001 From: Navy Date: Fri, 22 May 2020 23:13:47 +0300 Subject: [PATCH 2/2] trying to fix shit --- .../en_us/settings/en_us_moderation.lang | 86 ++++++++++++++ .../en_us/settings/en_us_utility.lang | 86 -------------- structure/client/Resolver.js | 6 + .../components/commands/information/Help.js | 2 +- .../components/commands/utility/Settings.js | 12 +- .../components/observers/CommandHandler.js | 11 +- .../components/settings/moderation/Modlogs.js | 110 ++++++++++++++++++ .../components/settings/moderation/Mute.js | 14 +-- .../settings/utility/GuildPrefix.js | 11 +- .../settings/utility/PermissionType.js | 4 +- structure/extensions/Guild.js | 17 ++- structure/interfaces/Setting.js | 4 +- 12 files changed, 244 insertions(+), 119 deletions(-) create mode 100644 language/languages/en_us/settings/en_us_moderation.lang create mode 100644 structure/client/components/settings/moderation/Modlogs.js diff --git a/language/languages/en_us/settings/en_us_moderation.lang b/language/languages/en_us/settings/en_us_moderation.lang new file mode 100644 index 0000000..6e5f75e --- /dev/null +++ b/language/languages/en_us/settings/en_us_moderation.lang @@ -0,0 +1,86 @@ +//modlogs setting + +[S_MODLOGS_DESCRIPTION] +Define the channel to which moderation logs are sent. The setting also allows you to exclude types of actions from being logged in the channel. + +[S_MODLOGS_CHANNEL404] +{val} does not resolve into a channel. + +[S_MODLOGS_CHANNEL_SUCCESS] +Successfully set the modlogs channel to {channel}. + +[S_MODLOGS_EXCLUDE404] +Missing arguments. + +//mute Setting + +[S_MUTE_DESCRIPTION] +Assign or create a muted role and choose mute functionality for your guild. +__Mute Types__ +**`0`:** Mutes only add/remove the muted role. *(default)* +**`1`:** Mutes remove all roles except for the muted role. +**`2`:** Mutes remove all roles, does not require a muted role. + +[S_MUTE_TYPENAN] +The argument provided is not a number! The available types are: `0`, `1`, or `2`. +View `{prefix}setting mute` for more help. + +[S_MUTE_TYPEINVALID] +The argument provided is not a valid type! The available types are: `0`, `1`, or `2`. +View `{prefix}setting mute` for more help. + +[S_MUTE_TYPESUCCESS] +Successfully set the **mute type** to `{type}`. + +[S_MUTE_TYPESWITCH] +switch({type}) { + case 0: + "Mutes will now *only add/remove* the muted role."; + break; + case 1: + "Mutes will now *remove all roles except for the muted role*, and then add them back once done."; + break; + case 2: + "Mutes will now *remove all roles* and then add them back once done."; + break; +} + +[S_MUTE_ROLEMISSINGPERMISSION] +The bot *must have* the `MANAGE_ROLES` permission to create a new mute role. + +[S_MUTE_ROLEPROMPT] +Found an existing role named **{name}** `({id})`, would you like to use it and update these roles permissions? +Answering no will create a new role with updated permissions. *(__y__es, __n__o)* +This prompt will time out in __30 seconds__. + +[S_MUTE_ROLEPROMPTERROR] +You provided an invalid input, please try again. + +[S_MUTE_ROLECREATEERROR] +The bot encountered an issue while creating a role for the guild. + +[S_MUTE_ROLEMISSING] +Cannot find a specified role with those arguments. +To create a new role, try `{prefix}setting createmute Muted` + +[S_MUTE_ROLESUCCESS] +Successfully {type} the **mute role** to `{role}`. + +[S_MUTE_GENERATEDPERMISSIONS] +**Permissions have been applied to all possible channels.** + +[S_MUTE_UNGENERATEDPERMISSIONS] +**None of the permissions have been changed.** + + +[S_MUTEDROLE_MISSINGPERMISSION] +The bot must have the `MANAGE_ROLES` permission to create a new muted role in the guild. + +[S_MUTEDROLE_ERRORCREATE] +There was an issue creating the muted role for your guild. + +[S_MUTEDROLE_CANNOTFIND] +I cannot find a role name with those arguments. If you would like to create a new one, use the command `{prefix}settings mute create`. + +[S_MUTEDROLE_SUCCESS] +Successfully set the muted role to `{role}`. \ No newline at end of file diff --git a/language/languages/en_us/settings/en_us_utility.lang b/language/languages/en_us/settings/en_us_utility.lang index c529f98..1864f0f 100644 --- a/language/languages/en_us/settings/en_us_utility.lang +++ b/language/languages/en_us/settings/en_us_utility.lang @@ -18,93 +18,7 @@ The guild prefix cannot include spaces. [S_GUILDPREFIX_RESET] Successfully reset the guild prefix to `{prefix}`. -//mute Setting -[S_MUTE_DESCRIPTION] -Assign or create a muted role and choose mute functionality for your guild. -__Mute Types__ -**`0`:** Mutes only add/remove the muted role. *(default)* -**`1`:** Mutes remove all roles except for the muted role. -**`2`:** Mutes remove all roles, does not require a muted role. - -[S_MUTE_TYPENAN] -The argument provided is not a number! The available types are: `0`, `1`, or `2`. -View `{prefix}setting mute` for more help. - -[S_MUTE_TYPEINVALID] -The argument provided is not a valid type! The available types are: `0`, `1`, or `2`. -View `{prefix}setting mute` for more help. - -[S_MUTE_TYPESUCCESS] -Successfully set the **mute type** to `{type}`. - -[S_MUTE_TYPESWITCH] -switch({type}) { - case 0: - "Mutes will now *only add/remove* the muted role."; - break; - case 1: - "Mutes will now *remove all roles except for the muted role*, and then add them back once done."; - break; - case 2: - "Mutes will now *remove all roles* and then add them back once done."; - break; -} - -[S_MUTE_ROLEMISSINGPERMISSION] -The bot *must have* the `MANAGE_ROLES` permission to create a new mute role. - -[S_MUTE_ROLEPROMPT] -Found an existing role named **{name}** `({id})`, would you like to use it and update these roles permissions? -Answering no will create a new role with updated permissions. *(__y__es, __n__o)* -This prompt will time out in __30 seconds__. - -[S_MUTE_ROLEPROMPTERROR] -You provided an invalid input, please try again. - -[S_MUTE_ROLECREATEERROR] -The bot encountered an issue while creating a role for the guild. - -[S_MUTE_ROLEMISSING] -Cannot find a specified role with those arguments. -To create a new role, try `{prefix}setting createmute Muted` - -[S_MUTE_ROLESUCCESS] -Successfully {type} the **mute role** to `{role}`. - -[S_MUTE_GENERATEDPERMISSIONS] -**Permissions have been applied to all possible channels.** - -[S_MUTE_UNGENERATEDPERMISSIONS] -**None of the permissions have been changed.** - - - - - - - - - - - - - - - - - -[S_MUTEDROLE_MISSINGPERMISSION] -The bot must have the `MANAGE_ROLES` permission to create a new muted role in the guild. - -[S_MUTEDROLE_ERRORCREATE] -There was an issue creating the muted role for your guild. - -[S_MUTEDROLE_CANNOTFIND] -I cannot find a role name with those arguments. If you would like to create a new one, use the command `{prefix}settings mute create`. - -[S_MUTEDROLE_SUCCESS] -Successfully set the muted role to `{role}`. //User Settings \ No newline at end of file diff --git a/structure/client/Resolver.js b/structure/client/Resolver.js index 50d5128..27f8720 100644 --- a/structure/client/Resolver.js +++ b/structure/client/Resolver.js @@ -141,8 +141,11 @@ class Resolver { } async resolveUser(resolveable, strict) { + + if (!resolveable) return false; const result = await this.resolveUsers([ resolveable ], strict); return result ? result[0] : false; + } /** @@ -211,6 +214,7 @@ class Resolver { async resolveMember(resolveable, guild, strict) { + if (!resolveable) return false; const result = await this.resolveMembers([ resolveable ], guild, strict); return result ? result[0] : false; @@ -274,6 +278,7 @@ class Resolver { resolveChannel(resolveable, guild, strict) { + if (!resolveable) return false; const result = this.resolveChannels([resolveable], guild, strict); return result ? result[0] : false; @@ -327,6 +332,7 @@ class Resolver { async resolveRole(resolveable, guild, strict) { + if (!resolveable) return false; const result = await this.resolveRoles([resolveable], guild, strict); return result ? result[0] : false; diff --git a/structure/client/components/commands/information/Help.js b/structure/client/components/commands/information/Help.js index 9c359d8..6329282 100644 --- a/structure/client/components/commands/information/Help.js +++ b/structure/client/components/commands/information/Help.js @@ -31,7 +31,7 @@ class HelpCommand extends Command { description: message.format('C_HELP_TEMPLATE', { desc: message.format(result.description), component: result.name.toUpperCase(), - text: message.format(result.example) + text: result.examples.map(ex => `\`{prefix}${result.name} ${ex}\``).join('\n') })//, // fields: [ // { diff --git a/structure/client/components/commands/utility/Settings.js b/structure/client/components/commands/utility/Settings.js index cfce326..40e3bcb 100644 --- a/structure/client/components/commands/utility/Settings.js +++ b/structure/client/components/commands/utility/Settings.js @@ -1,4 +1,4 @@ -const { Command } = require('../../../../interfaces/'); +const { Command } = require('../../../../interfaces'); const { stripIndents } = require('common-tags'); @@ -28,7 +28,11 @@ class SettingsCommand extends Command { default: true } ], - showUsage: true + showUsage: true, + examples: [ + 'prefix !', + 'modlogs #channel' + ] }); this.client = client; @@ -134,13 +138,13 @@ class SettingsCommand extends Command { async _showSetting(message, setting) { const prefix = message.guild.prefix; - let description = stripIndents`\`${prefix}setting ${setting.name}${setting.usage ? ` ${setting.usage}` : ''}\` ${setting.resolve === 'GUILD' ? ' *(guild-only)*' : '*(user-only)*'} + let description = stripIndents`\`${prefix}settings ${setting.name}${setting.usage ? ` ${setting.usage}` : ''}\` ${setting.resolve === 'GUILD' ? ' *(guild-only)*' : '*(user-only)*'} ${message.format(setting.description)}`; if(setting.examples.length > 0) { description += `\n\n**${message.format('GENERAL_EXAMPLES')}**`; for(let example of setting.examples) { - description += `\n\`${prefix}setting ${example}\``; + description += `\n\`${prefix}settings ${example}\``; } } diff --git a/structure/client/components/observers/CommandHandler.js b/structure/client/components/observers/CommandHandler.js index f69bbd5..877470a 100644 --- a/structure/client/components/observers/CommandHandler.js +++ b/structure/client/components/observers/CommandHandler.js @@ -154,7 +154,7 @@ class CommandHandler extends Observer { } - async _parseArguments(args = [], passedArguments = [], guild = null) { //Only need guild parameter if using a resolver type in your arguments e.g. channel, user, member, role + async _parseArguments(args = [], passedArguments = [], guild = null, debug = false) { //Only need guild parameter if using a resolver type in your arguments e.g. channel, user, member, role args = this._getWords(args.join(' ')).map(w=>w[0]); @@ -167,6 +167,10 @@ class CommandHandler extends Observer { let currentArgument = null; for(let i=0; i`${a.name} - ${a.value}`)); + let setting = message.guild._settings.modlogs || { }; + + if (parsedArguments.exclude) { + if (!parsedArguments.exclude.value.length) return { + msg: message.format('S_MODLOGS_EXCLUDE404'), + error: true + } + + } else { + + let [channel] = params; + if (channel === 'reset') { + + setting = {}; + await message.guild._updateSettings({ [this.index]: setting }); + return { + msg: message.format('S_MODLOGS_RESET'), + error: false + }; + + } else { + + channel = message.guild.resolveChannel(channel); + if (!channel) return { + msg: message.format('S_MODLOGS_CHANNEL404', { val: params[0] }), + error: true + }; + + setting.channel = channel.id; + await message.guild._updateSettings({ [this.index]: setting }); return { + msg: message.format('S_MODLOGS_CHANNEL_SUCCESS', { channel: channel.name }), + error: false + }; + + } + + + } + + } + + data(guild) { + return `**Prefix:** \`${guild.prefix}\``; + } + + fields(guild) { + return [ + { + name: 'Channel', + value: guild.resolveChannel(guild._settings[this.index]?.channel) || 'N/A', + inline: true + }, + { + name: 'Excluded types', + value: guild._settings[this.index]?.exclude.join(', ') || 'N/A', + inline: true + } + ]; + } + +} + +module.exports = Modlogs; \ No newline at end of file diff --git a/structure/client/components/settings/moderation/Mute.js b/structure/client/components/settings/moderation/Mute.js index ea1dfcf..3da571f 100644 --- a/structure/client/components/settings/moderation/Mute.js +++ b/structure/client/components/settings/moderation/Mute.js @@ -30,7 +30,7 @@ class MuteSetting extends Setting { default: true } ], - usage: "[test] ", + usage: '[test] ', examples: [ 'muterole Muted', 'mutetype 1', @@ -162,20 +162,16 @@ class MuteSetting extends Setting { return role; } - data(guild) { - return `**Muted Role:** ${guild._settings[this.index].role ? `<@&${guild._settings[this.index].role}>` : 'N/A'}\n**Mute Type:** \`${guild._setting[this.index].type}\``; - } - fields(guild) { return [ { - name: "Muted Role", - value: guild._settings[this.index].role ? `<@&${guild._settings[this.index].role}>` : '`N/A`', + name: '》Muted Role', + value: guild._settings[this.index]?.role ? `<@&${guild._settings[this.index].role}>` : '`N/A`', inline: true }, { - name: "Mute Type", - value: `\`${guild._settings[this.index].type}\``, + name: '》Mute Type', + value: `\`${guild._settings[this.index]?.type || 0}\``, inline: true } ]; diff --git a/structure/client/components/settings/utility/GuildPrefix.js b/structure/client/components/settings/utility/GuildPrefix.js index 27bb262..c70d144 100644 --- a/structure/client/components/settings/utility/GuildPrefix.js +++ b/structure/client/components/settings/utility/GuildPrefix.js @@ -39,16 +39,21 @@ class GuildPrefixSetting extends Setting { error: true }; + if (prefix === 'reset') prefix = this.default.prefix; + await message.guild._updateSettings({ [this.index]: prefix }); return { - msg: message.format(`S_GUILDPREFIX_SUCCESS`, { prefix }), + msg: message.format('S_GUILDPREFIX_SUCCESS', { prefix }), error: false }; } - data(guild) { - return `**Prefix:** \`${guild.prefix}\``; + fields(guild) { + return { + name: '》Prefix', + value: `\`${guild.prefix}\`` + }; } diff --git a/structure/client/components/settings/utility/PermissionType.js b/structure/client/components/settings/utility/PermissionType.js index d277daf..6af23d2 100644 --- a/structure/client/components/settings/utility/PermissionType.js +++ b/structure/client/components/settings/utility/PermissionType.js @@ -37,7 +37,7 @@ class PermissionTypeSetting extends Setting { await message.guild._updateSettings({ [this.index]: prefix }); return { - msg: message.format(`S_GUILDPREFIX_SUCCESS`, { prefix }), + msg: message.format('S_GUILDPREFIX_SUCCESS', { prefix }), error: false }; @@ -46,7 +46,7 @@ class PermissionTypeSetting extends Setting { fields(guild) { return [ { - name: "》Prefix", + name: '》Prefix', value: `\`${guild.prefix}\`` } ]; diff --git a/structure/extensions/Guild.js b/structure/extensions/Guild.js index fc3bf85..0573475 100644 --- a/structure/extensions/Guild.js +++ b/structure/extensions/Guild.js @@ -127,34 +127,31 @@ const Guild = Structures.extend('Guild', (Guild) => { async resolveMember(member, strict) { - const [ result ] = await this.resolveMembers([ member ], strict); - return result; + return await this.client.resolver.resolveMembers(member, this, strict); } - async resolveChannels(channels, strict = false) { + resolveChannels(channels, strict = false) { return this.client.resolver.resolveChannels(channels, this, strict); } - async resolveChannel(channel, strict) { + resolveChannel(channel, strict) { - const [ result ] = await this.resolveMembers([ channel ], strict); - return result; + return this.client.resolver.resolveChannel(channel, this, strict); } async resolveRoles(roles, strict = false) { - return this.client.resolver.resolveRoles(roles, this, strict); + return await this.client.resolver.resolveRoles(roles, this, strict); } async resolveRole(role, strict) { - - const [ result ] = await this.resolveRoles([ role ], strict); - return result; + + return await this.client.resolver.resolveRole(role, this, strict); } diff --git a/structure/interfaces/Setting.js b/structure/interfaces/Setting.js index bd24d83..626cdcd 100644 --- a/structure/interfaces/Setting.js +++ b/structure/interfaces/Setting.js @@ -41,8 +41,8 @@ class Setting extends Component { this.client.logger.error(`No handle function found in ${this.moduleResolveable}.`); } - async _parseArguments(params, guild) { - const response = await this.commandHandler._parseArguments(params, this.arguments, guild); + async _parseArguments(params, guild, debug = false) { + const response = await this.commandHandler._parseArguments(params, this.arguments, guild, debug); if(response.error) return response; return { parsedArguments: response.parsedArguments, params: response.newArgs, error: false }; }