aboutsummaryrefslogtreecommitdiff
path: root/src/commands/info
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-09-05 17:36:42 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-09-05 17:36:42 -0400
commit048f99752550c6e03d1990a03cad78f3ac7d73aa (patch)
treec238ac29b1b526e86bcbc4989036df981c860187 /src/commands/info
parent6f8a4d13a490eda7a195d14833c83810f7b5a789 (diff)
downloadtanzanite-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/commands/info')
-rw-r--r--src/commands/info/avatar.ts7
-rw-r--r--src/commands/info/botInfo.ts15
-rw-r--r--src/commands/info/color.ts16
-rw-r--r--src/commands/info/guildInfo.ts4
-rw-r--r--src/commands/info/help.ts32
-rw-r--r--src/commands/info/icon.ts7
-rw-r--r--src/commands/info/inviteInfo.ts8
-rw-r--r--src/commands/info/links.ts4
-rw-r--r--src/commands/info/ping.ts7
-rw-r--r--src/commands/info/pronouns.ts14
-rw-r--r--src/commands/info/snowflake.ts14
-rw-r--r--src/commands/info/userInfo.ts11
12 files changed, 66 insertions, 73 deletions
diff --git a/src/commands/info/avatar.ts b/src/commands/info/avatar.ts
index b97364f..aaeebbf 100644
--- a/src/commands/info/avatar.ts
+++ b/src/commands/info/avatar.ts
@@ -1,5 +1,5 @@
-import { Arg, BotCommand, clientSendAndPermCheck, colors, type CommandMessage, type OptArgType, type SlashMessage } from '#lib';
-import { ApplicationCommandOptionType, EmbedBuilder, GuildMember, PermissionFlagsBits } from 'discord.js';
+import { Arg, BotCommand, colors, type CommandMessage, type OptArgType, type SlashMessage } from '#lib';
+import { ApplicationCommandOptionType, EmbedBuilder, GuildMember } from 'discord.js';
export default class AvatarCommand extends BotCommand {
public constructor() {
@@ -21,7 +21,8 @@ export default class AvatarCommand extends BotCommand {
slashType: ApplicationCommandOptionType.User
}
],
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: [],
slash: true
});
diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts
index 64ecf1d..a877073 100644
--- a/src/commands/info/botInfo.ts
+++ b/src/commands/info/botInfo.ts
@@ -1,14 +1,6 @@
-import {
- BotCommand,
- clientSendAndPermCheck,
- colors,
- humanizeDuration,
- shell,
- type CommandMessage,
- type SlashMessage
-} from '#lib';
+import { BotCommand, colors, humanizeDuration, shell, type CommandMessage, type SlashMessage } from '#lib';
import assert from 'assert/strict';
-import { EmbedBuilder, PermissionFlagsBits, version as discordJSVersion } from 'discord.js';
+import { EmbedBuilder, version as discordJSVersion } from 'discord.js';
import * as os from 'os';
const { default: prettyBytes } = await import('pretty-bytes');
assert(prettyBytes);
@@ -23,7 +15,8 @@ export default class BotInfoCommand extends BotCommand {
usage: ['bot-info'],
examples: ['bot-info'],
slash: true,
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: []
});
}
diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts
index c139e1a..b396baa 100644
--- a/src/commands/info/color.ts
+++ b/src/commands/info/color.ts
@@ -1,15 +1,6 @@
-import {
- AllowedMentions,
- Arg,
- BotCommand,
- clientSendAndPermCheck,
- emojis,
- type ArgType,
- type CommandMessage,
- type SlashMessage
-} from '#lib';
+import { AllowedMentions, Arg, BotCommand, emojis, type ArgType, type CommandMessage, type SlashMessage } from '#lib';
import assert from 'assert/strict';
-import { ApplicationCommandOptionType, EmbedBuilder, GuildMember, PermissionFlagsBits, Role } from 'discord.js';
+import { ApplicationCommandOptionType, EmbedBuilder, GuildMember, Role } from 'discord.js';
import tinycolor from 'tinycolor2';
assert(tinycolor);
@@ -34,7 +25,8 @@ export default class ColorCommand extends BotCommand {
}
],
channel: 'guild',
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: []
});
}
diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts
index 97e4be3..e364a89 100644
--- a/src/commands/info/guildInfo.ts
+++ b/src/commands/info/guildInfo.ts
@@ -2,7 +2,6 @@ import {
akairo,
Arg,
BotCommand,
- clientSendAndPermCheck,
colors,
emojis,
mappings,
@@ -52,7 +51,8 @@ export default class GuildInfoCommand extends BotCommand {
}
],
slash: true,
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: []
});
}
diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts
index 6460b99..1680b75 100644
--- a/src/commands/info/help.ts
+++ b/src/commands/info/help.ts
@@ -1,9 +1,10 @@
import {
BotCommand,
- clientSendAndPermCheck,
colors,
format,
+ formatPerms,
invite,
+ permissionCheck,
type ArgType,
type CommandMessage,
type OptArgType,
@@ -17,8 +18,7 @@ import {
AutocompleteInteraction,
ButtonBuilder,
ButtonStyle,
- EmbedBuilder,
- PermissionFlagsBits
+ EmbedBuilder
} from 'discord.js';
import { default as Fuse } from 'fuse.js';
import packageDotJSON from '../../../package.json' assert { type: 'json' };
@@ -58,7 +58,8 @@ export default class HelpCommand extends BotCommand {
}
],
slash: true,
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: []
});
}
@@ -88,14 +89,24 @@ export default class HelpCommand extends BotCommand {
.setFooter({ text: `For more information about a command use ${prefix_}help <command>` });
for (const [, category] of this.handler.categories.sort((a, b) => a.id.localeCompare(b.id))) {
const categoryFilter = category.filter((command) => {
+ const inGuild = message.inGuild();
+
if (command.pseudo) return false;
if (command.hidden && !args.showHidden) return false;
- if (command.channel == 'guild' && !message.guild && !args.showHidden) return false;
+ if (command.channel == 'guild' && !inGuild && !args.showHidden) return false;
if (command.ownerOnly && !message.author.isOwner()) return false;
if (command.superUserOnly && !message.author.isSuperUser()) return false;
if (command.restrictedGuilds?.includes(message.guild?.id ?? '') === false && !args.showHidden) return false;
if (command.aliases.length === 0) return false;
+ permissions: {
+ if (!inGuild || !message.member) break permissions;
+
+ const canUse = permissionCheck(message, message.member, command.userPermissions, false);
+
+ if (!canUse) return false;
+ }
+
return true;
});
const categoryNice = category.id
@@ -121,7 +132,7 @@ export default class HelpCommand extends BotCommand {
this.addCommandAliases(embed, command);
this.addCommandArguments(embed, command, message.author.isOwner(), message.author.isSuperUser());
this.addCommandRestrictions(embed, command);
- // todo: permissions
+ this.addCommandPermissions(embed, command);
const params = { embeds: [embed], components: row.components.length ? [row] : undefined };
return message.util.reply(params);
@@ -178,6 +189,7 @@ export default class HelpCommand extends BotCommand {
return ret;
})
.join('\n')
+ .slice(0, 1024)
});
}
}
@@ -209,6 +221,14 @@ export default class HelpCommand extends BotCommand {
}
}
+ private addCommandPermissions(embed: EmbedBuilder, command: BotCommand): void {
+ if (command.userPermissions.length < 1 && command.clientPermissions.length < 1) return;
+ const permissions: string[] = [];
+ if (command.userPermissions.length > 0) permissions.push(`__User__: ${formatPerms(command.userPermissions)}`);
+ if (command.clientPermissions.length > 0) permissions.push(`__Client__: ${formatPerms(command.clientPermissions)}`);
+ embed.addFields({ name: 'ยป Required Permissions', value: permissions.join('\n') });
+ }
+
private addLinks(message: CommandMessage | SlashMessage): ActionRowBuilder<ButtonBuilder> {
const row = new ActionRowBuilder<ButtonBuilder>();
const config = this.client.config;
diff --git a/src/commands/info/icon.ts b/src/commands/info/icon.ts
index 71f02f9..ed7e8ca 100644
--- a/src/commands/info/icon.ts
+++ b/src/commands/info/icon.ts
@@ -1,6 +1,6 @@
-import { BotCommand, clientSendAndPermCheck, colors, type CommandMessage, type SlashMessage } from '#lib';
+import { BotCommand, colors, type CommandMessage, type SlashMessage } from '#lib';
import assert from 'assert/strict';
-import { EmbedBuilder, escapeMarkdown, PermissionFlagsBits } from 'discord.js';
+import { EmbedBuilder, escapeMarkdown } from 'discord.js';
export default class IconCommand extends BotCommand {
public constructor() {
@@ -10,7 +10,8 @@ export default class IconCommand extends BotCommand {
description: "A command to get the server's icon",
usage: ['icon'],
examples: ['icon'],
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: [],
channel: 'guild',
slash: true
diff --git a/src/commands/info/inviteInfo.ts b/src/commands/info/inviteInfo.ts
index 590bf16..bf66a4c 100644
--- a/src/commands/info/inviteInfo.ts
+++ b/src/commands/info/inviteInfo.ts
@@ -1,5 +1,5 @@
-import { Arg, ArgType, BotCommand, clientSendAndPermCheck, colors, type CommandMessage, type SlashMessage } from '#lib';
-import { ApplicationCommandOptionType, EmbedBuilder, Invite, PermissionFlagsBits } from 'discord.js';
+import { Arg, ArgType, BotCommand, colors, type CommandMessage, type SlashMessage } from '#lib';
+import { ApplicationCommandOptionType, EmbedBuilder, Invite } from 'discord.js';
export default class InviteInfoCommand extends BotCommand {
public constructor() {
@@ -20,7 +20,9 @@ export default class InviteInfoCommand extends BotCommand {
}
],
slash: true,
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ hidden: true,
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: []
});
}
diff --git a/src/commands/info/links.ts b/src/commands/info/links.ts
index ecc09c8..b3d0292 100644
--- a/src/commands/info/links.ts
+++ b/src/commands/info/links.ts
@@ -1,4 +1,4 @@
-import { BotCommand, clientSendAndPermCheck, invite, type CommandMessage, type SlashMessage } from '#lib';
+import { BotCommand, invite, type CommandMessage, type SlashMessage } from '#lib';
import assert from 'assert/strict';
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
import packageDotJSON from '../../../package.json' assert { type: 'json' };
@@ -13,7 +13,7 @@ export default class LinksCommand extends BotCommand {
description: 'Sends bot links',
usage: ['links'],
examples: ['links'],
- clientPermissions: (m) => clientSendAndPermCheck(m),
+ clientPermissions: [],
userPermissions: [],
slash: true
});
diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts
index 91bec1d..ad58cc0 100644
--- a/src/commands/info/ping.ts
+++ b/src/commands/info/ping.ts
@@ -1,5 +1,5 @@
-import { BotCommand, clientSendAndPermCheck, colors, format, type CommandMessage, type SlashMessage } from '#lib';
-import { EmbedBuilder, PermissionFlagsBits, type Message } from 'discord.js';
+import { BotCommand, colors, format, type CommandMessage, type SlashMessage } from '#lib';
+import { EmbedBuilder, type Message } from 'discord.js';
export default class PingCommand extends BotCommand {
public constructor() {
@@ -10,7 +10,8 @@ export default class PingCommand extends BotCommand {
usage: ['ping'],
examples: ['ping'],
slash: true,
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: []
});
}
diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts
index 47061fc..138bdfc 100644
--- a/src/commands/info/pronouns.ts
+++ b/src/commands/info/pronouns.ts
@@ -1,12 +1,5 @@
-import {
- AllowedMentions,
- BotCommand,
- clientSendAndPermCheck,
- type CommandMessage,
- type OptArgType,
- type SlashMessage
-} from '#lib';
-import { ApplicationCommandOptionType, EmbedBuilder, escapeMarkdown, PermissionFlagsBits } from 'discord.js';
+import { AllowedMentions, BotCommand, type CommandMessage, type OptArgType, type SlashMessage } from '#lib';
+import { ApplicationCommandOptionType, EmbedBuilder, escapeMarkdown } from 'discord.js';
export default class PronounsCommand extends BotCommand {
public constructor() {
@@ -27,7 +20,8 @@ export default class PronounsCommand extends BotCommand {
slashType: ApplicationCommandOptionType.User
}
],
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: [],
slash: true
});
diff --git a/src/commands/info/snowflake.ts b/src/commands/info/snowflake.ts
index deaf41c..ba93611 100644
--- a/src/commands/info/snowflake.ts
+++ b/src/commands/info/snowflake.ts
@@ -1,19 +1,10 @@
-import {
- BotCommand,
- clientSendAndPermCheck,
- colors,
- timestamp,
- type ArgType,
- type CommandMessage,
- type SlashMessage
-} from '#lib';
+import { BotCommand, colors, timestamp, type ArgType, type CommandMessage, type SlashMessage } from '#lib';
import { stripIndent } from '#tags';
import {
ApplicationCommandOptionType,
ChannelType,
EmbedBuilder,
escapeMarkdown,
- PermissionFlagsBits,
SnowflakeUtil,
type DeconstructedSnowflake,
type Snowflake
@@ -37,7 +28,8 @@ export default class SnowflakeCommand extends BotCommand {
slashType: ApplicationCommandOptionType.String
}
],
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: [],
slash: true
});
diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts
index 52875ef..f70896d 100644
--- a/src/commands/info/userInfo.ts
+++ b/src/commands/info/userInfo.ts
@@ -2,9 +2,9 @@ import {
Arg,
BotCommand,
bots,
- clientSendAndPermCheck,
colors,
emojis,
+ formatPerms,
mappings,
oxford,
sleep,
@@ -51,7 +51,8 @@ export default class UserInfoCommand extends BotCommand {
}
],
slash: true,
- clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
+ clientPermissions: ['EmbedLinks'],
+ clientCheckChannel: true,
userPermissions: []
});
}
@@ -246,11 +247,7 @@ export default class UserInfoCommand extends BotCommand {
if (member?.permissions.has(PermissionFlagsBits.Administrator) || member.guild?.ownerId == member.user.id) {
perms.push('`Administrator`');
} else if (member?.permissions.toArray().length) {
- member.permissions.toArray().forEach((permission) => {
- if (mappings.permissions[permission]?.important) {
- perms.push(`\`${mappings.permissions[permission].name}\``);
- }
- });
+ perms.push(formatPerms(member.permissions.toArray().filter((p) => mappings.permissions[p]?.important === true)));
}
if (perms.length) embed.addFields({ name: title, value: perms.join(' ') });