Skip to content
Open
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: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ DISCORD_TOKEN=
LOG_DIR=
API_TOKEN=
WEBHOOK_QUERY_SECRET=
WEBHOOK_URL=
WEBHOOK_URL=
QUEUE_BLACKLIST_ROLE_ID=
TOURNEY_BLACKLIST_ROLE_ID=
7 changes: 5 additions & 2 deletions src/command-handlers/moderation/createBan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { logModerationEvent } from '../../utils/logModerationEvent'
import { sendDm } from '../../utils/sendDm'
import { resolveModerationTarget } from './resolveModerationTarget'
import { getGuild } from '../../client'
import { env } from 'env'

const DAY_IN_MS = 24 * 60 * 60 * 1000

Expand Down Expand Up @@ -120,10 +121,12 @@ export async function createBan({

// add blacklisted roles for visibility + tourney blacklisting
const member = await guild.members.fetch(userId).catch(() => null)
console.log('Member found for role add:', !!member)
if (member) {
await Promise.all([
member.roles.add('1354296037094854788'),
member.roles.add('1344793211146600530'),
member.roles.add(env.QUEUE_BLACKLIST_ROLE_ID),
member.roles.add(env.TOURNEY_BLACKLIST_ROLE_ID),

])
}

Expand Down
5 changes: 3 additions & 2 deletions src/command-handlers/moderation/removeBan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { pool } from '../../db'
import { createEmbedType, logStrike } from '../../utils/logCommandUse'
import { logModerationEvent } from '../../utils/logModerationEvent'
import { sendDm } from '../../utils/sendDm'
import { env } from 'env'

export class RemoveBanError extends Error {
code: 'NOT_FOUND'
Expand Down Expand Up @@ -58,8 +59,8 @@ export async function removeBan({ userId, blame, reason }: RemoveBanParams) {
const member = await guild.members.fetch(userId).catch(() => null)
if (member) {
await Promise.all([
member.roles.remove('1354296037094854788'),
member.roles.remove('1344793211146600530'),
member.roles.remove(env.QUEUE_BLACKLIST_ROLE_ID),
member.roles.remove(env.TOURNEY_BLACKLIST_ROLE_ID),
])
}

Expand Down
3 changes: 3 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ const envSchema = z.object({
z.string().default(path.join(process.cwd(), 'fonts')),
),
GUILD_ID: z.string().trim().min(1, 'GUILD_ID is required'),
QUEUE_BLACKLIST_ROLE_ID: z.string().trim().min(1, 'QUEUE_BLACKLIST_ROLE_ID is required'),
TOURNEY_BLACKLIST_ROLE_ID: z.string().trim().min(1, 'TOURNEY_BLACKLIST_ROLE_ID is required'),
LOG_DIR: z.preprocess(
emptyStringToUndefined,
z.string().default(path.join(process.cwd(), 'logs')),
),

NODE_ENV: z.preprocess(
emptyStringToUndefined,
z.enum(['development', 'production', 'test']).default('production'),
Expand Down
15 changes: 14 additions & 1 deletion src/utils/automaticUnbans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { logModerationEvent } from './logModerationEvent'
import { sendDm } from './sendDm'
import { createEmbedType, logStrike } from './logCommandUse'
import { getGuild } from '../client'
import { env } from 'env'

export async function automaticUnban(ban: Bans) {
// remove ban
Expand All @@ -14,7 +15,17 @@ export async function automaticUnban(ban: Bans) {
await sendDm(userId, moderationMessages.banLiftedDm({ expired: true }))

const guild = await getGuild()
const username = (await guild.members.fetch(userId))?.displayName ?? userId
// Added member fetch to remove blacklisted roles when unbanning a user whose ban has expired.
const member = await guild.members.fetch(userId).catch(() => null)
const username = member?.displayName ?? userId

if (member) {
await Promise.all([
member.roles.remove(env.QUEUE_BLACKLIST_ROLE_ID),
member.roles.remove(env.TOURNEY_BLACKLIST_ROLE_ID),
])
}


// log ban removal
const embedType = createEmbedType(
Expand Down Expand Up @@ -44,6 +55,7 @@ export async function automaticUnban(ban: Bans) {
})
}


// check all bans for timeout. todo: replace with an api call from external service that is running a cronjob
export async function checkBans() {
const res = await pool.query('SELECT * FROM "bans"')
Expand All @@ -62,3 +74,4 @@ export async function checkBans() {
await automaticUnban(expiredBan)
}
}