implement first interaction handling

This commit is contained in:
2026-02-18 00:56:54 +01:00
parent cb7235fd69
commit 6053692bc1
31 changed files with 278 additions and 493 deletions

View File

@@ -0,0 +1,20 @@
import { VoiceChannels } from "entities/channels/channels.schema";
import z from "zod";
export const DynamicVoiceChannelKeyOptions = [
VoiceChannels.enum["for-two"],
VoiceChannels.enum["for-three"],
VoiceChannels.enum["for-four"],
VoiceChannels.enum["for-group"],
] as const;
export const DynamicVoiceChannelKeys = z.enum(DynamicVoiceChannelKeyOptions);
export const DynamicVoiceChannel = z.object({
channelId: z.string(),
size: z.number(),
key: DynamicVoiceChannelKeys,
});
export const DynamicVoiceChannels = z.array(DynamicVoiceChannel);
export const DynamicVoiceChannelsMap = z.map(z.string(), DynamicVoiceChannel);

View File

@@ -0,0 +1,62 @@
import type { VoiceChannelsServiceInterface } from "entities/channels/voice/voice-channels.service";
import type z from "zod";
import type {
DynamicVoiceChannels,
DynamicVoiceChannelsMap,
} from "./dynamic-voice-channels.schema";
export class DynamicVoiceChannelsService<
C extends { name: string; id: string },
> {
private voiceChannelsService: VoiceChannelsServiceInterface<C>;
dynamicVoiceChannels: z.output<typeof DynamicVoiceChannels>;
validChannelIds = new Set<string>();
dynamicVoiceChannelsMap: z.output<typeof DynamicVoiceChannelsMap>;
createdChannelIdsSet = new Set<string>();
constructor(
voiceChannelsService: VoiceChannelsServiceInterface<C>,
dynamicVoiceChannels: z.output<typeof DynamicVoiceChannels>,
) {
this.voiceChannelsService = voiceChannelsService;
this.dynamicVoiceChannels = dynamicVoiceChannels;
this.dynamicVoiceChannelsMap = new Map(
dynamicVoiceChannels.map((channel) => [channel.channelId, channel]),
);
this.validChannelIds = new Set(
dynamicVoiceChannels.map((channel) => channel.channelId),
);
}
async createDynamicVoiceChannel(id: string): Promise<C | void> {
if (this.validChannelIds.has(id)) {
// Channel is one of the dynamic voice channels, create a new one based on it
const channel = await this.voiceChannelsService.getVoiceChannelById(id);
if (!channel) {
throw new Error(`Channel with id ${id} not found`);
}
const newChannel = await this.voiceChannelsService.cloneVoiceChannel(
channel,
{
name: channel.name,
},
);
this.createdChannelIdsSet.add(newChannel.id);
return newChannel;
} else {
// Channel is not a dynamic voice channel, do nothing
}
}
deleteDynamicVoiceChannel(channelId: string): Promise<void> {
this.createdChannelIdsSet.delete(channelId);
return this.voiceChannelsService.deleteVoiceChannel(channelId);
}
}

View File

@@ -5,5 +5,5 @@ export type TextBasedFeatureHandleMessageSend = (
export type TextBasedFeatureInput = {
channelId: string;
handleMessageSend: TextBasedFeatureHandleMessageSend;
messagesService: TextBasedFeatureHandleMessageSend;
};