nv-kit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +0 -0
  2. package/package.json +16 -0
  3. package/src/command-handler/ChannelCommands.js +52 -0
  4. package/src/command-handler/Command.js +21 -0
  5. package/src/command-handler/CommandHandler.js +219 -0
  6. package/src/command-handler/CustomCommands.js +74 -0
  7. package/src/command-handler/DisabledCommands.js +50 -0
  8. package/src/command-handler/PrefixHandler.js +50 -0
  9. package/src/command-handler/SlashCommands.js +111 -0
  10. package/src/command-handler/commands/channelcommand.js +69 -0
  11. package/src/command-handler/commands/customcommand.js +28 -0
  12. package/src/command-handler/commands/delcustomcmd.js +21 -0
  13. package/src/command-handler/commands/prefix.js +21 -0
  14. package/src/command-handler/commands/requiredpermissions.js +110 -0
  15. package/src/command-handler/commands/requiredroles.js +112 -0
  16. package/src/command-handler/commands/togglecommand.js +42 -0
  17. package/src/command-handler/validations/run-time/argument-count.js +24 -0
  18. package/src/command-handler/validations/run-time/channel-command.js +26 -0
  19. package/src/command-handler/validations/run-time/disabled-commands.js +21 -0
  20. package/src/command-handler/validations/run-time/guild-only.js +15 -0
  21. package/src/command-handler/validations/run-time/has-permissions.js +50 -0
  22. package/src/command-handler/validations/run-time/has-roles.js +43 -0
  23. package/src/command-handler/validations/run-time/owner-only.js +12 -0
  24. package/src/command-handler/validations/run-time/test-only.js +10 -0
  25. package/src/command-handler/validations/runtime/argument-count.js +24 -0
  26. package/src/command-handler/validations/runtime/channel-command.js +26 -0
  27. package/src/command-handler/validations/runtime/disabled-commands.js +21 -0
  28. package/src/command-handler/validations/runtime/guild-only.js +15 -0
  29. package/src/command-handler/validations/runtime/has-permissions.js +50 -0
  30. package/src/command-handler/validations/runtime/has-roles.js +43 -0
  31. package/src/command-handler/validations/runtime/owner-only.js +12 -0
  32. package/src/command-handler/validations/runtime/test-only.js +10 -0
  33. package/src/command-handler/validations/syntax/bad-cooldown-types.js +28 -0
  34. package/src/command-handler/validations/syntax/callback-required.js +9 -0
  35. package/src/command-handler/validations/syntax/defer-reply.js +14 -0
  36. package/src/command-handler/validations/syntax/desc-required-for-slash.js +11 -0
  37. package/src/command-handler/validations/syntax/owner-only-without-owners.js +11 -0
  38. package/src/command-handler/validations/syntax/permissions-without-guild-only.js +10 -0
  39. package/src/command-handler/validations/syntax/test-without-server.js +11 -0
  40. package/src/event-handler/EventHandler.js +87 -0
  41. package/src/event-handler/events/interactionCreate/isButton/test.js +3 -0
  42. package/src/event-handler/events/interactionCreate/isCommand/slash-commands.js +77 -0
  43. package/src/event-handler/events/messageCreate/isHuman/legacy-commands.js +36 -0
  44. package/src/index.js +90 -0
  45. package/src/models/channel-commands-schema.js +16 -0
  46. package/src/models/cooldown-schema.js +16 -0
  47. package/src/models/custom-command-schema.js +16 -0
  48. package/src/models/disabled-commands-schema.js +12 -0
  49. package/src/models/guild-prefix-schema.js +16 -0
  50. package/src/models/required-permissions-schema.js +16 -0
  51. package/src/models/required-roles-schema.js +16 -0
  52. package/src/util/Cooldowns.js +232 -0
  53. package/src/util/FeatureHandler.js +20 -0
  54. package/src/util/get-all-files.js +28 -0
@@ -0,0 +1,21 @@
1
+ const { PermissionFlagsBits } = require('discord.js')
2
+
3
+ module.exports = {
4
+ description: 'Deletes a custom command',
5
+
6
+ minArgs: 1,
7
+ syntaxError: 'Correct syntax: {PREFIX}delCustomCmd {ARGS}',
8
+ expectedArgs: '<command name>',
9
+
10
+ type: 'SLASH',
11
+ guildOnly: true,
12
+ testOnly: true,
13
+
14
+ permissions: [PermissionFlagsBits.Administrator],
15
+
16
+ callback: async ({ instance, text: commandName, guild }) => {
17
+ await instance.commandHandler.customCommands.delete(guild.id, commandName)
18
+
19
+ return `Custom command "${commandName}" has been deleted!`
20
+ },
21
+ }
@@ -0,0 +1,21 @@
1
+ const { PermissionFlagsBits } = require('discord.js')
2
+
3
+ module.exports = {
4
+ description: 'Sets the prefix for this server',
5
+
6
+ minArgs: 1,
7
+ syntaxError: 'Correct syntax: {PREFIX}prefix {ARGS}',
8
+ expectedArgs: '<prefix>',
9
+
10
+ type: 'BOTH',
11
+ testOnly: true,
12
+ guildOnly: true,
13
+
14
+ permissions: [PermissionFlagsBits.Administrator],
15
+
16
+ callback: ({ instance, guild, text: prefix }) => {
17
+ instance.commandHandler.prefixHandler.set(guild.id, prefix)
18
+
19
+ return `Set "${prefix}" as the command prefix for this server.`
20
+ },
21
+ }
@@ -0,0 +1,110 @@
1
+ const {
2
+ PermissionFlagsBits,
3
+ ApplicationCommandOptionType,
4
+ } = require('discord.js')
5
+ const requiredPermissions = require('../../models/required-permissions-schema')
6
+
7
+ const clearAllPermissions = 'Clear All Permissions'
8
+
9
+ module.exports = {
10
+ description: 'Sets what commands require what permissions',
11
+
12
+ type: 'SLASH',
13
+ testOnly: true,
14
+ guildOnly: true,
15
+
16
+ permissions: [PermissionFlagsBits.Administrator],
17
+
18
+ options: [
19
+ {
20
+ name: 'command',
21
+ description: 'The command to set permissions to',
22
+ type: ApplicationCommandOptionType.String,
23
+ required: true,
24
+ autocomplete: true,
25
+ },
26
+ {
27
+ name: 'permission',
28
+ description: 'The permission to set for the command',
29
+ type: ApplicationCommandOptionType.String,
30
+ required: false,
31
+ autocomplete: true,
32
+ },
33
+ ],
34
+
35
+ autocomplete: (_, command, arg) => {
36
+ if (arg === 'command') {
37
+ return [...command.instance.commandHandler.commands.keys()]
38
+ } else if (arg === 'permission') {
39
+ return [clearAllPermissions, ...Object.keys(PermissionFlagsBits)]
40
+ }
41
+ },
42
+
43
+ callback: async ({ instance, guild, args }) => {
44
+ const [commandName, permission] = args
45
+
46
+ const command = instance.commandHandler.commands.get(commandName)
47
+ if (!command) {
48
+ return `The command "${commandName}" does not exist.`
49
+ }
50
+
51
+ const _id = `${guild.id}-${command.commandName}`
52
+
53
+ if (!permission) {
54
+ const document = await requiredPermissions.findById(_id)
55
+
56
+ const permissions =
57
+ document && document.permissions?.length
58
+ ? document.permissions.join(', ')
59
+ : 'None.'
60
+
61
+ return `Here are the permissions for "${commandName}": ${permissions}`
62
+ }
63
+
64
+ if (permission === clearAllPermissions) {
65
+ await requiredPermissions.deleteOne({ _id })
66
+
67
+ return `The command "${commandName}" no longer requires any permissions.`
68
+ }
69
+
70
+ const alreadyExists = await requiredPermissions.findOne({
71
+ _id,
72
+ permissions: {
73
+ $in: [permission],
74
+ },
75
+ })
76
+
77
+ if (alreadyExists) {
78
+ await requiredPermissions.findOneAndUpdate(
79
+ {
80
+ _id,
81
+ },
82
+ {
83
+ _id,
84
+ $pull: {
85
+ permissions: permission,
86
+ },
87
+ }
88
+ )
89
+
90
+ return `The command "${commandName}" no longer requires the permission "${permission}"`
91
+ }
92
+
93
+ await requiredPermissions.findOneAndUpdate(
94
+ {
95
+ _id,
96
+ },
97
+ {
98
+ _id,
99
+ $addToSet: {
100
+ permissions: permission,
101
+ },
102
+ },
103
+ {
104
+ upsert: true,
105
+ }
106
+ )
107
+
108
+ return `The command "${commandName}" now requires the permission "${permission}"`
109
+ },
110
+ }
@@ -0,0 +1,112 @@
1
+ const {
2
+ PermissionFlagsBits,
3
+ ApplicationCommandOptionType,
4
+ } = require('discord.js')
5
+ const requiredroles = require('../../models/required-roles-schema')
6
+
7
+ module.exports = {
8
+ description: 'Sets what commands require what roles',
9
+
10
+ type: 'SLASH',
11
+ testOnly: true,
12
+ guildOnly: true,
13
+
14
+ roles: [PermissionFlagsBits.Administrator],
15
+
16
+ options: [
17
+ {
18
+ name: 'command',
19
+ description: 'The command to set roles to',
20
+ type: ApplicationCommandOptionType.String,
21
+ required: true,
22
+ autocomplete: true,
23
+ },
24
+ {
25
+ name: 'role',
26
+ description: 'The role to set for the command',
27
+ type: ApplicationCommandOptionType.Role,
28
+ required: false,
29
+ },
30
+ ],
31
+
32
+ autocomplete: (_, command) => {
33
+ return [...command.instance.commandHandler.commands.keys()]
34
+ },
35
+
36
+ callback: async ({ instance, guild, args }) => {
37
+ const [commandName, role] = args
38
+
39
+ const command = instance.commandHandler.commands.get(commandName)
40
+ if (!command) {
41
+ return `The command "${commandName}" does not exist.`
42
+ }
43
+
44
+ const _id = `${guild.id}-${command.commandName}`
45
+
46
+ if (!role) {
47
+ const document = await requiredroles.findById(_id)
48
+
49
+ const roles =
50
+ document && document.roles?.length
51
+ ? document.roles.map((roleId) => `<@&${roleId}>`)
52
+ : 'None.'
53
+
54
+ return {
55
+ content: `Here are the roles for "${commandName}": ${roles}`,
56
+ allowedMentions: {
57
+ roles: [],
58
+ },
59
+ }
60
+ }
61
+
62
+ const alreadyExists = await requiredroles.findOne({
63
+ _id,
64
+ roles: {
65
+ $in: [role],
66
+ },
67
+ })
68
+
69
+ if (alreadyExists) {
70
+ await requiredroles.findOneAndUpdate(
71
+ {
72
+ _id,
73
+ },
74
+ {
75
+ _id,
76
+ $pull: {
77
+ roles: role,
78
+ },
79
+ }
80
+ )
81
+
82
+ return {
83
+ content: `The command "${commandName}" no longer requires the role <@&${role}>`,
84
+ allowedMentions: {
85
+ roles: [],
86
+ },
87
+ }
88
+ }
89
+
90
+ await requiredroles.findOneAndUpdate(
91
+ {
92
+ _id,
93
+ },
94
+ {
95
+ _id,
96
+ $addToSet: {
97
+ roles: role,
98
+ },
99
+ },
100
+ {
101
+ upsert: true,
102
+ }
103
+ )
104
+
105
+ return {
106
+ content: `The command "${commandName}" now requires the role <@&${role}>`,
107
+ allowedMentions: {
108
+ roles: [],
109
+ },
110
+ }
111
+ },
112
+ }
@@ -0,0 +1,42 @@
1
+ const {
2
+ PermissionFlagsBits,
3
+ ApplicationCommandOptionType,
4
+ } = require('discord.js')
5
+
6
+ module.exports = {
7
+ description: 'Toggles a command on or off for your guild',
8
+
9
+ type: 'SLASH',
10
+ guildOnly: true,
11
+ testOnly: true,
12
+
13
+ permissions: [PermissionFlagsBits.Administrator],
14
+
15
+ options: [
16
+ {
17
+ name: 'command',
18
+ description: 'The command to toggle on or off',
19
+ type: ApplicationCommandOptionType.String,
20
+ required: true,
21
+ autocomplete: true,
22
+ },
23
+ ],
24
+
25
+ autocomplete: (_, command) => {
26
+ return [...command.instance.commandHandler.commands.keys()]
27
+ },
28
+
29
+ callback: async ({ instance, guild, text: commandName, interaction }) => {
30
+ const { disabledCommands } = instance.commandHandler
31
+
32
+ if (disabledCommands.isDisabled(guild.id, commandName)) {
33
+ await disabledCommands.enable(guild.id, commandName)
34
+
35
+ interaction.reply(`Command "${commandName}" has been enabled`)
36
+ } else {
37
+ await disabledCommands.disable(guild.id, commandName)
38
+
39
+ interaction.reply(`Command "${commandName}" has been disabled`)
40
+ }
41
+ },
42
+ }
@@ -0,0 +1,24 @@
1
+ module.exports = (command, usage, prefix) => {
2
+ const {
3
+ minArgs = 0,
4
+ maxArgs = -1,
5
+ correctSyntax,
6
+ expectedArgs = '',
7
+ } = command.commandObject
8
+ const { length } = usage.args
9
+
10
+ if (length < minArgs || (length > maxArgs && maxArgs !== -1)) {
11
+ const text = correctSyntax
12
+ .replace('{PREFIX}', prefix)
13
+ .replace('{ARGS}', expectedArgs)
14
+
15
+ const { message, interaction } = usage
16
+
17
+ if (message) message.reply(text)
18
+ else if (interaction) interaction.reply(text)
19
+
20
+ return false
21
+ }
22
+
23
+ return true
24
+ }
@@ -0,0 +1,26 @@
1
+ module.exports = async (command, usage) => {
2
+ const { commandName, instance } = command
3
+ const { guild, channel, message, interaction } = usage
4
+
5
+ if (!guild) {
6
+ return true
7
+ }
8
+
9
+ const availableChannels =
10
+ await instance.commandHandler.channelCommands.getAvailableChannels(
11
+ guild.id,
12
+ commandName
13
+ )
14
+
15
+ if (availableChannels.length && !availableChannels.includes(channel.id)) {
16
+ const channelNames = availableChannels.map((c) => `<#${c}> `)
17
+ const reply = `You can only run this command inside of the following channels: ${channelNames}.`
18
+
19
+ if (message) message.reply(reply)
20
+ else if (interaction) interaction.reply(reply)
21
+
22
+ return false
23
+ }
24
+
25
+ return true
26
+ }
@@ -0,0 +1,21 @@
1
+ module.exports = async (command, usage) => {
2
+ const { commandName, instance } = command
3
+ const { guild, message, interaction } = usage
4
+
5
+ if (!guild) {
6
+ return true
7
+ }
8
+
9
+ if (
10
+ instance.commandHandler.disabledCommands.isDisabled(guild.id, commandName)
11
+ ) {
12
+ const text = 'This command is disabled'
13
+
14
+ if (message) message.channel.send(text)
15
+ else if (interaction) interaction.reply(text)
16
+
17
+ return false
18
+ }
19
+
20
+ return true
21
+ }
@@ -0,0 +1,15 @@
1
+ module.exports = (command, usage) => {
2
+ const { guildOnly } = command.commandObject
3
+ const { guild, message, interaction } = usage
4
+
5
+ if (guildOnly === true && !guild) {
6
+ const text = 'This command can only be ran within a guild/server.'
7
+
8
+ if (message) message.reply(text)
9
+ else if (interaction) interaction.reply(text)
10
+
11
+ return false
12
+ }
13
+
14
+ return true
15
+ }
@@ -0,0 +1,50 @@
1
+ const { PermissionFlagsBits } = require('discord.js')
2
+ const requiredPermissions = require('../../../models/required-permissions-schema')
3
+
4
+ const keys = Object.keys(PermissionFlagsBits)
5
+
6
+ module.exports = async (command, usage) => {
7
+ const { permissions = [] } = command.commandObject
8
+ const { guild, member, message, interaction } = usage
9
+
10
+ if (!member) {
11
+ return true
12
+ }
13
+
14
+ const document = await requiredPermissions.findById(
15
+ `${guild.id}-${command.commandName}`
16
+ )
17
+ if (document) {
18
+ for (const permission of document.permissions) {
19
+ if (!permissions.includes(permission)) {
20
+ permissions.push(permission)
21
+ }
22
+ }
23
+ }
24
+
25
+ if (permissions.length) {
26
+ const missingPermissions = []
27
+
28
+ for (const permission of permissions) {
29
+ if (!member.permissions.has(permission)) {
30
+ const permissionName = keys.find(
31
+ (key) => key === permission || PermissionFlagsBits[key] === permission
32
+ )
33
+ missingPermissions.push(permissionName)
34
+ }
35
+ }
36
+
37
+ if (missingPermissions.length) {
38
+ const text = `You are missing the following permissions: "${missingPermissions.join(
39
+ '", "'
40
+ )}"`
41
+
42
+ if (message) message.reply(text)
43
+ else if (interaction) interaction.reply(text)
44
+
45
+ return false
46
+ }
47
+ }
48
+
49
+ return true
50
+ }
@@ -0,0 +1,43 @@
1
+ const requiredRoles = require('../../../models/required-roles-schema')
2
+
3
+ module.exports = async (command, usage) => {
4
+ const { guild, member, message, interaction } = usage
5
+
6
+ if (!member) {
7
+ return true
8
+ }
9
+
10
+ const _id = `${guild.id}-${command.commandName}`
11
+ const document = await requiredRoles.findById(_id)
12
+
13
+ if (document) {
14
+ let hasRole = false
15
+
16
+ for (const roleId of document.roles) {
17
+ if (member.roles.cache.has(roleId)) {
18
+ hasRole = true
19
+ break
20
+ }
21
+ }
22
+
23
+ if (hasRole) {
24
+ return true
25
+ }
26
+
27
+ const reply = {
28
+ content: `You need one of these roles: ${document.roles.map(
29
+ (roleId) => `<@&${roleId}>`
30
+ )}`,
31
+ allowedMentions: {
32
+ roles: [],
33
+ },
34
+ }
35
+
36
+ if (message) message.reply(reply)
37
+ else if (interaction) interaction.reply(reply)
38
+
39
+ return false
40
+ }
41
+
42
+ return true
43
+ }
@@ -0,0 +1,12 @@
1
+ module.exports = (command, usage) => {
2
+ const { instance, commandObject } = command
3
+ const { botOwners } = instance
4
+ const { ownerOnly } = commandObject
5
+ const { user } = usage
6
+
7
+ if (ownerOnly === true && !botOwners.includes(user.id)) {
8
+ return false
9
+ }
10
+
11
+ return true
12
+ }
@@ -0,0 +1,10 @@
1
+ module.exports = (command, usage) => {
2
+ const { instance, commandObject } = command
3
+ const { guild } = usage
4
+
5
+ if (commandObject.testOnly !== true) {
6
+ return true
7
+ }
8
+
9
+ return instance.testServers.includes(guild?.id)
10
+ }
@@ -0,0 +1,24 @@
1
+ module.exports = (command, usage, prefix) => {
2
+ const {
3
+ minArgs = 0,
4
+ maxArgs = -1,
5
+ correctSyntax,
6
+ expectedArgs = '',
7
+ } = command.commandObject
8
+ const { length } = usage.args
9
+
10
+ if (length < minArgs || (length > maxArgs && maxArgs !== -1)) {
11
+ const text = correctSyntax
12
+ .replace('{PREFIX}', prefix)
13
+ .replace('{ARGS}', expectedArgs)
14
+
15
+ const { message, interaction } = usage
16
+
17
+ if (message) message.reply(text)
18
+ else if (interaction) interaction.reply(text)
19
+
20
+ return false
21
+ }
22
+
23
+ return true
24
+ }
@@ -0,0 +1,26 @@
1
+ module.exports = async (command, usage) => {
2
+ const { commandName, instance } = command
3
+ const { guild, channel, message, interaction } = usage
4
+
5
+ if (!guild) {
6
+ return true
7
+ }
8
+
9
+ const availableChannels =
10
+ await instance.commandHandler.channelCommands.getAvailableChannels(
11
+ guild.id,
12
+ commandName
13
+ )
14
+
15
+ if (availableChannels.length && !availableChannels.includes(channel.id)) {
16
+ const channelNames = availableChannels.map((c) => `<#${c}> `)
17
+ const reply = `You can only run this command inside of the following channels: ${channelNames}.`
18
+
19
+ if (message) message.reply(reply)
20
+ else if (interaction) interaction.reply(reply)
21
+
22
+ return false
23
+ }
24
+
25
+ return true
26
+ }
@@ -0,0 +1,21 @@
1
+ module.exports = async (command, usage) => {
2
+ const { commandName, instance } = command
3
+ const { guild, message, interaction } = usage
4
+
5
+ if (!guild) {
6
+ return true
7
+ }
8
+
9
+ if (
10
+ instance.commandHandler.disabledCommands.isDisabled(guild.id, commandName)
11
+ ) {
12
+ const text = 'This command is disabled'
13
+
14
+ if (message) message.channel.send(text)
15
+ else if (interaction) interaction.reply(text)
16
+
17
+ return false
18
+ }
19
+
20
+ return true
21
+ }
@@ -0,0 +1,15 @@
1
+ module.exports = (command, usage) => {
2
+ const { guildOnly } = command.commandObject
3
+ const { guild, message, interaction } = usage
4
+
5
+ if (guildOnly === true && !guild) {
6
+ const text = 'This command can only be ran within a guild/server.'
7
+
8
+ if (message) message.reply(text)
9
+ else if (interaction) interaction.reply(text)
10
+
11
+ return false
12
+ }
13
+
14
+ return true
15
+ }
@@ -0,0 +1,50 @@
1
+ const { PermissionFlagsBits } = require('discord.js')
2
+ const requiredPermissions = require('../../../models/required-permissions-schema')
3
+
4
+ const keys = Object.keys(PermissionFlagsBits)
5
+
6
+ module.exports = async (command, usage) => {
7
+ const { permissions = [] } = command.commandObject
8
+ const { guild, member, message, interaction } = usage
9
+
10
+ if (!member) {
11
+ return true
12
+ }
13
+
14
+ const document = await requiredPermissions.findById(
15
+ `${guild.id}-${command.commandName}`
16
+ )
17
+ if (document) {
18
+ for (const permission of document.permissions) {
19
+ if (!permissions.includes(permission)) {
20
+ permissions.push(permission)
21
+ }
22
+ }
23
+ }
24
+
25
+ if (permissions.length) {
26
+ const missingPermissions = []
27
+
28
+ for (const permission of permissions) {
29
+ if (!member.permissions.has(permission)) {
30
+ const permissionName = keys.find(
31
+ (key) => key === permission || PermissionFlagsBits[key] === permission
32
+ )
33
+ missingPermissions.push(permissionName)
34
+ }
35
+ }
36
+
37
+ if (missingPermissions.length) {
38
+ const text = `You are missing the following permissions: "${missingPermissions.join(
39
+ '", "'
40
+ )}"`
41
+
42
+ if (message) message.reply(text)
43
+ else if (interaction) interaction.reply(text)
44
+
45
+ return false
46
+ }
47
+ }
48
+
49
+ return true
50
+ }