feat: add multimodal analysis support to LLM moderation client by processing image attachments

This commit is contained in:
MythEclipse
2026-05-17 23:56:04 +07:00
parent 059d569566
commit 51dc1f8869
21 changed files with 443 additions and 83 deletions
+8 -2
View File
@@ -17,7 +17,10 @@ import { createMusicPlayer } from "./musicPlayer";
export interface MediaControllerDependencies {
isVoiceConnected?: () => boolean;
isBrowserStreaming?: () => boolean;
resolveMediaSource?: (source: string, mode?: MediaMode) => Promise<ResolvedMediaSource>;
resolveMediaSource?: (
source: string,
mode?: MediaMode,
) => Promise<ResolvedMediaSource>;
musicPlayer?: MusicPlayer;
screenController?: ScreenShareController;
onStateChange?: (state: MediaState) => void;
@@ -91,7 +94,10 @@ export class MediaController {
// reject to avoid stealing the shared player. If this controller started
// the screenPlayback, stop it and proceed.
if (this.screenPlayback || this.dependencies.screenController?.isActive()) {
if (this.dependencies.screenController?.isActive() && !this.screenPlayback) {
if (
this.dependencies.screenController?.isActive() &&
!this.screenPlayback
) {
throw new AppError("Another media mode is active", "MEDIA_BUSY", 409);
}
this.screenPlayback?.stop();
+13 -10
View File
@@ -20,7 +20,7 @@ export function createMediaResolver(
return async function resolve(
input: string,
mode: MediaMode = "music"
mode: MediaMode = "music",
): Promise<ResolvedMediaSource> {
const source = input.trim();
if (!source) {
@@ -34,17 +34,19 @@ export function createMediaResolver(
const url = parseUrl(source);
if (url && isYouTubeUrl(url)) {
const metadata = await ytdlp.getMetadata(source);
const directUrl = mode === "screen"
? await ytdlp.getDirectVideoUrl(source)
: await ytdlp.getDirectAudioUrl(source);
const directUrl =
mode === "screen"
? await ytdlp.getDirectVideoUrl(source)
: await ytdlp.getDirectAudioUrl(source);
return { source: directUrl, title: metadata.title, kind: "youtube" };
}
if (url && isSpotifyTrackUrl(url)) {
const result = await playDlResolver.resolveSpotifyTrack(source);
const directUrl = mode === "screen"
? await ytdlp.getDirectVideoUrl(result.url)
: await ytdlp.getDirectAudioUrl(result.url);
const directUrl =
mode === "screen"
? await ytdlp.getDirectVideoUrl(result.url)
: await ytdlp.getDirectAudioUrl(result.url);
return { source: directUrl, title: result.title, kind: "spotify" };
}
@@ -62,9 +64,10 @@ export function createMediaResolver(
if (!url && !looksLikeUrl(source)) {
const result = await playDlResolver.searchYouTube(source);
const directUrl = mode === "screen"
? await ytdlp.getDirectVideoUrl(result.url)
: await ytdlp.getDirectAudioUrl(result.url);
const directUrl =
mode === "screen"
? await ytdlp.getDirectVideoUrl(result.url)
: await ytdlp.getDirectAudioUrl(result.url);
return { source: directUrl, title: result.title, kind: "search" };
}
+9 -6
View File
@@ -1,7 +1,4 @@
import {
Streamer,
playPreparedStream,
} from "../streaming";
import { Streamer, playPreparedStream } from "../streaming";
import { AppError } from "../errors";
import { createChildLogger } from "../logger";
import { discordPlayer } from "../player";
@@ -23,8 +20,14 @@ export interface ScreenShareControllerDependencies {
getDirectVideoUrl?: (source: string) => Promise<string>;
streamer: Streamer;
useTranscoder?: boolean;
onBeforeStreamStart?: (guildId: string, channelId: string) => Promise<void> | void;
onAfterStreamEnd?: (guildId: string, channelId: string) => Promise<void> | void;
onBeforeStreamStart?: (
guildId: string,
channelId: string,
) => Promise<void> | void;
onAfterStreamEnd?: (
guildId: string,
channelId: string,
) => Promise<void> | void;
onStreamStart?: () => void;
onStreamEnd?: () => void;
}