forked from Galactic/galactic-bot
inhibitors
This commit is contained in:
parent
b8042f5bde
commit
dc30103454
38
src/structure/components/inhibitors/ChannelIgnore.js
Normal file
38
src/structure/components/inhibitors/ChannelIgnore.js
Normal file
@ -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;
|
24
src/structure/components/inhibitors/ClientPermissions.js
Normal file
24
src/structure/components/inhibitors/ClientPermissions.js
Normal file
@ -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;
|
25
src/structure/components/inhibitors/GuildOnly.js
Normal file
25
src/structure/components/inhibitors/GuildOnly.js
Normal file
@ -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;
|
26
src/structure/components/inhibitors/Restricted.js
Normal file
26
src/structure/components/inhibitors/Restricted.js
Normal file
@ -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;
|
50
src/structure/components/inhibitors/Throttle.js
Normal file
50
src/structure/components/inhibitors/Throttle.js
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user