Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/discord/events/voiceStateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export const voiceStateUpdate: VoiceStateUpdateEvent = {

// Check if the user actually left or joined a channel before logging
if (New.channel !== Old.channel) {
logTent(Old, New);
await logTent(Old, New);
}

teardownTent(Old);
await teardownTent(Old);
},
};

Expand Down
24 changes: 19 additions & 5 deletions src/discord/utils/tents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ export async function pitchTent(
});
}

// Store timeouts for each channel to handle host rejoining
const hostTimeouts: { [channelId: string]: NodeJS.Timeout } = {};

/**
* Template
* @param {VoiceState} Old The previous voice state
Expand All @@ -151,15 +154,29 @@ export async function teardownTent(
Old:VoiceState,
): Promise<void> {
const tempVoiceCategory = await Old.guild.channels.fetch(env.CATEGORY_VOICE) as CategoryChannel;
tempVoiceCategory.children.cache.forEach(channel => {
const deletePromises = tempVoiceCategory.children.cache.map(async channel => {
// Get the number of humans in the channel
const humans = channel.members.filter(member => !member.user.bot).size;

// If the channel is a voice channel, and it's a tent, and there are no humans in it delete it
if (channel.type === ChannelType.GuildVoice && channel.name.includes('⛺') && humans < 1) {
channel.delete('Removing temporary voice chan!');
// Clear any pending host transfer timeout for this channel
if (hostTimeouts[channel.id]) {
clearTimeout(hostTimeouts[channel.id]);
delete hostTimeouts[channel.id];
}

try {
await Old.guild.channels.fetch(channel.id);
// If fetch succeeds, delete the channel
await channel.delete('Removing temporary voice chan!');
} catch (err) {
// Channel was likely already deleted or doesn't exist
}
}
});

await Promise.all(deletePromises);
}

export async function transferTent(
Expand Down Expand Up @@ -200,9 +217,6 @@ export async function transferTent(
}
}

// Store timeouts for each channel to handle host rejoining
const hostTimeouts: { [channelId: string]: NodeJS.Timeout } = {};

const joinMessages = [
'Hope you brought snacks!',
'The marshmallows are crisp!',
Expand Down
14 changes: 14 additions & 0 deletions src/global/utils/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,20 @@ async function checkBirthdays() {
return;
}

if (!user.discord_id) {
log.debug(F, `User ${user.id} has no discord_id, skipping birthday message`);
return;
}

// Check if user is in the server
const guild = await discordClient.guilds.fetch(env.DISCORD_GUILD_ID);
const member = await guild.members.fetch(user.discord_id).catch(() => null);

if (!member) {
log.debug(F, `User ${user.discord_id} is not in the server, skipping birthday message`);
return;
}

// Send message to VIP lounge channel
const vipLounge = await discordClient.channels.fetch(env.CHANNEL_VIPLOUNGE) as TextChannel;
await vipLounge.send(`Happy Birthday, <@${user.discord_id}>! 🎉`);
Expand Down
Loading