53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import config from "config";
|
|
import client from "lib/client";
|
|
import { getRandomInt } from "lib/utils";
|
|
import { } from "./dynamicChannel.components.ts";
|
|
import {
|
|
Client,
|
|
EmbedBuilder,
|
|
type Message,
|
|
type CacheType,
|
|
type GuildMember,
|
|
type Interaction,
|
|
type OmitPartialGroupDMChannel,
|
|
VoiceState,
|
|
VoiceChannel,
|
|
StageChannel,
|
|
Events,
|
|
type VoiceBasedChannel,
|
|
} from "discord.js";
|
|
|
|
export class DynamicChannelService {
|
|
async handleInteraction(interaction: Interaction<CacheType>) {
|
|
// todo
|
|
}
|
|
|
|
async createChannel(oldState: VoiceState, newState: VoiceState, channel: VoiceBasedChannel): Promise<StageChannel | VoiceChannel> {
|
|
console.log("createChannel()");
|
|
|
|
const newChannel = await channel.clone({
|
|
name: channel.name + " " + newState.member?.displayName,
|
|
position: channel.position
|
|
});
|
|
|
|
return newChannel;
|
|
}
|
|
|
|
async deleteChannel(oldState: VoiceState, newState: VoiceState, newChannel: StageChannel | VoiceChannel, channelListeners: Map<any, any>, channelListener: (oldState: VoiceState, newState: VoiceState) => void) {
|
|
|
|
console.log("deleteChannel()");
|
|
|
|
if (oldState.channelId === newChannel.id || newState.channelId === newChannel.id) {
|
|
|
|
if (newChannel.members.size === 0) {
|
|
newChannel.delete()
|
|
.catch(console.error);
|
|
|
|
client.removeListener(Events.VoiceStateUpdate, channelListener);
|
|
channelListeners.delete(newChannel.id);
|
|
}
|
|
}
|
|
return channelListeners;
|
|
}
|
|
}
|