diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-09-05 17:36:42 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-09-05 17:36:42 -0400 |
commit | 048f99752550c6e03d1990a03cad78f3ac7d73aa (patch) | |
tree | c238ac29b1b526e86bcbc4989036df981c860187 /src/inhibitors | |
parent | 6f8a4d13a490eda7a195d14833c83810f7b5a789 (diff) | |
download | tanzanite-048f99752550c6e03d1990a03cad78f3ac7d73aa.tar.gz tanzanite-048f99752550c6e03d1990a03cad78f3ac7d73aa.tar.bz2 tanzanite-048f99752550c6e03d1990a03cad78f3ac7d73aa.zip |
revamp command permissions, fix permission exploit for some command when used in forum channels, use enums more
Diffstat (limited to 'src/inhibitors')
17 files changed, 125 insertions, 86 deletions
diff --git a/src/inhibitors/blacklist/channelGlobalBlacklist.ts b/src/inhibitors/blacklist/channelGlobalBlacklist.ts index 988931b..a212606 100644 --- a/src/inhibitors/blacklist/channelGlobalBlacklist.ts +++ b/src/inhibitors/blacklist/channelGlobalBlacklist.ts @@ -1,21 +1,21 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class UserGlobalBlacklistInhibitor extends BotInhibitor { public constructor() { - super('channelGlobalBlacklist', { - reason: 'channelGlobalBlacklist', - type: 'post', + super(InhibitorReason.ChannelGlobalBlacklist, { + reason: InhibitorReason.ChannelGlobalBlacklist, + type: InhibitorType.Post, priority: 500 }); } public exec(message: CommandMessage | SlashMessage, command: BotCommand): boolean { if (!message.author || !message.inGuild()) return false; - // do not change to message.author.isOwner() + //! do not change to message.author.isOwner() if (this.client.isOwner(message.author) || this.client.user!.id === message.author.id) return false; if (this.client.cache.global.blacklistedChannels.includes(message.channel!.id) && !command.bypassChannelBlacklist) { void this.client.console.verbose( - 'channelGlobalBlacklist', + InhibitorReason.ChannelGlobalBlacklist, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.` ); return true; diff --git a/src/inhibitors/blacklist/channelGuildBlacklist.ts b/src/inhibitors/blacklist/channelGuildBlacklist.ts index 4bf42d2..ec81666 100644 --- a/src/inhibitors/blacklist/channelGuildBlacklist.ts +++ b/src/inhibitors/blacklist/channelGuildBlacklist.ts @@ -1,17 +1,17 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class ChannelGuildBlacklistInhibitor extends BotInhibitor { public constructor() { - super('channelGuildBlacklist', { - reason: 'channelGuildBlacklist', - type: 'post', + super(InhibitorReason.ChannelGuildBlacklist, { + reason: InhibitorReason.ChannelGuildBlacklist, + type: InhibitorType.Post, priority: 499 }); } public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise<boolean> { if (!message.author || !message.inGuild()) return false; - // do not change to message.author.isOwner() + //! do not change to message.author.isOwner() if (this.client.isOwner(message.author) || this.client.user!.id === message.author.id) return false; if ( (await message.guild.getSetting('bypassChannelBlacklist'))?.includes(message.author.id) && @@ -24,7 +24,7 @@ export default class ChannelGuildBlacklistInhibitor extends BotInhibitor { !command.bypassChannelBlacklist ) { void this.client.console.verbose( - 'channelGuildBlacklist', + InhibitorReason.ChannelGuildBlacklist, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.` ); return true; diff --git a/src/inhibitors/blacklist/guildBlacklist.ts b/src/inhibitors/blacklist/guildBlacklist.ts index 636d0a3..b1f1543 100644 --- a/src/inhibitors/blacklist/guildBlacklist.ts +++ b/src/inhibitors/blacklist/guildBlacklist.ts @@ -1,17 +1,17 @@ -import { BotInhibitor, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type CommandMessage, type SlashMessage } from '#lib'; export default class GuildBlacklistInhibitor extends BotInhibitor { public constructor() { - super('guildBlacklist', { - reason: 'guildBlacklist', - type: 'all', + super(InhibitorReason.GuildBlacklist, { + reason: InhibitorReason.GuildBlacklist, + type: InhibitorType.All, priority: 50 }); } public exec(message: CommandMessage | SlashMessage): boolean { if (!message.author || !message.inGuild()) return false; - // do not change to message.author.isOwner() + //! do not change to message.author.isOwner() if ( this.client.isOwner(message.author) || this.client.isSuperUser(message.author) || @@ -20,7 +20,7 @@ export default class GuildBlacklistInhibitor extends BotInhibitor { return false; if (this.client.cache.global.blacklistedGuilds.includes(message.guild.id)) { void this.client.console.verbose( - 'guildBlacklist', + InhibitorReason.GuildBlacklist, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.` ); return true; diff --git a/src/inhibitors/blacklist/userGlobalBlacklist.ts b/src/inhibitors/blacklist/userGlobalBlacklist.ts index f5b15df..b0eacfc 100644 --- a/src/inhibitors/blacklist/userGlobalBlacklist.ts +++ b/src/inhibitors/blacklist/userGlobalBlacklist.ts @@ -1,21 +1,21 @@ -import { BotInhibitor, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type CommandMessage, type SlashMessage } from '#lib'; export default class UserGlobalBlacklistInhibitor extends BotInhibitor { public constructor() { - super('userGlobalBlacklist', { - reason: 'userGlobalBlacklist', - type: 'pre', + super(InhibitorReason.UserGlobalBlacklist, { + reason: InhibitorReason.UserGlobalBlacklist, + type: InhibitorType.Pre, priority: 30 }); } public exec(message: CommandMessage | SlashMessage): boolean { if (!message.author) return false; - // do not change to message.author.isOwner() + //! do not change to message.author.isOwner() if (this.client.isOwner(message.author) || this.client.user!.id === message.author.id) return false; if (this.client.cache.global.blacklistedUsers.includes(message.author.id)) { void this.client.console.verbose( - 'userGlobalBlacklist', + InhibitorReason.UserGlobalBlacklist, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${ message.inGuild() ? message.guild?.name : message.author.tag }>>.` diff --git a/src/inhibitors/blacklist/userGuildBlacklist.ts b/src/inhibitors/blacklist/userGuildBlacklist.ts index 3186d59..4330f87 100644 --- a/src/inhibitors/blacklist/userGuildBlacklist.ts +++ b/src/inhibitors/blacklist/userGuildBlacklist.ts @@ -1,17 +1,17 @@ -import { BotInhibitor, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type CommandMessage, type SlashMessage } from '#lib'; export default class UserGuildBlacklistInhibitor extends BotInhibitor { public constructor() { - super('userGuildBlacklist', { - reason: 'userGuildBlacklist', - type: 'pre', + super(InhibitorReason.UserGuildBlacklist, { + reason: InhibitorReason.UserGuildBlacklist, + type: InhibitorType.Pre, priority: 20 }); } public async exec(message: CommandMessage | SlashMessage): Promise<boolean> { if (!message.author || !message.inGuild()) return false; - // do not change to message.author.isOwner() + //! do not change to message.author.isOwner() if ( this.client.isOwner(message.author) || this.client.isSuperUser(message.author) || @@ -20,7 +20,7 @@ export default class UserGuildBlacklistInhibitor extends BotInhibitor { return false; if ((await message.guild.getSetting('blacklistedUsers'))?.includes(message.author.id)) { void this.client.console.verbose( - 'userGuildBlacklist', + InhibitorReason.UserGuildBlacklist, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.` ); return true; diff --git a/src/inhibitors/checks/cannotSend.ts b/src/inhibitors/checks/cannotSend.ts new file mode 100644 index 0000000..e9eab98 --- /dev/null +++ b/src/inhibitors/checks/cannotSend.ts @@ -0,0 +1,39 @@ +import { BotCommand, BotInhibitor, InhibitorReason, InhibitorType, type SlashMessage } from '#lib'; +import { type Message } from 'discord.js'; + +export default class CannotSendInhibitor extends BotInhibitor { + public constructor() { + super(InhibitorReason.CannotSend, { + reason: InhibitorReason.CannotSend, + type: InhibitorType.Post, + priority: 1000 + }); + } + + public async exec(message: Message | SlashMessage, command: BotCommand): Promise<boolean> { + // let it error if it is the owner + if (this.client.isOwner(message.author)) return false; + if (!message.inGuild() || !message.channel) return false; + if (command.skipSendCheck) return false; + + if (!message.guild.members.me) throw new Error(`Client member not cached in ${message.guild.name} (${message.guild.id})`); + + // doesn't apply to slash commands + if (message.util?.isSlash) return false; + + const sendPerm = message.channel.isThread() ? 'SendMessages' : 'SendMessagesInThreads'; + + const perms = message.channel.permissionsFor(message.guild.members.me); + + if (perms == null) { + // todo: remove once forum channels are fixed + if (message.channel.isThread() && message.channel.parent == null) { + return false; + } else { + return true; + } + } + + return !perms.has(sendPerm); + } +} diff --git a/src/inhibitors/checks/fatal.ts b/src/inhibitors/checks/fatal.ts index 4364d48..b585bd8 100644 --- a/src/inhibitors/checks/fatal.ts +++ b/src/inhibitors/checks/fatal.ts @@ -1,11 +1,11 @@ -import { BotInhibitor, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type SlashMessage } from '#lib'; import { type Message } from 'discord.js'; export default class FatalInhibitor extends BotInhibitor { public constructor() { - super('fatal', { - reason: 'fatal', - type: 'all', + super(InhibitorReason.Fatal, { + reason: InhibitorReason.Fatal, + type: InhibitorType.All, priority: 100 }); } @@ -16,7 +16,7 @@ export default class FatalInhibitor extends BotInhibitor { for (const property in globalCache) { if (!globalCache[property as keyof typeof globalCache]) { void this.client.console.verbose( - 'fatal', + InhibitorReason.Fatal, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/checks/guildUnavailable.ts b/src/inhibitors/checks/guildUnavailable.ts index 4439d69..dc2ac26 100644 --- a/src/inhibitors/checks/guildUnavailable.ts +++ b/src/inhibitors/checks/guildUnavailable.ts @@ -1,11 +1,11 @@ -import { BotInhibitor, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type SlashMessage } from '#lib'; import { type Message } from 'discord.js'; export default class GuildUnavailableInhibitor extends BotInhibitor { public constructor() { - super('guildUnavailable', { - reason: 'guildUnavailable', - type: 'all', + super(InhibitorReason.GuildUnavailable, { + reason: InhibitorReason.GuildUnavailable, + type: InhibitorType.All, priority: 70 }); } @@ -13,7 +13,7 @@ export default class GuildUnavailableInhibitor extends BotInhibitor { public async exec(message: Message | SlashMessage): Promise<boolean> { if (message.inGuild() && !message.guild.available) { void this.client.console.verbose( - 'guildUnavailable', + InhibitorReason.GuildUnavailable, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.` ); return true; diff --git a/src/inhibitors/command/globalDisabledCommand.ts b/src/inhibitors/command/disabledGlobal.ts index 4a93f2f..bfb5969 100644 --- a/src/inhibitors/command/globalDisabledCommand.ts +++ b/src/inhibitors/command/disabledGlobal.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; -export default class DisabledGuildCommandInhibitor extends BotInhibitor { +export default class DisabledGlobalInhibitor extends BotInhibitor { public constructor() { - super('disabledGlobalCommand', { - reason: 'disabledGlobal', - type: 'post', + super(InhibitorReason.DisabledGlobal, { + reason: InhibitorReason.DisabledGlobal, + type: InhibitorType.Post, priority: 300 }); } @@ -13,7 +13,7 @@ export default class DisabledGuildCommandInhibitor extends BotInhibitor { if (message.author.isOwner()) return false; if (this.client.cache.global.disabledCommands.includes(command?.id)) { void this.client.console.verbose( - 'disabledGlobalCommand', + InhibitorReason.DisabledGlobal, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/command/guildDisabledCommand.ts b/src/inhibitors/command/disabledGuild.ts index 97ac995..0df827d 100644 --- a/src/inhibitors/command/guildDisabledCommand.ts +++ b/src/inhibitors/command/disabledGuild.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; -export default class DisabledGuildCommandInhibitor extends BotInhibitor { +export default class DisabledGuildInhibitor extends BotInhibitor { public constructor() { - super('disabledGuildCommand', { - reason: 'disabledGuild', - type: 'post', + super(InhibitorReason.DisabledGuild, { + reason: InhibitorReason.DisabledGuild, + type: InhibitorType.Post, priority: 250 }); } @@ -15,7 +15,7 @@ export default class DisabledGuildCommandInhibitor extends BotInhibitor { if ((await message.guild.getSetting('disabledCommands'))?.includes(command?.id)) { void this.client.console.verbose( - 'disabledGuildCommand', + InhibitorReason.DisabledGuild, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.` ); return true; diff --git a/src/inhibitors/command/dm.ts b/src/inhibitors/command/dm.ts index f25f542..aa39b94 100644 --- a/src/inhibitors/command/dm.ts +++ b/src/inhibitors/command/dm.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class DMInhibitor extends BotInhibitor { public constructor() { - super('dm', { - reason: 'dm', - type: 'post', + super(InhibitorReason.Dm, { + reason: InhibitorReason.Dm, + type: InhibitorType.Post, priority: 75 }); } diff --git a/src/inhibitors/command/guild.ts b/src/inhibitors/command/guild.ts index 1d70c7d..24e2577 100644 --- a/src/inhibitors/command/guild.ts +++ b/src/inhibitors/command/guild.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class GuildInhibitor extends BotInhibitor { public constructor() { - super('guild', { - reason: 'guild', - type: 'post', + super(InhibitorReason.Guild, { + reason: InhibitorReason.Guild, + type: InhibitorType.Post, priority: 80 }); } @@ -12,7 +12,7 @@ export default class GuildInhibitor extends BotInhibitor { public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise<boolean> { if (command.channel === 'guild' && !message.guild) { void this.client.console.verbose( - 'guild', + InhibitorReason.Guild, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.author.tag}>>.` ); return true; diff --git a/src/inhibitors/command/nsfw.ts b/src/inhibitors/command/notNsfw.ts index 623115e..08e5556 100644 --- a/src/inhibitors/command/nsfw.ts +++ b/src/inhibitors/command/notNsfw.ts @@ -1,11 +1,11 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; import { type TextChannel } from 'discord.js'; -export default class NsfwInhibitor extends BotInhibitor { +export default class NotNsfwInhibitor extends BotInhibitor { public constructor() { - super('nsfw', { - reason: 'notNsfw', - type: 'post', + super(InhibitorReason.NotNsfw, { + reason: InhibitorReason.NotNsfw, + type: InhibitorType.Post, priority: 25 }); } @@ -13,7 +13,7 @@ export default class NsfwInhibitor extends BotInhibitor { public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise<boolean> { if (command.onlyNsfw && !(message.channel as TextChannel).nsfw) { void this.client.console.verbose( - 'notNsfw', + InhibitorReason.NotNsfw, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/command/owner.ts b/src/inhibitors/command/owner.ts index 15643be..8736cff 100644 --- a/src/inhibitors/command/owner.ts +++ b/src/inhibitors/command/owner.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class OwnerInhibitor extends BotInhibitor { public constructor() { - super('owner', { - reason: 'owner', - type: 'post', + super(InhibitorReason.Owner, { + reason: InhibitorReason.Owner, + type: InhibitorType.Post, priority: 100 }); } @@ -13,7 +13,7 @@ export default class OwnerInhibitor extends BotInhibitor { if (command.ownerOnly) { if (!this.client.isOwner(message.author)) { void this.client.console.verbose( - 'owner', + InhibitorReason.Owner, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/command/restrictedChannel.ts b/src/inhibitors/command/restrictedChannel.ts index ec23604..bfacebc 100644 --- a/src/inhibitors/command/restrictedChannel.ts +++ b/src/inhibitors/command/restrictedChannel.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class RestrictedChannelInhibitor extends BotInhibitor { public constructor() { - super('restrictedChannel', { - reason: 'restrictedChannel', - type: 'post', + super(InhibitorReason.RestrictedChannel, { + reason: InhibitorReason.RestrictedChannel, + type: InhibitorType.Post, priority: 10 }); } @@ -13,7 +13,7 @@ export default class RestrictedChannelInhibitor extends BotInhibitor { if (command.restrictedChannels?.length && message.channel) { if (!command.restrictedChannels.includes(message.channel.id)) { void this.client.console.verbose( - 'restrictedChannel', + InhibitorReason.RestrictedChannel, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/command/restrictedGuild.ts b/src/inhibitors/command/restrictedGuild.ts index ec0ad2c..4520cbc 100644 --- a/src/inhibitors/command/restrictedGuild.ts +++ b/src/inhibitors/command/restrictedGuild.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class RestrictedGuildInhibitor extends BotInhibitor { public constructor() { - super('restrictedGuild', { - reason: 'restrictedGuild', - type: 'post', + super(InhibitorReason.RestrictedGuild, { + reason: InhibitorReason.RestrictedGuild, + type: InhibitorType.Post, priority: 5 }); } @@ -13,7 +13,7 @@ export default class RestrictedGuildInhibitor extends BotInhibitor { if (command.restrictedChannels?.length && message.channel) { if (!command.restrictedChannels.includes(message.channel.id)) { void this.client.console.verbose( - 'restrictedGuild', + InhibitorReason.RestrictedGuild, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/command/superUser.ts b/src/inhibitors/command/superUser.ts index a923c1a..dd71539 100644 --- a/src/inhibitors/command/superUser.ts +++ b/src/inhibitors/command/superUser.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class SuperUserInhibitor extends BotInhibitor { public constructor() { - super('superUser', { - reason: 'superUser', - type: 'post', + super(InhibitorReason.SuperUser, { + reason: InhibitorReason.SuperUser, + type: InhibitorType.Post, priority: 99 }); } |