Skip to content

Commit

Permalink
fix(bot): account for implicit permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
CarelessInternet committed Feb 11, 2024
1 parent f3bf0ba commit 0497b63
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apps/bot/src/commands/thread-ticketing/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ export class ModalInteraction extends Modal.Interaction {

const me = await guild.members.fetchMe();

if (!channel.permissionsFor(me).has([PermissionFlagsBits.SendMessages])) {
if (!channel.permissionsFor(me).has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages])) {
return interaction.editReply({
embeds: [
super
.userEmbedError(user)
// eslint-disable-next-line @typescript-eslint/no-base-to-string
.setDescription(`I do not have the send messages permission in ${channel.toString()}.`),
.setDescription(`I do not have the viwe channel and send messages permission in ${channel.toString()}.`),
],
});
}
Expand Down
2 changes: 2 additions & 0 deletions apps/bot/src/commands/thread-ticketing/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export class ModalInteraction extends Modal.Interaction {
.has([
PermissionFlagsBits.MentionEveryone,
PermissionFlagsBits.ManageMessages,
PermissionFlagsBits.ViewChannel,
PermissionFlagsBits.SendMessagesInThreads,
isPrivate ? PermissionFlagsBits.CreatePrivateThreads : PermissionFlagsBits.CreatePublicThreads,
])
Expand All @@ -322,6 +323,7 @@ export class ModalInteraction extends Modal.Interaction {
[
'Mention All Roles',
'Manage Messages',
'View Channel',
'Send Messages in Threads',
`Create ${isPrivate ? 'Private' : 'Public'} Threads`,
].join(', '),
Expand Down
2 changes: 1 addition & 1 deletion apps/bot/src/events/guild/GuildMemberAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class extends Event.Handler {

const me = await members.fetchMe();

if (!channel.permissionsFor(me).has(PermissionFlagsBits.SendMessages)) return;
if (!channel.permissionsFor(me).has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages])) return;

if (data.welcomeNewMemberRoles.length > 0) {
const highestRoleWithManageRoles = me.roles.cache
Expand Down
2 changes: 1 addition & 1 deletion apps/bot/src/events/guild/GuildMemberRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class extends Event.Handler {

const me = await members.fetchMe();

if (!channel.permissionsFor(me).has(PermissionFlagsBits.SendMessages)) return;
if (!channel.permissionsFor(me).has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages])) return;

const embed = farewellEmbed({
data: {
Expand Down
6 changes: 5 additions & 1 deletion apps/bot/src/events/guild/MessageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export default class extends Event.Handler {
if (
!message.channel
.permissionsFor(me)
.has([PermissionFlagsBits.CreatePublicThreads, PermissionFlagsBits.SendMessagesInThreads])
.has([
PermissionFlagsBits.CreatePublicThreads,
PermissionFlagsBits.ViewChannel,
PermissionFlagsBits.SendMessagesInThreads,
])
)
return;
if (message.author.id === me.id) return;
Expand Down
3 changes: 2 additions & 1 deletion apps/bot/src/events/guild/ThreadCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default class extends Event.Handler {
const parent = thread.parent ?? (await thread.guild.channels.fetch(thread.parentId));
const me = await thread.guild.members.fetchMe();

if (!parent?.permissionsFor(me).has([PermissionFlagsBits.SendMessagesInThreads])) return;
if (!parent?.permissionsFor(me).has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessagesInThreads]))
return;

if (parent.type === ChannelType.GuildForum) {
const user = await thread.client.users.fetch(thread.ownerId ?? '');
Expand Down
3 changes: 2 additions & 1 deletion apps/bot/src/utils/thread-ticketing/closeTicket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export async function closeTicket(
const logsChannel = await guild.channels.fetch(row.logsChannelId);

if (!logsChannel?.isTextBased()) return;
if (!logsChannel.permissionsFor(me).has([PermissionFlagsBits.SendMessages])) return;
if (!logsChannel.permissionsFor(me).has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages]))
return;

void logsChannel.send({
embeds: [
Expand Down
3 changes: 2 additions & 1 deletion apps/bot/src/utils/thread-ticketing/deleteTicket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export async function deleteTicket(
const logsChannel = await guild.channels.fetch(row.logsChannelId);

if (!logsChannel?.isTextBased()) return;
if (!logsChannel.permissionsFor(me).has([PermissionFlagsBits.SendMessages])) return;
if (!logsChannel.permissionsFor(me).has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages]))
return;

void logsChannel.send({
embeds: [
Expand Down
3 changes: 2 additions & 1 deletion apps/bot/src/utils/thread-ticketing/lockTicket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export async function lockTicket(
const logsChannel = await guild.channels.fetch(row.logsChannelId);

if (!logsChannel?.isTextBased()) return;
if (!logsChannel.permissionsFor(me).has([PermissionFlagsBits.SendMessages])) return;
if (!logsChannel.permissionsFor(me).has([PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages]))
return;

void logsChannel.send({
embeds: [
Expand Down

0 comments on commit 0497b63

Please sign in to comment.