From 8432278388d6b2aa15ff1b6c272b98145c0e7c95 Mon Sep 17 00:00:00 2001 From: alfianchii Date: Wed, 31 Dec 2025 12:09:35 +0700 Subject: [PATCH 1/8] fixL checkin channel with `getChannel` func --- src/bot/events/interaction-create/checkin/validators/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bot/events/interaction-create/checkin/validators/index.ts b/src/bot/events/interaction-create/checkin/validators/index.ts index df8ad63..ef3ce65 100644 --- a/src/bot/events/interaction-create/checkin/validators/index.ts +++ b/src/bot/events/interaction-create/checkin/validators/index.ts @@ -433,7 +433,7 @@ export class Checkin extends CheckinMessage { await this.assertSubmittedCheckinToday(client.prisma, opt) const updatedCheckin = await this.updateCheckinStatus(client.prisma, flamewarden, opt, checkinCreatedAt, checkinStatus, comment, isAudit) as CheckinType - const checkinChannel = await client.channels.fetch(CHECKIN_CHANNEL) as TextChannel + const checkinChannel = await getChannel(guild, CHECKIN_CHANNEL) as TextChannel const { messageId } = this.getMessageFromLink(updatedCheckin.link!) const message = await checkinChannel.messages.fetch(messageId) From 89df5e6a01f1d28113e949308f5058652fa776bd Mon Sep 17 00:00:00 2001 From: alfianchii Date: Wed, 31 Dec 2025 12:19:32 +0700 Subject: [PATCH 2/8] chore: use `client.user` instead --- src/bot/events/message-create/channel/handlers/check-in.ts | 2 +- src/bot/events/message-create/server-booster/handlers/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bot/events/message-create/channel/handlers/check-in.ts b/src/bot/events/message-create/channel/handlers/check-in.ts index f438c59..84fb1cc 100644 --- a/src/bot/events/message-create/channel/handlers/check-in.ts +++ b/src/bot/events/message-create/channel/handlers/check-in.ts @@ -26,7 +26,7 @@ registerMessageHandler({ throw new CheckInError(CheckIn.ERR.NotGuild) const channel = msg.channel as TextChannel - CheckIn.assertMissPerms(msg.guild.members.me!, channel) + CheckIn.assertMissPerms(msg.client.user!, channel) await msg.delete() log.warn(`${channel.name}: deleted unauthorized message from '${msg.author.tag}'`) diff --git a/src/bot/events/message-create/server-booster/handlers/index.ts b/src/bot/events/message-create/server-booster/handlers/index.ts index 825d115..a412d5d 100644 --- a/src/bot/events/message-create/server-booster/handlers/index.ts +++ b/src/bot/events/message-create/server-booster/handlers/index.ts @@ -26,7 +26,7 @@ registerMessageHandler({ const auraFarmingChannel = await getChannel(msg.guild, AURA_FARMING_CHANNEL) as TextChannel ServerBooster.assertChannel(auraFarmingChannel) - ServerBooster.assertMissPerms(msg.guild.members.me!, auraFarmingChannel) + ServerBooster.assertMissPerms(msg.client.user, auraFarmingChannel) const member = msg.member! ServerBooster.assertMember(member) From 38ca88a09568775580648165f068152d58b99231 Mon Sep 17 00:00:00 2001 From: alfianchii Date: Wed, 31 Dec 2025 12:23:45 +0700 Subject: [PATCH 3/8] chore: func renaming --- src/utils/discord/assert.ts | 4 ++-- src/utils/discord/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/discord/assert.ts b/src/utils/discord/assert.ts index 83bda9c..553d746 100644 --- a/src/utils/discord/assert.ts +++ b/src/utils/discord/assert.ts @@ -1,7 +1,7 @@ import type { ClientUser, Guild, GuildMember, Message, Role, TextChannel, ThreadAutoArchiveDuration, ThreadChannel } from 'discord.js' import { getTempToken, parseMessageLink, tempStore } from '@utils/component' import { ChannelType, PermissionsBitField } from 'discord.js' -import { getBotPerms, getChannel, getMissPerms } from '.' +import { getChannel, getMissPerms, getPerms } from '.' import { DiscordBaseError } from './error' import { DiscordMessage } from './message' @@ -109,7 +109,7 @@ export class DiscordAssert extends DiscordMessage { } static assertMissPerms(user: ClientUser | GuildMember, channel: TextChannel) { - const channelPerms = getBotPerms(user, channel) + const channelPerms = getPerms(user, channel) const missedPerms = getMissPerms(channelPerms, this.BASE_PERMS) if (missedPerms.length) { diff --git a/src/utils/discord/index.ts b/src/utils/discord/index.ts index d58c8a0..d899b4e 100644 --- a/src/utils/discord/index.ts +++ b/src/utils/discord/index.ts @@ -20,7 +20,7 @@ export async function getBot(guild: Guild): Promise { return guild!.members.me as GuildMember ?? await guild!.members.fetchMe() } -export const getBotPerms = (user: ClientUser | GuildMember, channel: TextChannel): Readonly => channel.permissionsFor(user!)! +export const getPerms = (user: ClientUser | GuildMember, channel: TextChannel): Readonly => channel.permissionsFor(user!)! export function getAttachments(interaction: ChatInputCommandInteraction, fileCount: number): Attachment[] { const files: Attachment[] = [] From 947eb3567b8c0cc7acb026df53dafcfdec775181 Mon Sep 17 00:00:00 2001 From: alfianchii Date: Wed, 31 Dec 2025 12:26:13 +0700 Subject: [PATCH 4/8] fix: use `members.me` to assert bot's perms --- src/bot/commands/checkin/handlers/checkin-audit.ts | 2 +- src/bot/commands/checkin/handlers/checkin-status.ts | 2 +- src/bot/commands/checkin/handlers/index.ts | 2 +- src/bot/commands/embed/handlers/role-grant-create.ts | 2 +- src/bot/commands/message/handlers/send.ts | 2 +- src/bot/commands/utility/handlers/ping.ts | 2 +- .../interaction-create/checkin/handlers/approve-button.ts | 2 +- .../interaction-create/checkin/handlers/custom-button-modal.ts | 2 +- .../events/interaction-create/checkin/handlers/custom-button.ts | 2 +- .../events/interaction-create/checkin/handlers/detail-button.ts | 2 +- .../events/interaction-create/checkin/handlers/reject-button.ts | 2 +- .../embed/handlers/role-grant-create-button.ts | 2 +- .../embed/handlers/role-grant-create-modal.ts | 2 +- .../events/interaction-create/grinder-role/handlers/button.ts | 2 +- .../jobs/handlers/reset-grinder-roles-button.ts | 2 +- .../events/interaction-create/message/handlers/send-modal.ts | 2 +- src/bot/events/message-create/channel/handlers/check-in.ts | 2 +- src/bot/events/message-create/server-booster/handlers/index.ts | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/bot/commands/checkin/handlers/checkin-audit.ts b/src/bot/commands/checkin/handlers/checkin-audit.ts index f21ceed..f55a969 100644 --- a/src/bot/commands/checkin/handlers/checkin-audit.ts +++ b/src/bot/commands/checkin/handlers/checkin-audit.ts @@ -26,7 +26,7 @@ registerCommand({ throw new CheckinAuditError(CheckinAudit.ERR.NotGuild) const channel = await getChannel(interaction.guild, AUDIT_FLAME_CHANNEL) as TextChannel - CheckinAudit.assertMissPerms(interaction.client.user, channel) + CheckinAudit.assertMissPerms(interaction.guild.members.me!, channel) const thread = await CheckinAudit.assertThreadUnderChannel(interaction.guild, interaction.channelId, channel) CheckinAudit.assertNotArchivedThread(thread) CheckinAudit.assertNotPrivateThread(thread) diff --git a/src/bot/commands/checkin/handlers/checkin-status.ts b/src/bot/commands/checkin/handlers/checkin-status.ts index 0ea5e03..2d47eb4 100644 --- a/src/bot/commands/checkin/handlers/checkin-status.ts +++ b/src/bot/commands/checkin/handlers/checkin-status.ts @@ -24,7 +24,7 @@ registerCommand({ throw new CheckinStatusError(CheckinStatus.ERR.NotGuild) const channel = await CheckinStatus.assertAllowedChannel(interaction.guild, interaction.channelId, AUDIT_FLAME_CHANNEL) - CheckinStatus.assertMissPerms(interaction.client.user, channel) + CheckinStatus.assertMissPerms(interaction.guild.members.me!, channel) const member = interaction.member as GuildMember CheckinStatus.assertMember(member) diff --git a/src/bot/commands/checkin/handlers/index.ts b/src/bot/commands/checkin/handlers/index.ts index 859949f..41d1e59 100644 --- a/src/bot/commands/checkin/handlers/index.ts +++ b/src/bot/commands/checkin/handlers/index.ts @@ -32,7 +32,7 @@ registerCommand({ throw new CheckinError(Checkin.ERR.NotGuild) const channel = await Checkin.assertAllowedChannel(interaction.guild, interaction.channelId, CHECKIN_CHANNEL) - Checkin.assertMissPerms(interaction.client.user, channel) + Checkin.assertMissPerms(interaction.guild.members.me!, channel) const attachments = getAttachments(interaction, Checkin.ATTACHMENT_COUNT) const tempToken = Checkin.setTempItem(attachments) diff --git a/src/bot/commands/embed/handlers/role-grant-create.ts b/src/bot/commands/embed/handlers/role-grant-create.ts index 7e0ef6c..1940867 100644 --- a/src/bot/commands/embed/handlers/role-grant-create.ts +++ b/src/bot/commands/embed/handlers/role-grant-create.ts @@ -30,7 +30,7 @@ registerCommand({ throw new EmbedRoleGrantError(RoleGrantCreate.ERR.NotGuild) const channel = interaction.channel as TextChannel - RoleGrantCreate.assertMissPerms(interaction.client.user, channel) + RoleGrantCreate.assertMissPerms(interaction.guild.members.me!, channel) const buttonName = interaction.options.getString('button-name', true) const role = interaction.options.getRole('role', true) diff --git a/src/bot/commands/message/handlers/send.ts b/src/bot/commands/message/handlers/send.ts index 87d1189..f5639c0 100644 --- a/src/bot/commands/message/handlers/send.ts +++ b/src/bot/commands/message/handlers/send.ts @@ -37,7 +37,7 @@ registerCommand({ throw new SendError(Send.ERR.NotGuild) const channel = interaction.channel as TextChannel - Send.assertMissPerms(interaction.client.user, channel) + Send.assertMissPerms(interaction.guild.members.me!, channel) const attachments = getAttachments(interaction, Send.ATTACHMENT_COUNT) const tempToken = Send.setTempItem(attachments) diff --git a/src/bot/commands/utility/handlers/ping.ts b/src/bot/commands/utility/handlers/ping.ts index 089d94d..d5c86e4 100644 --- a/src/bot/commands/utility/handlers/ping.ts +++ b/src/bot/commands/utility/handlers/ping.ts @@ -23,7 +23,7 @@ registerCommand({ throw new PingError(Ping.ERR.NotGuild) const channel = interaction.channel as TextChannel - Ping.assertMissPerms(interaction.client.user, channel) + Ping.assertMissPerms(interaction.guild.members.me!, channel) await sendReply(interaction, 'Pong!') } diff --git a/src/bot/events/interaction-create/checkin/handlers/approve-button.ts b/src/bot/events/interaction-create/checkin/handlers/approve-button.ts index 728ea5a..3c964fa 100644 --- a/src/bot/events/interaction-create/checkin/handlers/approve-button.ts +++ b/src/bot/events/interaction-create/checkin/handlers/approve-button.ts @@ -34,7 +34,7 @@ registerInteractionHandler({ const { checkinId, checkinCreatedAt } = Checkin.getButtonId(interaction, interaction.customId) const channel = interaction.channel as TextChannel - Checkin.assertMissPerms(interaction.client.user, channel) + Checkin.assertMissPerms(interaction.guild.members.me!, channel) const flamewarden = await interaction.guild.members.fetch(interaction.member.id) Checkin.assertMember(flamewarden) Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE) diff --git a/src/bot/events/interaction-create/checkin/handlers/custom-button-modal.ts b/src/bot/events/interaction-create/checkin/handlers/custom-button-modal.ts index b239bf8..00e0f6b 100644 --- a/src/bot/events/interaction-create/checkin/handlers/custom-button-modal.ts +++ b/src/bot/events/interaction-create/checkin/handlers/custom-button-modal.ts @@ -35,7 +35,7 @@ registerInteractionHandler({ const { checkinId, checkinCreatedAt } = Checkin.getModalReviewId(interaction, interaction.customId) const channel = interaction.channel as TextChannel - Checkin.assertMissPerms(interaction.client.user, channel) + Checkin.assertMissPerms(interaction.guild.members.me!, channel) const flamewarden = await interaction.guild.members.fetch(interaction.member.id) Checkin.assertMember(flamewarden) Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE) diff --git a/src/bot/events/interaction-create/checkin/handlers/custom-button.ts b/src/bot/events/interaction-create/checkin/handlers/custom-button.ts index 62cdfba..d7fb3df 100644 --- a/src/bot/events/interaction-create/checkin/handlers/custom-button.ts +++ b/src/bot/events/interaction-create/checkin/handlers/custom-button.ts @@ -31,7 +31,7 @@ registerInteractionHandler({ throw new CheckinCustomButtonError(Checkin.ERR.NotGuild) const channel = interaction.channel as TextChannel - Checkin.assertMissPerms(interaction.client.user, channel) + Checkin.assertMissPerms(interaction.guild.members.me!, channel) const flamewarden = await interaction.guild.members.fetch(interaction.member.id) Checkin.assertMember(flamewarden) Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE) diff --git a/src/bot/events/interaction-create/checkin/handlers/detail-button.ts b/src/bot/events/interaction-create/checkin/handlers/detail-button.ts index 1cb2bc8..2ce0563 100644 --- a/src/bot/events/interaction-create/checkin/handlers/detail-button.ts +++ b/src/bot/events/interaction-create/checkin/handlers/detail-button.ts @@ -32,7 +32,7 @@ registerInteractionHandler({ const channel = interaction.channel as TextChannel const member = interaction.member as GuildMember - Checkin.assertMissPerms(interaction.client.user, channel) + Checkin.assertMissPerms(interaction.guild.members.me!, channel) Checkin.assertMember(member) Checkin.assertMemberGrindRoles(member) diff --git a/src/bot/events/interaction-create/checkin/handlers/reject-button.ts b/src/bot/events/interaction-create/checkin/handlers/reject-button.ts index a5db077..edf73e0 100644 --- a/src/bot/events/interaction-create/checkin/handlers/reject-button.ts +++ b/src/bot/events/interaction-create/checkin/handlers/reject-button.ts @@ -34,7 +34,7 @@ registerInteractionHandler({ const { checkinId, checkinCreatedAt } = Checkin.getButtonId(interaction, interaction.customId) const channel = interaction.channel as TextChannel - Checkin.assertMissPerms(interaction.client.user, channel) + Checkin.assertMissPerms(interaction.guild.members.me!, channel) const flamewarden = await interaction.guild.members.fetch(interaction.member.id) Checkin.assertMember(flamewarden) Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE) diff --git a/src/bot/events/interaction-create/embed/handlers/role-grant-create-button.ts b/src/bot/events/interaction-create/embed/handlers/role-grant-create-button.ts index bed00cd..5466313 100644 --- a/src/bot/events/interaction-create/embed/handlers/role-grant-create-button.ts +++ b/src/bot/events/interaction-create/embed/handlers/role-grant-create-button.ts @@ -29,7 +29,7 @@ registerInteractionHandler({ throw new EmbedRoleGrantButtonError(RoleGrantCreate.ERR.NotGuild) const channel = interaction.channel as TextChannel - RoleGrantCreate.assertMissPerms(interaction.client.user, channel) + RoleGrantCreate.assertMissPerms(interaction.guild.members.me!, channel) const { roleId } = RoleGrantCreate.getButtonId(interaction, interaction.customId) const member = interaction.member as GuildMember diff --git a/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts b/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts index 8faed0f..a2321e8 100644 --- a/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts +++ b/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts @@ -33,7 +33,7 @@ registerInteractionHandler({ const { channelId, roleId, buttonName } = RoleGrantCreate.getModalId(interaction, interaction.customId) const channel = await getChannel(interaction.guild, channelId) as TextChannel RoleGrantCreate.assertChannel(channel) - RoleGrantCreate.assertMissPerms(interaction.client.user, channel) + RoleGrantCreate.assertMissPerms(interaction.guild.members.me!, channel) const role = await getRole(interaction.guild, roleId) RoleGrantCreate.assertRole(role) diff --git a/src/bot/events/interaction-create/grinder-role/handlers/button.ts b/src/bot/events/interaction-create/grinder-role/handlers/button.ts index 98b6293..b9820a3 100644 --- a/src/bot/events/interaction-create/grinder-role/handlers/button.ts +++ b/src/bot/events/interaction-create/grinder-role/handlers/button.ts @@ -29,7 +29,7 @@ registerInteractionHandler({ throw new GrinderRoleButtonError(GrinderRole.ERR.NotGuild) const channel = interaction.channel as TextChannel - GrinderRole.assertMissPerms(interaction.client.user, channel) + GrinderRole.assertMissPerms(interaction.guild.members.me!, channel) await sendReply(interaction, GrinderRole.MSG.WelcomeNotes) } diff --git a/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts b/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts index 0bdd59c..c33fb16 100644 --- a/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts +++ b/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts @@ -29,7 +29,7 @@ registerInteractionHandler({ throw new ResetGrinderRolesButtonError(ResetGrinderRoles.ERR.NotGuild) const channel = interaction.channel as TextChannel - ResetGrinderRoles.assertMissPerms(interaction.client.user, channel) + ResetGrinderRoles.assertMissPerms(interaction.guild.members.me!, channel) const { thread } = await ResetGrinderRoles.getButtonId(interaction, interaction.customId) diff --git a/src/bot/events/interaction-create/message/handlers/send-modal.ts b/src/bot/events/interaction-create/message/handlers/send-modal.ts index 7347be4..184e801 100644 --- a/src/bot/events/interaction-create/message/handlers/send-modal.ts +++ b/src/bot/events/interaction-create/message/handlers/send-modal.ts @@ -31,7 +31,7 @@ registerInteractionHandler({ const { channelId, tempToken } = Send.getModalId(interaction, interaction.customId) const channel = await getChannel(interaction.guild, channelId) as TextChannel Send.assertChannel(channel) - Send.assertMissPerms(interaction.client.user, channel) + Send.assertMissPerms(interaction.guild.members.me!, channel) const attachments = tempStore.get(tempToken) as Attachment[] Send.delTempItem(attachments, tempToken) diff --git a/src/bot/events/message-create/channel/handlers/check-in.ts b/src/bot/events/message-create/channel/handlers/check-in.ts index 84fb1cc..f438c59 100644 --- a/src/bot/events/message-create/channel/handlers/check-in.ts +++ b/src/bot/events/message-create/channel/handlers/check-in.ts @@ -26,7 +26,7 @@ registerMessageHandler({ throw new CheckInError(CheckIn.ERR.NotGuild) const channel = msg.channel as TextChannel - CheckIn.assertMissPerms(msg.client.user!, channel) + CheckIn.assertMissPerms(msg.guild.members.me!, channel) await msg.delete() log.warn(`${channel.name}: deleted unauthorized message from '${msg.author.tag}'`) diff --git a/src/bot/events/message-create/server-booster/handlers/index.ts b/src/bot/events/message-create/server-booster/handlers/index.ts index a412d5d..825d115 100644 --- a/src/bot/events/message-create/server-booster/handlers/index.ts +++ b/src/bot/events/message-create/server-booster/handlers/index.ts @@ -26,7 +26,7 @@ registerMessageHandler({ const auraFarmingChannel = await getChannel(msg.guild, AURA_FARMING_CHANNEL) as TextChannel ServerBooster.assertChannel(auraFarmingChannel) - ServerBooster.assertMissPerms(msg.client.user, auraFarmingChannel) + ServerBooster.assertMissPerms(msg.guild.members.me!, auraFarmingChannel) const member = msg.member! ServerBooster.assertMember(member) From 7f9e3cff3c9c78b39ed9982506c30768ddd24682 Mon Sep 17 00:00:00 2001 From: alfianchii Date: Wed, 31 Dec 2025 12:34:34 +0700 Subject: [PATCH 5/8] fix: cache `members.me` with `getBot` --- src/bot/commands/checkin/handlers/checkin-audit.ts | 5 +++-- src/bot/commands/checkin/handlers/checkin-status.ts | 5 +++-- src/bot/commands/checkin/handlers/index.ts | 5 +++-- src/bot/commands/embed/handlers/role-grant-create.ts | 5 +++-- src/bot/commands/message/handlers/send.ts | 5 +++-- src/bot/commands/utility/handlers/ping.ts | 5 +++-- .../interaction-create/checkin/handlers/approve-button.ts | 5 +++-- .../checkin/handlers/custom-button-modal.ts | 5 +++-- .../interaction-create/checkin/handlers/custom-button.ts | 5 +++-- .../interaction-create/checkin/handlers/detail-button.ts | 5 +++-- .../interaction-create/checkin/handlers/reject-button.ts | 5 +++-- .../embed/handlers/role-grant-create-button.ts | 5 +++-- .../embed/handlers/role-grant-create-modal.ts | 5 +++-- .../interaction-create/grinder-role/handlers/button.ts | 5 +++-- .../jobs/handlers/reset-grinder-roles-button.ts | 5 +++-- .../events/interaction-create/message/handlers/send-modal.ts | 5 +++-- src/bot/events/message-create/channel/handlers/check-in.ts | 4 +++- .../events/message-create/server-booster/handlers/index.ts | 5 +++-- 18 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/bot/commands/checkin/handlers/checkin-audit.ts b/src/bot/commands/checkin/handlers/checkin-audit.ts index f55a969..f17cc8c 100644 --- a/src/bot/commands/checkin/handlers/checkin-audit.ts +++ b/src/bot/commands/checkin/handlers/checkin-audit.ts @@ -3,7 +3,7 @@ import { registerCommand } from '@commands/registry' import { AUDIT_FLAME_CHANNEL, FLAMEWARDEN_ROLE } from '@config/discord' import { CHECKIN_AUDIT_ID } from '@events/interaction-create/checkin/handlers/audit-modal' import { createCheckinReviewModal, encodeSnowflake, getCustomId } from '@utils/component' -import { getChannel, sendReply } from '@utils/discord' +import { getBot, getChannel, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { log } from '@utils/logger' import { SlashCommandBuilder } from 'discord.js' @@ -26,7 +26,8 @@ registerCommand({ throw new CheckinAuditError(CheckinAudit.ERR.NotGuild) const channel = await getChannel(interaction.guild, AUDIT_FLAME_CHANNEL) as TextChannel - CheckinAudit.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + CheckinAudit.assertMissPerms(bot, channel) const thread = await CheckinAudit.assertThreadUnderChannel(interaction.guild, interaction.channelId, channel) CheckinAudit.assertNotArchivedThread(thread) CheckinAudit.assertNotPrivateThread(thread) diff --git a/src/bot/commands/checkin/handlers/checkin-status.ts b/src/bot/commands/checkin/handlers/checkin-status.ts index 2d47eb4..e3245be 100644 --- a/src/bot/commands/checkin/handlers/checkin-status.ts +++ b/src/bot/commands/checkin/handlers/checkin-status.ts @@ -1,7 +1,7 @@ import type { ChatInputCommandInteraction, Client, GuildMember } from 'discord.js' import { registerCommand } from '@commands/registry' import { AUDIT_FLAME_CHANNEL, FLAMEWARDEN_ROLE } from '@config/discord' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { log } from '@utils/logger' import { SlashCommandBuilder } from 'discord.js' @@ -24,7 +24,8 @@ registerCommand({ throw new CheckinStatusError(CheckinStatus.ERR.NotGuild) const channel = await CheckinStatus.assertAllowedChannel(interaction.guild, interaction.channelId, AUDIT_FLAME_CHANNEL) - CheckinStatus.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + CheckinStatus.assertMissPerms(bot, channel) const member = interaction.member as GuildMember CheckinStatus.assertMember(member) diff --git a/src/bot/commands/checkin/handlers/index.ts b/src/bot/commands/checkin/handlers/index.ts index 41d1e59..261337c 100644 --- a/src/bot/commands/checkin/handlers/index.ts +++ b/src/bot/commands/checkin/handlers/index.ts @@ -4,7 +4,7 @@ import { CHECKIN_CHANNEL } from '@config/discord' import { CHECKIN_ID } from '@events/interaction-create/checkin/handlers/modal' import { Checkin } from '@events/interaction-create/checkin/validators' import { encodeSnowflake, getCustomId } from '@utils/component' -import { getAttachments, sendReply } from '@utils/discord' +import { getAttachments, getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { log } from '@utils/logger' import { DUMMY } from '@utils/placeholder' @@ -32,7 +32,8 @@ registerCommand({ throw new CheckinError(Checkin.ERR.NotGuild) const channel = await Checkin.assertAllowedChannel(interaction.guild, interaction.channelId, CHECKIN_CHANNEL) - Checkin.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + Checkin.assertMissPerms(bot, channel) const attachments = getAttachments(interaction, Checkin.ATTACHMENT_COUNT) const tempToken = Checkin.setTempItem(attachments) diff --git a/src/bot/commands/embed/handlers/role-grant-create.ts b/src/bot/commands/embed/handlers/role-grant-create.ts index 1940867..cd14275 100644 --- a/src/bot/commands/embed/handlers/role-grant-create.ts +++ b/src/bot/commands/embed/handlers/role-grant-create.ts @@ -4,7 +4,7 @@ import { LabelBuilder, ModalBuilder, TextInputBuilder } from '@discordjs/builder import { EMBED_ROLE_GRANT_CREATE_MODAL_ID } from '@events/interaction-create/embed/handlers/role-grant-create-modal' import { RoleGrantCreate } from '@events/interaction-create/embed/validators/role-grant-create' import { encodeSnowflake, getCustomId } from '@utils/component' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { log } from '@utils/logger' import { DUMMY } from '@utils/placeholder' @@ -30,7 +30,8 @@ registerCommand({ throw new EmbedRoleGrantError(RoleGrantCreate.ERR.NotGuild) const channel = interaction.channel as TextChannel - RoleGrantCreate.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + RoleGrantCreate.assertMissPerms(bot, channel) const buttonName = interaction.options.getString('button-name', true) const role = interaction.options.getRole('role', true) diff --git a/src/bot/commands/message/handlers/send.ts b/src/bot/commands/message/handlers/send.ts index f5639c0..6dbeb40 100644 --- a/src/bot/commands/message/handlers/send.ts +++ b/src/bot/commands/message/handlers/send.ts @@ -3,7 +3,7 @@ import { registerCommand } from '@commands/registry' import { MESSAGE_SEND_ID } from '@events/interaction-create/message/handlers/send-modal' import { Send } from '@events/interaction-create/message/validators/send' import { encodeSnowflake, getCustomId } from '@utils/component' -import { getAttachments, sendReply } from '@utils/discord' +import { getAttachments, getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { log } from '@utils/logger' import { DUMMY } from '@utils/placeholder' @@ -37,7 +37,8 @@ registerCommand({ throw new SendError(Send.ERR.NotGuild) const channel = interaction.channel as TextChannel - Send.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + Send.assertMissPerms(bot, channel) const attachments = getAttachments(interaction, Send.ATTACHMENT_COUNT) const tempToken = Send.setTempItem(attachments) diff --git a/src/bot/commands/utility/handlers/ping.ts b/src/bot/commands/utility/handlers/ping.ts index d5c86e4..c4857d2 100644 --- a/src/bot/commands/utility/handlers/ping.ts +++ b/src/bot/commands/utility/handlers/ping.ts @@ -1,6 +1,6 @@ import type { ChatInputCommandInteraction, TextChannel } from 'discord.js' import { registerCommand } from '@commands/registry' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { log } from '@utils/logger' import { SlashCommandBuilder } from 'discord.js' @@ -23,7 +23,8 @@ registerCommand({ throw new PingError(Ping.ERR.NotGuild) const channel = interaction.channel as TextChannel - Ping.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + Ping.assertMissPerms(bot, channel) await sendReply(interaction, 'Pong!') } diff --git a/src/bot/events/interaction-create/checkin/handlers/approve-button.ts b/src/bot/events/interaction-create/checkin/handlers/approve-button.ts index 3c964fa..bd46060 100644 --- a/src/bot/events/interaction-create/checkin/handlers/approve-button.ts +++ b/src/bot/events/interaction-create/checkin/handlers/approve-button.ts @@ -3,7 +3,7 @@ import { FLAMEWARDEN_ROLE } from '@config/discord' import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { generateCustomId } from '@utils/component' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { Checkin } from '../validators' @@ -34,7 +34,8 @@ registerInteractionHandler({ const { checkinId, checkinCreatedAt } = Checkin.getButtonId(interaction, interaction.customId) const channel = interaction.channel as TextChannel - Checkin.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + Checkin.assertMissPerms(bot, channel) const flamewarden = await interaction.guild.members.fetch(interaction.member.id) Checkin.assertMember(flamewarden) Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE) diff --git a/src/bot/events/interaction-create/checkin/handlers/custom-button-modal.ts b/src/bot/events/interaction-create/checkin/handlers/custom-button-modal.ts index 00e0f6b..914b1ed 100644 --- a/src/bot/events/interaction-create/checkin/handlers/custom-button-modal.ts +++ b/src/bot/events/interaction-create/checkin/handlers/custom-button-modal.ts @@ -4,7 +4,7 @@ import { FLAMEWARDEN_ROLE } from '@config/discord' import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { generateCustomId } from '@utils/component' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { Checkin } from '../validators' @@ -35,7 +35,8 @@ registerInteractionHandler({ const { checkinId, checkinCreatedAt } = Checkin.getModalReviewId(interaction, interaction.customId) const channel = interaction.channel as TextChannel - Checkin.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + Checkin.assertMissPerms(bot, channel) const flamewarden = await interaction.guild.members.fetch(interaction.member.id) Checkin.assertMember(flamewarden) Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE) diff --git a/src/bot/events/interaction-create/checkin/handlers/custom-button.ts b/src/bot/events/interaction-create/checkin/handlers/custom-button.ts index d7fb3df..adee2a7 100644 --- a/src/bot/events/interaction-create/checkin/handlers/custom-button.ts +++ b/src/bot/events/interaction-create/checkin/handlers/custom-button.ts @@ -3,7 +3,7 @@ import { FLAMEWARDEN_ROLE } from '@config/discord' import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { createCheckinReviewModal, encodeSnowflake, generateCustomId, getCustomId } from '@utils/component' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { Checkin } from '../validators' @@ -31,7 +31,8 @@ registerInteractionHandler({ throw new CheckinCustomButtonError(Checkin.ERR.NotGuild) const channel = interaction.channel as TextChannel - Checkin.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + Checkin.assertMissPerms(bot, channel) const flamewarden = await interaction.guild.members.fetch(interaction.member.id) Checkin.assertMember(flamewarden) Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE) diff --git a/src/bot/events/interaction-create/checkin/handlers/detail-button.ts b/src/bot/events/interaction-create/checkin/handlers/detail-button.ts index 2ce0563..8704e5d 100644 --- a/src/bot/events/interaction-create/checkin/handlers/detail-button.ts +++ b/src/bot/events/interaction-create/checkin/handlers/detail-button.ts @@ -2,7 +2,7 @@ import type { GuildMember, TextChannel } from 'discord.js' import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { generateCustomId } from '@utils/component' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { Checkin } from '../validators' @@ -32,7 +32,8 @@ registerInteractionHandler({ const channel = interaction.channel as TextChannel const member = interaction.member as GuildMember - Checkin.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + Checkin.assertMissPerms(bot, channel) Checkin.assertMember(member) Checkin.assertMemberGrindRoles(member) diff --git a/src/bot/events/interaction-create/checkin/handlers/reject-button.ts b/src/bot/events/interaction-create/checkin/handlers/reject-button.ts index edf73e0..4ee1eb2 100644 --- a/src/bot/events/interaction-create/checkin/handlers/reject-button.ts +++ b/src/bot/events/interaction-create/checkin/handlers/reject-button.ts @@ -3,7 +3,7 @@ import { FLAMEWARDEN_ROLE } from '@config/discord' import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { generateCustomId } from '@utils/component' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { Checkin } from '../validators' @@ -34,7 +34,8 @@ registerInteractionHandler({ const { checkinId, checkinCreatedAt } = Checkin.getButtonId(interaction, interaction.customId) const channel = interaction.channel as TextChannel - Checkin.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + Checkin.assertMissPerms(bot, channel) const flamewarden = await interaction.guild.members.fetch(interaction.member.id) Checkin.assertMember(flamewarden) Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE) diff --git a/src/bot/events/interaction-create/embed/handlers/role-grant-create-button.ts b/src/bot/events/interaction-create/embed/handlers/role-grant-create-button.ts index 5466313..6093cf6 100644 --- a/src/bot/events/interaction-create/embed/handlers/role-grant-create-button.ts +++ b/src/bot/events/interaction-create/embed/handlers/role-grant-create-button.ts @@ -2,7 +2,7 @@ import type { GuildMember, TextChannel } from 'discord.js' import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { generateCustomId } from '@utils/component' -import { getRole, sendReply } from '@utils/discord' +import { getBot, getRole, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { RoleGrantCreate } from '../validators/role-grant-create' @@ -29,7 +29,8 @@ registerInteractionHandler({ throw new EmbedRoleGrantButtonError(RoleGrantCreate.ERR.NotGuild) const channel = interaction.channel as TextChannel - RoleGrantCreate.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + RoleGrantCreate.assertMissPerms(bot, channel) const { roleId } = RoleGrantCreate.getButtonId(interaction, interaction.customId) const member = interaction.member as GuildMember diff --git a/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts b/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts index a2321e8..f73de0f 100644 --- a/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts +++ b/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts @@ -2,7 +2,7 @@ import type { TextChannel } from 'discord.js' import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { createEmbed, encodeSnowflake, generateCustomId, getCustomId } from '@utils/component' -import { getChannel, getRole, sendAsBot, sendReply } from '@utils/discord' +import { getBot, getChannel, getRole, sendAsBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js' @@ -33,7 +33,8 @@ registerInteractionHandler({ const { channelId, roleId, buttonName } = RoleGrantCreate.getModalId(interaction, interaction.customId) const channel = await getChannel(interaction.guild, channelId) as TextChannel RoleGrantCreate.assertChannel(channel) - RoleGrantCreate.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + RoleGrantCreate.assertMissPerms(bot, channel) const role = await getRole(interaction.guild, roleId) RoleGrantCreate.assertRole(role) diff --git a/src/bot/events/interaction-create/grinder-role/handlers/button.ts b/src/bot/events/interaction-create/grinder-role/handlers/button.ts index b9820a3..26ee335 100644 --- a/src/bot/events/interaction-create/grinder-role/handlers/button.ts +++ b/src/bot/events/interaction-create/grinder-role/handlers/button.ts @@ -3,7 +3,7 @@ import { GrinderRole } from '@events/guild-member-update/grinder-role/validators import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { generateCustomId } from '@utils/component' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' @@ -29,7 +29,8 @@ registerInteractionHandler({ throw new GrinderRoleButtonError(GrinderRole.ERR.NotGuild) const channel = interaction.channel as TextChannel - GrinderRole.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + GrinderRole.assertMissPerms(bot, channel) await sendReply(interaction, GrinderRole.MSG.WelcomeNotes) } diff --git a/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts b/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts index c33fb16..f796ab7 100644 --- a/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts +++ b/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts @@ -3,7 +3,7 @@ import { ResetGrinderRoles } from '@events/client-ready/jobs/validators/reset-gr import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { generateCustomId } from '@utils/component' -import { sendReply } from '@utils/discord' +import { getBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' @@ -29,7 +29,8 @@ registerInteractionHandler({ throw new ResetGrinderRolesButtonError(ResetGrinderRoles.ERR.NotGuild) const channel = interaction.channel as TextChannel - ResetGrinderRoles.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + ResetGrinderRoles.assertMissPerms(bot, channel) const { thread } = await ResetGrinderRoles.getButtonId(interaction, interaction.customId) diff --git a/src/bot/events/interaction-create/message/handlers/send-modal.ts b/src/bot/events/interaction-create/message/handlers/send-modal.ts index 184e801..caefe60 100644 --- a/src/bot/events/interaction-create/message/handlers/send-modal.ts +++ b/src/bot/events/interaction-create/message/handlers/send-modal.ts @@ -2,7 +2,7 @@ import type { Attachment, TextChannel } from 'discord.js' import { EVENT_PATH } from '@events/index' import { registerInteractionHandler } from '@events/interaction-create/registry' import { generateCustomId, tempStore } from '@utils/component' -import { getChannel, sendAsBot, sendReply } from '@utils/discord' +import { getBot, getChannel, sendAsBot, sendReply } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { Send } from '../validators/send' @@ -31,7 +31,8 @@ registerInteractionHandler({ const { channelId, tempToken } = Send.getModalId(interaction, interaction.customId) const channel = await getChannel(interaction.guild, channelId) as TextChannel Send.assertChannel(channel) - Send.assertMissPerms(interaction.guild.members.me!, channel) + const bot = await getBot(interaction.guild) + Send.assertMissPerms(bot, channel) const attachments = tempStore.get(tempToken) as Attachment[] Send.delTempItem(attachments, tempToken) diff --git a/src/bot/events/message-create/channel/handlers/check-in.ts b/src/bot/events/message-create/channel/handlers/check-in.ts index f438c59..1e00ef6 100644 --- a/src/bot/events/message-create/channel/handlers/check-in.ts +++ b/src/bot/events/message-create/channel/handlers/check-in.ts @@ -2,6 +2,7 @@ import type { TextChannel } from 'discord.js' import { CHECKIN_CHANNEL } from '@config/discord' import { EVENT_PATH } from '@events/index' import { registerMessageHandler } from '@events/message-create/registry' +import { getBot } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { log } from '@utils/logger' @@ -26,7 +27,8 @@ registerMessageHandler({ throw new CheckInError(CheckIn.ERR.NotGuild) const channel = msg.channel as TextChannel - CheckIn.assertMissPerms(msg.guild.members.me!, channel) + const bot = await getBot(msg.guild) + CheckIn.assertMissPerms(bot, channel) await msg.delete() log.warn(`${channel.name}: deleted unauthorized message from '${msg.author.tag}'`) diff --git a/src/bot/events/message-create/server-booster/handlers/index.ts b/src/bot/events/message-create/server-booster/handlers/index.ts index 825d115..8ddccd5 100644 --- a/src/bot/events/message-create/server-booster/handlers/index.ts +++ b/src/bot/events/message-create/server-booster/handlers/index.ts @@ -2,7 +2,7 @@ import type { TextChannel } from 'discord.js' import { AURA_FARMING_CHANNEL, SYSTEM_ASHES_CHANNEL } from '@config/discord' import { EVENT_PATH } from '@events/index' import { registerMessageHandler } from '@events/message-create/registry' -import { getChannel, sendAsBot } from '@utils/discord' +import { getBot, getChannel, sendAsBot } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { ServerBooster } from '../validators' @@ -26,7 +26,8 @@ registerMessageHandler({ const auraFarmingChannel = await getChannel(msg.guild, AURA_FARMING_CHANNEL) as TextChannel ServerBooster.assertChannel(auraFarmingChannel) - ServerBooster.assertMissPerms(msg.guild.members.me!, auraFarmingChannel) + const bot = await getBot(msg.guild) + ServerBooster.assertMissPerms(bot, auraFarmingChannel) const member = msg.member! ServerBooster.assertMember(member) From a56ccc8b4df4e4ff50c15395daf5bb214029a6f2 Mon Sep 17 00:00:00 2001 From: alfianchii Date: Wed, 31 Dec 2025 12:37:51 +0700 Subject: [PATCH 6/8] chore: func renaming --- .../client-ready/jobs/handlers/notify-waiting-checkin.ts | 2 +- .../events/client-ready/jobs/handlers/reset-grinder-roles.ts | 4 ++-- .../events/guild-member-update/grinder-role/handlers/index.ts | 2 +- src/bot/events/interaction-create/checkin/validators/index.ts | 2 +- .../embed/handlers/role-grant-create-modal.ts | 2 +- .../events/interaction-create/message/handlers/send-modal.ts | 2 +- .../events/message-create/server-booster/handlers/index.ts | 2 +- src/utils/discord/assert.ts | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bot/events/client-ready/jobs/handlers/notify-waiting-checkin.ts b/src/bot/events/client-ready/jobs/handlers/notify-waiting-checkin.ts index 98c4642..7ea1fa5 100644 --- a/src/bot/events/client-ready/jobs/handlers/notify-waiting-checkin.ts +++ b/src/bot/events/client-ready/jobs/handlers/notify-waiting-checkin.ts @@ -28,7 +28,7 @@ registerClientReadyHandler({ const guild = await client.guilds.fetch(process.env.GUILD_ID!) const wardenDutyChannel = await getChannel(guild, WARDEN_DUTY_CHANNEL) as TextChannel - NotifyWaitingCheckin.assertChannel(wardenDutyChannel) + NotifyWaitingCheckin.assertTextChannel(wardenDutyChannel) const checkins = await NotifyWaitingCheckin.getTodayWaitingCheckins(client.prisma) await NotifyWaitingCheckin.sendOpening(guild.name, wardenDutyChannel) diff --git a/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts b/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts index cadb4b2..afb6b68 100644 --- a/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts +++ b/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts @@ -28,9 +28,9 @@ registerClientReadyHandler({ const guild = await client.guilds.fetch(process.env.GUILD_ID!) const grindAshesChannel = await getChannel(guild, GRIND_ASHES_CHANNEL) as TextChannel - ResetGrinderRoles.assertChannel(grindAshesChannel) + ResetGrinderRoles.assertTextChannel(grindAshesChannel) const auditFlameChannel = await getChannel(guild, AUDIT_FLAME_CHANNEL) as TextChannel - ResetGrinderRoles.assertChannel(auditFlameChannel) + ResetGrinderRoles.assertTextChannel(auditFlameChannel) const users = await ResetGrinderRoles.getUsersWithLatestStreak(client.prisma) await ResetGrinderRoles.validateUsers(client.prisma, guild, grindAshesChannel, auditFlameChannel, users) diff --git a/src/bot/events/guild-member-update/grinder-role/handlers/index.ts b/src/bot/events/guild-member-update/grinder-role/handlers/index.ts index c593ffb..60f3bef 100644 --- a/src/bot/events/guild-member-update/grinder-role/handlers/index.ts +++ b/src/bot/events/guild-member-update/grinder-role/handlers/index.ts @@ -27,7 +27,7 @@ registerGuildMemberUpdateHandler({ const oldHasGrinderRole = GrinderRole.isMemberHasRole(oldMember, GRINDER_ROLE) if (newHasGrinderRole && !oldHasGrinderRole) { const channel = await getChannel(newMember.guild, AURA_FARMING_CHANNEL) as TextChannel - GrinderRole.assertChannel(channel) + GrinderRole.assertTextChannel(channel) const button = GrinderRole.generateButton(newMember.guild.id) await sendAsBot( diff --git a/src/bot/events/interaction-create/checkin/validators/index.ts b/src/bot/events/interaction-create/checkin/validators/index.ts index ef3ce65..302e685 100644 --- a/src/bot/events/interaction-create/checkin/validators/index.ts +++ b/src/bot/events/interaction-create/checkin/validators/index.ts @@ -166,7 +166,7 @@ export class Checkin extends CheckinMessage { const hasGrindRole = this.isMemberHasRole(member, newRole.id) const channel = await getChannel(guild, AURA_FARMING_CHANNEL) as TextChannel - this.assertChannel(channel) + this.assertTextChannel(channel) if (!hasGrindRole) { await attachNewGrindRole(member, newRole) diff --git a/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts b/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts index f73de0f..a6220b9 100644 --- a/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts +++ b/src/bot/events/interaction-create/embed/handlers/role-grant-create-modal.ts @@ -32,7 +32,7 @@ registerInteractionHandler({ const { channelId, roleId, buttonName } = RoleGrantCreate.getModalId(interaction, interaction.customId) const channel = await getChannel(interaction.guild, channelId) as TextChannel - RoleGrantCreate.assertChannel(channel) + RoleGrantCreate.assertTextChannel(channel) const bot = await getBot(interaction.guild) RoleGrantCreate.assertMissPerms(bot, channel) const role = await getRole(interaction.guild, roleId) diff --git a/src/bot/events/interaction-create/message/handlers/send-modal.ts b/src/bot/events/interaction-create/message/handlers/send-modal.ts index caefe60..678934e 100644 --- a/src/bot/events/interaction-create/message/handlers/send-modal.ts +++ b/src/bot/events/interaction-create/message/handlers/send-modal.ts @@ -30,7 +30,7 @@ registerInteractionHandler({ const { channelId, tempToken } = Send.getModalId(interaction, interaction.customId) const channel = await getChannel(interaction.guild, channelId) as TextChannel - Send.assertChannel(channel) + Send.assertTextChannel(channel) const bot = await getBot(interaction.guild) Send.assertMissPerms(bot, channel) const attachments = tempStore.get(tempToken) as Attachment[] diff --git a/src/bot/events/message-create/server-booster/handlers/index.ts b/src/bot/events/message-create/server-booster/handlers/index.ts index 8ddccd5..a187ddd 100644 --- a/src/bot/events/message-create/server-booster/handlers/index.ts +++ b/src/bot/events/message-create/server-booster/handlers/index.ts @@ -25,7 +25,7 @@ registerMessageHandler({ throw new ServerBoosterError(ServerBooster.ERR.NotGuild) const auraFarmingChannel = await getChannel(msg.guild, AURA_FARMING_CHANNEL) as TextChannel - ServerBooster.assertChannel(auraFarmingChannel) + ServerBooster.assertTextChannel(auraFarmingChannel) const bot = await getBot(msg.guild) ServerBooster.assertMissPerms(bot, auraFarmingChannel) const member = msg.member! diff --git a/src/utils/discord/assert.ts b/src/utils/discord/assert.ts index 553d746..a451fb5 100644 --- a/src/utils/discord/assert.ts +++ b/src/utils/discord/assert.ts @@ -75,7 +75,7 @@ export class DiscordAssert extends DiscordMessage { throw new DiscordAssertError(this.ERR.MemberAboveMe) } - static assertChannel(channel: TextChannel) { + static assertTextChannel(channel: TextChannel) { if (!channel || channel.type !== ChannelType.GuildText) throw new DiscordAssertError(this.ERR.ChannelNotFound) } @@ -103,7 +103,7 @@ export class DiscordAssert extends DiscordMessage { } const channel = await getChannel(guild, channelId) as TextChannel - this.assertChannel(channel) + this.assertTextChannel(channel) return channel } From 668448829c153b9a74c923f98456931318f587ea Mon Sep 17 00:00:00 2001 From: alfianchii Date: Wed, 31 Dec 2025 12:45:29 +0700 Subject: [PATCH 7/8] chore: rename `assertAllowedChannel` --- src/bot/commands/checkin/handlers/checkin-status.ts | 2 +- src/bot/commands/checkin/handlers/index.ts | 2 +- .../events/client-ready/jobs/handlers/reset-grinder-roles.ts | 2 +- .../events/message-reaction-add/checkin/handlers/submitted.ts | 2 +- src/utils/discord/assert.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bot/commands/checkin/handlers/checkin-status.ts b/src/bot/commands/checkin/handlers/checkin-status.ts index e3245be..4ea942f 100644 --- a/src/bot/commands/checkin/handlers/checkin-status.ts +++ b/src/bot/commands/checkin/handlers/checkin-status.ts @@ -23,7 +23,7 @@ registerCommand({ if (!interaction.inCachedGuild()) throw new CheckinStatusError(CheckinStatus.ERR.NotGuild) - const channel = await CheckinStatus.assertAllowedChannel(interaction.guild, interaction.channelId, AUDIT_FLAME_CHANNEL) + const channel = await CheckinStatus.assertAllowedTextChannel(interaction.guild, interaction.channelId, AUDIT_FLAME_CHANNEL) const bot = await getBot(interaction.guild) CheckinStatus.assertMissPerms(bot, channel) const member = interaction.member as GuildMember diff --git a/src/bot/commands/checkin/handlers/index.ts b/src/bot/commands/checkin/handlers/index.ts index 261337c..17ecd64 100644 --- a/src/bot/commands/checkin/handlers/index.ts +++ b/src/bot/commands/checkin/handlers/index.ts @@ -31,7 +31,7 @@ registerCommand({ if (!interaction.inCachedGuild()) throw new CheckinError(Checkin.ERR.NotGuild) - const channel = await Checkin.assertAllowedChannel(interaction.guild, interaction.channelId, CHECKIN_CHANNEL) + const channel = await Checkin.assertAllowedTextChannel(interaction.guild, interaction.channelId, CHECKIN_CHANNEL) const bot = await getBot(interaction.guild) Checkin.assertMissPerms(bot, channel) diff --git a/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts b/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts index afb6b68..7a99f5f 100644 --- a/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts +++ b/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts @@ -23,7 +23,7 @@ registerClientReadyHandler({ errorTag: () => `${moduleName}: ${ResetGrinderRoles.ERR.UnexpectedResetGrinderRoles}`, exec(client: Client) { try { - cron.schedule('0 0 * * *', async () => { + cron.schedule('*/1 * * * *', async () => { log.check(ResetGrinderRoles.MSG.JobRunning) const guild = await client.guilds.fetch(process.env.GUILD_ID!) diff --git a/src/bot/events/message-reaction-add/checkin/handlers/submitted.ts b/src/bot/events/message-reaction-add/checkin/handlers/submitted.ts index e63cda7..d47446f 100644 --- a/src/bot/events/message-reaction-add/checkin/handlers/submitted.ts +++ b/src/bot/events/message-reaction-add/checkin/handlers/submitted.ts @@ -33,7 +33,7 @@ registerReactionHandler({ const emoji = Checkin.assertEmojis(reaction.emoji.name) Checkin.assertMember(flamewarden) Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE) - await Checkin.assertAllowedChannel(guild, message.channel.id, CHECKIN_CHANNEL) + await Checkin.assertAllowedTextChannel(guild, message.channel.id, CHECKIN_CHANNEL) await Checkin.validateCheckin( client, diff --git a/src/utils/discord/assert.ts b/src/utils/discord/assert.ts index a451fb5..7a556be 100644 --- a/src/utils/discord/assert.ts +++ b/src/utils/discord/assert.ts @@ -97,7 +97,7 @@ export class DiscordAssert extends DiscordMessage { throw new DiscordAssertError(this.ERR.RoleMissing(roleId)) } - static async assertAllowedChannel(guild: Guild, currentChannelId: string, channelId: string) { + static async assertAllowedTextChannel(guild: Guild, currentChannelId: string, channelId: string) { if (currentChannelId !== channelId) { throw new DiscordAssertError(this.ERR.AllowedChannel(channelId)) } From 3118dec4e1ec6d0c8f4b193504c0c468622c3eba Mon Sep 17 00:00:00 2001 From: alfianchii Date: Wed, 31 Dec 2025 13:02:09 +0700 Subject: [PATCH 8/8] fix: do assertion for miss perms and text channel --- src/bot/commands/checkin/handlers/checkin-audit.ts | 1 + src/bot/commands/checkin/handlers/checkin-status.ts | 1 + src/bot/commands/checkin/handlers/index.ts | 1 + .../client-ready/jobs/handlers/notify-waiting-checkin.ts | 4 +++- .../events/client-ready/jobs/handlers/reset-grinder-roles.ts | 5 ++++- .../guild-member-update/grinder-role/handlers/index.ts | 4 +++- .../events/interaction-create/checkin/validators/index.ts | 1 - .../interaction-create/grinder-role/handlers/button.ts | 1 + .../jobs/handlers/reset-grinder-roles-button.ts | 1 + .../events/interaction-create/message/handlers/send-modal.ts | 1 - src/bot/events/message-create/channel/handlers/check-in.ts | 1 + 11 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/bot/commands/checkin/handlers/checkin-audit.ts b/src/bot/commands/checkin/handlers/checkin-audit.ts index f17cc8c..a698c55 100644 --- a/src/bot/commands/checkin/handlers/checkin-audit.ts +++ b/src/bot/commands/checkin/handlers/checkin-audit.ts @@ -26,6 +26,7 @@ registerCommand({ throw new CheckinAuditError(CheckinAudit.ERR.NotGuild) const channel = await getChannel(interaction.guild, AUDIT_FLAME_CHANNEL) as TextChannel + CheckinAudit.assertTextChannel(channel) const bot = await getBot(interaction.guild) CheckinAudit.assertMissPerms(bot, channel) const thread = await CheckinAudit.assertThreadUnderChannel(interaction.guild, interaction.channelId, channel) diff --git a/src/bot/commands/checkin/handlers/checkin-status.ts b/src/bot/commands/checkin/handlers/checkin-status.ts index 4ea942f..69fbb00 100644 --- a/src/bot/commands/checkin/handlers/checkin-status.ts +++ b/src/bot/commands/checkin/handlers/checkin-status.ts @@ -24,6 +24,7 @@ registerCommand({ throw new CheckinStatusError(CheckinStatus.ERR.NotGuild) const channel = await CheckinStatus.assertAllowedTextChannel(interaction.guild, interaction.channelId, AUDIT_FLAME_CHANNEL) + CheckinStatus.assertTextChannel(channel) const bot = await getBot(interaction.guild) CheckinStatus.assertMissPerms(bot, channel) const member = interaction.member as GuildMember diff --git a/src/bot/commands/checkin/handlers/index.ts b/src/bot/commands/checkin/handlers/index.ts index 17ecd64..8ec785e 100644 --- a/src/bot/commands/checkin/handlers/index.ts +++ b/src/bot/commands/checkin/handlers/index.ts @@ -32,6 +32,7 @@ registerCommand({ throw new CheckinError(Checkin.ERR.NotGuild) const channel = await Checkin.assertAllowedTextChannel(interaction.guild, interaction.channelId, CHECKIN_CHANNEL) + Checkin.assertTextChannel(channel) const bot = await getBot(interaction.guild) Checkin.assertMissPerms(bot, channel) diff --git a/src/bot/events/client-ready/jobs/handlers/notify-waiting-checkin.ts b/src/bot/events/client-ready/jobs/handlers/notify-waiting-checkin.ts index 7ea1fa5..024d944 100644 --- a/src/bot/events/client-ready/jobs/handlers/notify-waiting-checkin.ts +++ b/src/bot/events/client-ready/jobs/handlers/notify-waiting-checkin.ts @@ -3,7 +3,7 @@ import process from 'node:process' import { WARDEN_DUTY_CHANNEL } from '@config/discord' import { registerClientReadyHandler } from '@events/client-ready/registry' import { EVENT_PATH } from '@events/index' -import { getChannel } from '@utils/discord' +import { getBot, getChannel } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { log } from '@utils/logger' @@ -29,6 +29,8 @@ registerClientReadyHandler({ const guild = await client.guilds.fetch(process.env.GUILD_ID!) const wardenDutyChannel = await getChannel(guild, WARDEN_DUTY_CHANNEL) as TextChannel NotifyWaitingCheckin.assertTextChannel(wardenDutyChannel) + const bot = await getBot(guild) + NotifyWaitingCheckin.assertMissPerms(bot, wardenDutyChannel) const checkins = await NotifyWaitingCheckin.getTodayWaitingCheckins(client.prisma) await NotifyWaitingCheckin.sendOpening(guild.name, wardenDutyChannel) diff --git a/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts b/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts index 7a99f5f..daf9485 100644 --- a/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts +++ b/src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts @@ -3,7 +3,7 @@ import process from 'node:process' import { AUDIT_FLAME_CHANNEL, GRIND_ASHES_CHANNEL } from '@config/discord' import { registerClientReadyHandler } from '@events/client-ready/registry' import { EVENT_PATH } from '@events/index' -import { getChannel } from '@utils/discord' +import { getBot, getChannel } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { log } from '@utils/logger' @@ -31,6 +31,9 @@ registerClientReadyHandler({ ResetGrinderRoles.assertTextChannel(grindAshesChannel) const auditFlameChannel = await getChannel(guild, AUDIT_FLAME_CHANNEL) as TextChannel ResetGrinderRoles.assertTextChannel(auditFlameChannel) + const bot = await getBot(guild) + ResetGrinderRoles.assertMissPerms(bot, grindAshesChannel) + ResetGrinderRoles.assertMissPerms(bot, auditFlameChannel) const users = await ResetGrinderRoles.getUsersWithLatestStreak(client.prisma) await ResetGrinderRoles.validateUsers(client.prisma, guild, grindAshesChannel, auditFlameChannel, users) diff --git a/src/bot/events/guild-member-update/grinder-role/handlers/index.ts b/src/bot/events/guild-member-update/grinder-role/handlers/index.ts index 60f3bef..29dface 100644 --- a/src/bot/events/guild-member-update/grinder-role/handlers/index.ts +++ b/src/bot/events/guild-member-update/grinder-role/handlers/index.ts @@ -2,7 +2,7 @@ import type { TextChannel } from 'discord.js' import { AURA_FARMING_CHANNEL, GRINDER_ROLE } from '@config/discord' import { registerGuildMemberUpdateHandler } from '@events/guild-member-update/registry' import { EVENT_PATH } from '@events/index' -import { getChannel, sendAsBot } from '@utils/discord' +import { getBot, getChannel, sendAsBot } from '@utils/discord' import { DiscordBaseError } from '@utils/discord/error' import { getModuleName } from '@utils/io' import { GrinderRole } from '../validators' @@ -28,6 +28,8 @@ registerGuildMemberUpdateHandler({ if (newHasGrinderRole && !oldHasGrinderRole) { const channel = await getChannel(newMember.guild, AURA_FARMING_CHANNEL) as TextChannel GrinderRole.assertTextChannel(channel) + const bot = await getBot(newMember.guild) + GrinderRole.assertMissPerms(bot, channel) const button = GrinderRole.generateButton(newMember.guild.id) await sendAsBot( diff --git a/src/bot/events/interaction-create/checkin/validators/index.ts b/src/bot/events/interaction-create/checkin/validators/index.ts index 302e685..100a925 100644 --- a/src/bot/events/interaction-create/checkin/validators/index.ts +++ b/src/bot/events/interaction-create/checkin/validators/index.ts @@ -166,7 +166,6 @@ export class Checkin extends CheckinMessage { const hasGrindRole = this.isMemberHasRole(member, newRole.id) const channel = await getChannel(guild, AURA_FARMING_CHANNEL) as TextChannel - this.assertTextChannel(channel) if (!hasGrindRole) { await attachNewGrindRole(member, newRole) diff --git a/src/bot/events/interaction-create/grinder-role/handlers/button.ts b/src/bot/events/interaction-create/grinder-role/handlers/button.ts index 26ee335..e96bf77 100644 --- a/src/bot/events/interaction-create/grinder-role/handlers/button.ts +++ b/src/bot/events/interaction-create/grinder-role/handlers/button.ts @@ -29,6 +29,7 @@ registerInteractionHandler({ throw new GrinderRoleButtonError(GrinderRole.ERR.NotGuild) const channel = interaction.channel as TextChannel + GrinderRole.assertTextChannel(channel) const bot = await getBot(interaction.guild) GrinderRole.assertMissPerms(bot, channel) diff --git a/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts b/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts index f796ab7..aa1c6c2 100644 --- a/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts +++ b/src/bot/events/interaction-create/jobs/handlers/reset-grinder-roles-button.ts @@ -29,6 +29,7 @@ registerInteractionHandler({ throw new ResetGrinderRolesButtonError(ResetGrinderRoles.ERR.NotGuild) const channel = interaction.channel as TextChannel + ResetGrinderRoles.assertTextChannel(channel) const bot = await getBot(interaction.guild) ResetGrinderRoles.assertMissPerms(bot, channel) diff --git a/src/bot/events/interaction-create/message/handlers/send-modal.ts b/src/bot/events/interaction-create/message/handlers/send-modal.ts index 678934e..60a0bdc 100644 --- a/src/bot/events/interaction-create/message/handlers/send-modal.ts +++ b/src/bot/events/interaction-create/message/handlers/send-modal.ts @@ -30,7 +30,6 @@ registerInteractionHandler({ const { channelId, tempToken } = Send.getModalId(interaction, interaction.customId) const channel = await getChannel(interaction.guild, channelId) as TextChannel - Send.assertTextChannel(channel) const bot = await getBot(interaction.guild) Send.assertMissPerms(bot, channel) const attachments = tempStore.get(tempToken) as Attachment[] diff --git a/src/bot/events/message-create/channel/handlers/check-in.ts b/src/bot/events/message-create/channel/handlers/check-in.ts index 1e00ef6..bb02a90 100644 --- a/src/bot/events/message-create/channel/handlers/check-in.ts +++ b/src/bot/events/message-create/channel/handlers/check-in.ts @@ -27,6 +27,7 @@ registerMessageHandler({ throw new CheckInError(CheckIn.ERR.NotGuild) const channel = msg.channel as TextChannel + CheckIn.assertTextChannel(channel) const bot = await getBot(msg.guild) CheckIn.assertMissPerms(bot, channel)