inhibitors

This commit is contained in:
Erik 2022-04-21 11:14:12 +03:00
parent b8042f5bde
commit dc30103454
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
5 changed files with 163 additions and 0 deletions

View 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;

View 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;

View 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;

View 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;

View 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;