implement first interaction handling
This commit is contained in:
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,5 @@ export type TextBasedFeatureHandleMessageSend = (
|
||||
|
||||
export type TextBasedFeatureInput = {
|
||||
channelId: string;
|
||||
handleMessageSend: TextBasedFeatureHandleMessageSend;
|
||||
messagesService: TextBasedFeatureHandleMessageSend;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user