refactor: resolve architecture disconnects and codebase weaknesses
- Consolidate eventTypes.ts as single source of truth for Redis channels: - Remove duplicate DiscordGatewayEvent interface from eventBroadcaster.ts - Replace all hardcoded channel strings with EventChannels constants - eventTypes.ts is no longer an orphan file - Remove dangerous moderation action feature (selfbot safety): - Remove /messages/:id/moderate endpoint from backend - Remove moderation:action handler from commandHandler.ts - Remove publishFireAndForgetCommand (wrong envelope format) - Verified no remaining references to moderation:action in code - Remove unused getCommandPublisher import from redis-bridge.ts Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
3614d32701
commit
7d6612bb2d
@@ -1,12 +1,6 @@
|
||||
import type { CustomLogger } from "@bete/shared/logger";
|
||||
import Redis from "ioredis";
|
||||
|
||||
export interface DiscordGatewayEvent {
|
||||
type: string;
|
||||
data: unknown;
|
||||
timestamp: number;
|
||||
source: string;
|
||||
}
|
||||
import { type DiscordGatewayEvent, EventChannels } from "./eventTypes.js";
|
||||
|
||||
export class RedisEventPublisher {
|
||||
private redis: Redis;
|
||||
@@ -49,7 +43,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async messageCreated(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:message:created", {
|
||||
await this.publisher.publish(EventChannels.MESSAGE_CREATED, {
|
||||
type: "message_created",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
@@ -58,7 +52,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async messageUpdated(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:message:updated", {
|
||||
await this.publisher.publish(EventChannels.MESSAGE_UPDATED, {
|
||||
type: "message_updated",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
@@ -67,7 +61,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async messageDeleted(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:message:deleted", {
|
||||
await this.publisher.publish(EventChannels.MESSAGE_DELETED, {
|
||||
type: "message_deleted",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
@@ -76,7 +70,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async messageAnalyzed(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:message:analyzed", {
|
||||
await this.publisher.publish(EventChannels.MESSAGE_ANALYZED, {
|
||||
type: "message_analyzed",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
@@ -85,7 +79,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async attachmentCreated(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:attachment:created", {
|
||||
await this.publisher.publish(EventChannels.ATTACHMENT_CREATED, {
|
||||
type: "attachment_created",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
@@ -94,7 +88,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async attachmentUploaded(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:attachment:uploaded", {
|
||||
await this.publisher.publish(EventChannels.ATTACHMENT_UPLOADED, {
|
||||
type: "attachment_uploaded",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
@@ -103,7 +97,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async voiceRecordingStarted(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:voice:started", {
|
||||
await this.publisher.publish(EventChannels.VOICE_STARTED, {
|
||||
type: "voice_recording_started",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
@@ -112,7 +106,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async voiceRecordingStopped(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:voice:stopped", {
|
||||
await this.publisher.publish(EventChannels.VOICE_STOPPED, {
|
||||
type: "voice_recording_stopped",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
@@ -121,7 +115,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async voiceRecordingUploaded(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:voice:uploaded", {
|
||||
await this.publisher.publish(EventChannels.VOICE_UPLOADED, {
|
||||
type: "voice_recording_uploaded",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
@@ -140,7 +134,7 @@ export class EventBroadcaster {
|
||||
userId: string,
|
||||
metadata?: Record<string, unknown>,
|
||||
): Promise<void> {
|
||||
await this.publisher.publish("discord:voice:pcm", {
|
||||
await this.publisher.publish(EventChannels.VOICE_PCM, {
|
||||
type: "voice_pcm_data",
|
||||
data: {
|
||||
userId,
|
||||
@@ -161,7 +155,7 @@ export class EventBroadcaster {
|
||||
userId: string,
|
||||
data: { username: string; avatar: string; speaking: boolean },
|
||||
): Promise<void> {
|
||||
await this.publisher.publish("discord:voice:active_user", {
|
||||
await this.publisher.publish(EventChannels.VOICE_ACTIVE_USER, {
|
||||
type: "voice_active_user",
|
||||
data: {
|
||||
userId,
|
||||
@@ -173,7 +167,7 @@ export class EventBroadcaster {
|
||||
}
|
||||
|
||||
async analysisQueueStatus(data: unknown): Promise<void> {
|
||||
await this.publisher.publish("discord:analysis:queue_status", {
|
||||
await this.publisher.publish(EventChannels.ANALYSIS_QUEUE_STATUS, {
|
||||
type: "analysis_queue_status",
|
||||
data,
|
||||
timestamp: Date.now(),
|
||||
|
||||
Reference in New Issue
Block a user