Skip to content
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
6 changes: 4 additions & 2 deletions src/bot/commands/checkin/handlers/checkin-audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, getMember, sendReply } from '@utils/discord'
import { getBot, getChannel, getMember, sendReply } from '@utils/discord'
import { DiscordBaseError } from '@utils/discord/error'
import { log } from '@utils/logger'
import { SlashCommandBuilder } from 'discord.js'
Expand All @@ -26,7 +26,9 @@ 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.assertTextChannel(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)
Expand Down
8 changes: 5 additions & 3 deletions src/bot/commands/checkin/handlers/checkin-status.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -23,8 +23,10 @@ registerCommand({
if (!interaction.inCachedGuild())
throw new CheckinStatusError(CheckinStatus.ERR.NotGuild)

const channel = await CheckinStatus.assertAllowedChannel(interaction.guild, interaction.channelId, AUDIT_FLAME_CHANNEL)
CheckinStatus.assertMissPerms(interaction.client.user, channel)
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
CheckinStatus.assertMember(member)

Expand Down
8 changes: 5 additions & 3 deletions src/bot/commands/checkin/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -31,8 +31,10 @@ registerCommand({
if (!interaction.inCachedGuild())
throw new CheckinError(Checkin.ERR.NotGuild)

const channel = await Checkin.assertAllowedChannel(interaction.guild, interaction.channelId, CHECKIN_CHANNEL)
Checkin.assertMissPerms(interaction.client.user, channel)
const channel = await Checkin.assertAllowedTextChannel(interaction.guild, interaction.channelId, CHECKIN_CHANNEL)
Checkin.assertTextChannel(channel)
const bot = await getBot(interaction.guild)
Checkin.assertMissPerms(bot, channel)

const attachments = getAttachments(interaction, Checkin.ATTACHMENT_COUNT)
const tempToken = Checkin.setTempItem(attachments)
Expand Down
5 changes: 3 additions & 2 deletions src/bot/commands/embed/handlers/role-grant-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -30,7 +30,8 @@ registerCommand({
throw new EmbedRoleGrantError(RoleGrantCreate.ERR.NotGuild)

const channel = interaction.channel as TextChannel
RoleGrantCreate.assertMissPerms(interaction.client.user, 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)
Expand Down
5 changes: 3 additions & 2 deletions src/bot/commands/message/handlers/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -37,7 +37,8 @@ registerCommand({
throw new SendError(Send.ERR.NotGuild)

const channel = interaction.channel as TextChannel
Send.assertMissPerms(interaction.client.user, channel)
const bot = await getBot(interaction.guild)
Send.assertMissPerms(bot, channel)

const attachments = getAttachments(interaction, Send.ATTACHMENT_COUNT)
const tempToken = Send.setTempItem(attachments)
Expand Down
5 changes: 3 additions & 2 deletions src/bot/commands/utility/handlers/ping.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -23,7 +23,8 @@ registerCommand({
throw new PingError(Ping.ERR.NotGuild)

const channel = interaction.channel as TextChannel
Ping.assertMissPerms(interaction.client.user, channel)
const bot = await getBot(interaction.guild)
Ping.assertMissPerms(bot, channel)

await sendReply(interaction, 'Pong!')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -28,7 +28,9 @@ 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 bot = await getBot(guild)
NotifyWaitingCheckin.assertMissPerms(bot, wardenDutyChannel)
const checkins = await NotifyWaitingCheckin.getTodayWaitingCheckins(client.prisma)

await NotifyWaitingCheckin.sendOpening(guild.name, wardenDutyChannel)
Expand Down
11 changes: 7 additions & 4 deletions src/bot/events/client-ready/jobs/handlers/reset-grinder-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -23,14 +23,17 @@ 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!)
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 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -27,7 +27,9 @@ 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 bot = await getBot(newMember.guild)
GrinderRole.assertMissPerms(bot, channel)
const button = GrinderRole.generateButton(newMember.guild.id)

await sendAsBot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getMember, sendReply } from '@utils/discord'
import { getBot, getMember, sendReply } from '@utils/discord'
import { DiscordBaseError } from '@utils/discord/error'
import { getModuleName } from '@utils/io'
import { Checkin } from '../validators'
Expand Down Expand Up @@ -34,7 +34,8 @@ registerInteractionHandler({
const { checkinId, checkinCreatedAt } = Checkin.getButtonId(interaction, interaction.customId)

const channel = interaction.channel as TextChannel
Checkin.assertMissPerms(interaction.client.user, channel)
const bot = await getBot(interaction.guild)
Checkin.assertMissPerms(bot, channel)
const flamewarden = await getMember(interaction.guild, interaction.member.id)
Checkin.assertMember(flamewarden)
Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getMember, sendReply } from '@utils/discord'
import { getBot, getMember, sendReply } from '@utils/discord'
import { DiscordBaseError } from '@utils/discord/error'
import { getModuleName } from '@utils/io'
import { Checkin } from '../validators'
Expand Down Expand Up @@ -35,7 +35,8 @@ registerInteractionHandler({
const { checkinId, checkinCreatedAt } = Checkin.getModalReviewId(interaction, interaction.customId)

const channel = interaction.channel as TextChannel
Checkin.assertMissPerms(interaction.client.user, channel)
const bot = await getBot(interaction.guild)
Checkin.assertMissPerms(bot, channel)
const flamewarden = await getMember(interaction.guild, interaction.member.id)
Checkin.assertMember(flamewarden)
Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getMember, sendReply } from '@utils/discord'
import { getBot, getMember, sendReply } from '@utils/discord'
import { DiscordBaseError } from '@utils/discord/error'
import { getModuleName } from '@utils/io'
import { Checkin } from '../validators'
Expand Down Expand Up @@ -31,7 +31,8 @@ registerInteractionHandler({
throw new CheckinCustomButtonError(Checkin.ERR.NotGuild)

const channel = interaction.channel as TextChannel
Checkin.assertMissPerms(interaction.client.user, channel)
const bot = await getBot(interaction.guild)
Checkin.assertMissPerms(bot, channel)
const flamewarden = await getMember(interaction.guild, interaction.member.id)
Checkin.assertMember(flamewarden)
Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -32,7 +32,8 @@ registerInteractionHandler({

const channel = interaction.channel as TextChannel
const member = interaction.member as GuildMember
Checkin.assertMissPerms(interaction.client.user, channel)
const bot = await getBot(interaction.guild)
Checkin.assertMissPerms(bot, channel)
Checkin.assertMember(member)
Checkin.assertMemberGrindRoles(member)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { getMember, sendReply } from '@utils/discord'
import { getBot, getMember, sendReply } from '@utils/discord'
import { DiscordBaseError } from '@utils/discord/error'
import { getModuleName } from '@utils/io'
import { Checkin } from '../validators'
Expand Down Expand Up @@ -34,7 +34,8 @@ registerInteractionHandler({
const { checkinId, checkinCreatedAt } = Checkin.getButtonId(interaction, interaction.customId)

const channel = interaction.channel as TextChannel
Checkin.assertMissPerms(interaction.client.user, channel)
const bot = await getBot(interaction.guild)
Checkin.assertMissPerms(bot, channel)
const flamewarden = await getMember(interaction.guild, interaction.member.id)
Checkin.assertMember(flamewarden)
Checkin.assertMemberHasRole(flamewarden, FLAMEWARDEN_ROLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.assertChannel(channel)

if (!hasGrindRole) {
await attachNewGrindRole(member, newRole)
Expand Down Expand Up @@ -433,7 +432,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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -29,7 +29,8 @@ registerInteractionHandler({
throw new EmbedRoleGrantButtonError(RoleGrantCreate.ERR.NotGuild)

const channel = interaction.channel as TextChannel
RoleGrantCreate.assertMissPerms(interaction.client.user, channel)
const bot = await getBot(interaction.guild)
RoleGrantCreate.assertMissPerms(bot, channel)

const { roleId } = RoleGrantCreate.getButtonId(interaction, interaction.customId)
const member = interaction.member as GuildMember
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -32,8 +32,9 @@ 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.assertTextChannel(channel)
const bot = await getBot(interaction.guild)
RoleGrantCreate.assertMissPerms(bot, channel)
const role = await getRole(interaction.guild, roleId)
RoleGrantCreate.assertRole(role)

Expand Down
Loading