diff --git a/src/structure/components/inhibitors/ChannelIgnore.js b/src/structure/components/inhibitors/ChannelIgnore.js new file mode 100644 index 0000000..3d4e5d1 --- /dev/null +++ b/src/structure/components/inhibitors/ChannelIgnore.js @@ -0,0 +1,38 @@ +const { Inhibitor } = require("../../interfaces"); + +class ChannelIgnore extends Inhibitor { + + constructor(client) { + super(client, { + name: 'channelIgnore', + priority: 5, + guild: true, + silent: true + }); + } + + async execute(interaction) { + + const member = await interaction.memberWrapper(); + if (await member.isAdmin()) return super._succeed(); + + const { guild, channel } = interaction; + const settings = await guild.settings(); + const { channels, bypass } = settings.ignore; + const roles = member.roles.cache.map((r) => r.id); + + if (!channels.length) return super._succeed(); + if (channels.includes(channel.id)) { + for (const role of roles) { + if (bypass.includes(role)) return super._succeed(); + } + return super._fail({ error: true, silent: true }); + } + + return super._succeed(); + + } + +} + +module.exports = ChannelIgnore; \ No newline at end of file diff --git a/src/structure/components/inhibitors/ClientPermissions.js b/src/structure/components/inhibitors/ClientPermissions.js new file mode 100644 index 0000000..1002e99 --- /dev/null +++ b/src/structure/components/inhibitors/ClientPermissions.js @@ -0,0 +1,24 @@ +const { Inhibitor } = require("../../interfaces"); + +class ClientPermissions extends Inhibitor { + + constructor(client) { + super(client, { + name: 'clientPermissions', + priority: 11, + guarded: true, + guild: true + }); + } + + async execute(interaction, command) { + + const missing = interaction.channel.permissionsFor(interaction.guild.me).missing(command.clientPermissions); + if (missing.length) return super._fail({ error: true, missing: missing.join(', '), silent: true }); + return super._succeed(); + + } + +} + +module.exports = ClientPermissions; \ No newline at end of file diff --git a/src/structure/components/inhibitors/GuildOnly.js b/src/structure/components/inhibitors/GuildOnly.js new file mode 100644 index 0000000..5aaf7e1 --- /dev/null +++ b/src/structure/components/inhibitors/GuildOnly.js @@ -0,0 +1,25 @@ +const { Inhibitor } = require("../../interfaces"); + +class GuildOnly extends Inhibitor { + + constructor(client) { + + super(client, { + name: 'guildOnly', + priority: 12, + guarded: true + }); + + } + + execute(interaction, command) { + if (command.guildOnly && !interaction.guild) { + return super._fail(); + } + return super._succeed(); + + } + +} + +module.exports = GuildOnly; \ No newline at end of file diff --git a/src/structure/components/inhibitors/Restricted.js b/src/structure/components/inhibitors/Restricted.js new file mode 100644 index 0000000..49dfc92 --- /dev/null +++ b/src/structure/components/inhibitors/Restricted.js @@ -0,0 +1,26 @@ +const { Inhibitor } = require('../../interfaces/'); + +class Restricted extends Inhibitor { + + constructor(client) { + + super(client, { + name: 'restricted', + priority: 10, + guarded: true + }); + + } + + async execute(interaction, command) { + const user = await interaction.userWrapper(); + if (command.restricted && !user.developer) { + return super._fail(); + } + return super._succeed(); + + } + +} + +module.exports = Restricted; \ No newline at end of file diff --git a/src/structure/components/inhibitors/Throttle.js b/src/structure/components/inhibitors/Throttle.js new file mode 100644 index 0000000..52b4e14 --- /dev/null +++ b/src/structure/components/inhibitors/Throttle.js @@ -0,0 +1,50 @@ +const { Inhibitor } = require('../../interfaces/'); + +class Throttle extends Inhibitor { + + constructor(client) { + + super(client, { + name: 'throttle', + priority: 20 + }); + + } + + async execute(interaction, command) { + + const user = await interaction.userWrapper(); + if (user.developer) return super._succeed(); + const throttle = this.throttleCommand(interaction, command); + + if (throttle) { + throttle.usages++; + if (throttle.usages > command.throttling.usages) { + const remaining = (throttle.start + (command.throttling.duration * 1000) - Date.now()) / 1000; //eslint-disable-line no-extra-parens + return super._fail({ remaining: remaining.toFixed(2) }); + } + } + + return super._succeed(); + + } + + throttleCommand(interaction, command) { + if (!command.throttling) return undefined; + let throttle = command._throttles.get(interaction.author.id); + if (!throttle) { + throttle = { + start: Date.now(), + usages: 0, + timeout: this.client.setTimeout(() => { + command._throttles.delete(interaction.author.id); + }, command.throttling.duration * 1000) + }; + command._throttles.set(interaction.author.id, throttle); + } + return throttle; + } + +} + +module.exports = Throttle; \ No newline at end of file