Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bot): account for implicit permissions #361

Merged
merged 2 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 view 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
Loading