refactor: migrate all code to use getGuildConfig() for guild settings
- Update all commands and events to fetch guild config once per execution - Pass config to service methods that need it (ModerationService.issueWarning) - Update terminal service to use guildSettingsService for persistence - Remove direct imports of config for guild-specific settings This consolidates configuration to database-backed guild settings, eliminating the dual config system.
This commit is contained in:
@@ -2,10 +2,14 @@ import { moderationCases } from "@db/schema";
|
||||
import { eq, and, desc } from "drizzle-orm";
|
||||
import { DrizzleClient } from "@shared/db/DrizzleClient";
|
||||
import type { CreateCaseOptions, ClearCaseOptions, SearchCasesFilter } from "@/modules/moderation/moderation.types";
|
||||
import { config } from "@shared/lib/config";
|
||||
import { getUserWarningEmbed } from "@/modules/moderation/moderation.view";
|
||||
import { CaseType } from "@shared/lib/constants";
|
||||
|
||||
export interface ModerationConfig {
|
||||
dmOnWarn?: boolean;
|
||||
autoTimeoutThreshold?: number;
|
||||
}
|
||||
|
||||
export class ModerationService {
|
||||
/**
|
||||
* Generate the next sequential case ID
|
||||
@@ -62,6 +66,7 @@ export class ModerationService {
|
||||
guildName?: string;
|
||||
dmTarget?: { send: (options: any) => Promise<any> };
|
||||
timeoutTarget?: { timeout: (duration: number, reason: string) => Promise<any> };
|
||||
config?: ModerationConfig;
|
||||
}) {
|
||||
const moderationCase = await this.createCase({
|
||||
type: CaseType.WARN,
|
||||
@@ -77,9 +82,10 @@ export class ModerationService {
|
||||
}
|
||||
|
||||
const warningCount = await this.getActiveWarningCount(options.userId);
|
||||
const config = options.config ?? {};
|
||||
|
||||
// Try to DM the user if configured
|
||||
if (config.moderation.cases.dmOnWarn && options.dmTarget) {
|
||||
if (config.dmOnWarn !== false && options.dmTarget) {
|
||||
try {
|
||||
await options.dmTarget.send({
|
||||
embeds: [getUserWarningEmbed(
|
||||
@@ -96,8 +102,8 @@ export class ModerationService {
|
||||
|
||||
// Check for auto-timeout threshold
|
||||
let autoTimeoutIssued = false;
|
||||
if (config.moderation.cases.autoTimeoutThreshold &&
|
||||
warningCount >= config.moderation.cases.autoTimeoutThreshold &&
|
||||
if (config.autoTimeoutThreshold &&
|
||||
warningCount >= config.autoTimeoutThreshold &&
|
||||
options.timeoutTarget) {
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user