added reminder cmd + fixed custom channel
All checks were successful
release-tag / release-image (push) Successful in 22s

This commit is contained in:
2025-01-14 19:22:44 +01:00
parent 3852ff922e
commit 76525b73c9
6 changed files with 239 additions and 81 deletions

View File

@@ -4,7 +4,7 @@ import {
Client,
Events,
IntentsBitField,
VoiceState,
type VoiceState,
type ButtonInteraction,
type CacheType,
type ChatInputCommandInteraction,
@@ -48,7 +48,7 @@ export default class DiscordController extends EventEmitter {
this.customMessageService = new CustomMessageService();
this.dynamicChannelService = new DynamicChannelService();
var channelListeners = new Map();
let channelListeners = new Map();
// log when running
client.once("ready", async () => {
await this.setActivity();
@@ -70,32 +70,48 @@ export default class DiscordController extends EventEmitter {
await this.greetingService.welcome(member);
});
client.on(Events.VoiceStateUpdate, async (oldState: VoiceState, newState: VoiceState) => {
// check if user joined a vc
if (!oldState.channelId && newState.channelId || oldState.channelId != newState.channelId) {
// check if right vc
if (newState.channelId === config.discord.vchannelIdForTwo || newState.channelId === config.discord.vchannelIdForThree || newState.channelId === config.discord.vchannelIdForFour || newState.channelId === config.discord.vchannelIdForGroup) {
const channel = newState.channel;
if (!channel) {
console.error("channel not found");
return;
}
try {
// create new channel with same settings
/*const newChannel = await channel.clone({
client.on(
Events.VoiceStateUpdate,
async (oldState: VoiceState, newState: VoiceState) => {
// check if user joined a vc
if (
(!oldState.channelId && newState.channelId) ||
oldState.channelId !== newState.channelId
) {
// check if right vc
if (
newState.channelId === config.discord.vchannelIdForTwo ||
newState.channelId === config.discord.vchannelIdForThree ||
newState.channelId === config.discord.vchannelIdForFour ||
newState.channelId === config.discord.vchannelIdForGroup
) {
const channel = newState.channel;
if (!channel) {
console.error("channel not found");
return;
}
try {
// create new channel with same settings
/*const newChannel = await channel.clone({
name: channel.name + "; " + newState.member?.displayName,
position: channel.position
});*/
const newChannel = await this.dynamicChannelService.createChannel(
oldState,
newState,
channel,
);
const newChannel = await this.dynamicChannelService.createChannel(oldState, newState, channel);
// move user in new channel
await newState.setChannel(newChannel);
// move user in new channel
await newState.setChannel(newChannel);
// create specific listener for channel
const channelListener = async (oldState: VoiceState, newState: VoiceState) => {
/*if (oldState.channelId === newChannel.id || newState.channelId === newChannel.id) {
// create specific listener for channel
const channelListener = async (
oldState: VoiceState,
newState: VoiceState,
) => {
/*if (oldState.channelId === newChannel.id || newState.channelId === newChannel.id) {
// check if channel empty
if (newChannel.members.size === 0) {
newChannel.delete()
@@ -105,22 +121,27 @@ export default class DiscordController extends EventEmitter {
channelListeners.delete(newChannel.id);
}
}*/
channelListeners = await this.dynamicChannelService.deleteChannel(oldState, newState, newChannel, channelListeners, channelListener);
channelListeners =
await this.dynamicChannelService.deleteChannel(
oldState,
newState,
newChannel,
channelListeners,
channelListener,
);
};
// save listener in map
channelListeners.set(newChannel.id, channelListener);
};
// save listener in map
channelListeners.set(newChannel.id, channelListener);
// add listener
client.on(Events.VoiceStateUpdate, channelListener);
} catch (error) {
console.error("error while duplicating channel", error);
// add listener
client.on(Events.VoiceStateUpdate, channelListener);
} catch (error) {
console.error("error while duplicating channel", error);
}
}
}
}
});
},
);
}
async setActivity() {
@@ -191,6 +212,9 @@ export default class DiscordController extends EventEmitter {
case Commands.Enum.message:
await this.customMessageService.handleInteraction(interaction);
return;
case Commands.Enum.reminder:
await this.greetingService.handleInteraction(interaction);
return;
default:
break;
}