(oldState, newState, client)
| 21 | export default { |
| 22 | name: 'voiceStateUpdate', |
| 23 | async execute(oldState, newState, client) { |
| 24 | if (newState.member.user.bot) return; |
| 25 | |
| 26 | const guildId = newState.guild.id; |
| 27 | const userId = newState.member.id; |
| 28 | const cooldownKey = `${guildId}-${userId}`; |
| 29 | cleanupCooldownEntries(); |
| 30 | |
| 31 | try { |
| 32 | const config = await getJoinToCreateConfig(client, guildId); |
| 33 | |
| 34 | if (!config.enabled || config.triggerChannels.length === 0) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | if (!oldState.channel && newState.channel) { |
| 39 | await handleVoiceJoin(client, newState, config); |
| 40 | } |
| 41 | |
| 42 | if (oldState.channel && !newState.channel) { |
| 43 | await handleVoiceLeave(client, oldState, config); |
| 44 | } |
| 45 | |
| 46 | if (oldState.channel && newState.channel && oldState.channel.id !== newState.channel.id) { |
| 47 | await handleVoiceMove(client, oldState, newState, config); |
| 48 | } |
| 49 | |
| 50 | } catch (error) { |
| 51 | logger.error(`Error in voiceStateUpdate for guild ${guildId}:`, error); |
| 52 | } |
| 53 | |
| 54 | async function handleVoiceJoin(client, state, config) { |
| 55 | const { channel, member } = state; |
| 56 | |
| 57 | if (!config.triggerChannels.includes(channel.id)) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | const now = Date.now(); |
| 62 | if (channelCreationCooldown.has(cooldownKey)) { |
| 63 | const lastCreation = channelCreationCooldown.get(cooldownKey); |
| 64 | if (now - lastCreation < VOICE_CREATE_COOLDOWN_MS) { |
| 65 | logger.warn(`User ${member.id} is on cooldown for channel creation`); |
| 66 | return; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | const existingTempChannel = Object.keys(config.temporaryChannels || {}).find( |
| 71 | tempChannelId => { |
| 72 | const tempInfo = config.temporaryChannels[tempChannelId]; |
| 73 | return tempInfo && tempInfo.ownerId === member.id; |
| 74 | } |
| 75 | ); |
| 76 | |
| 77 | if (existingTempChannel) { |
| 78 | const tempChannel = state.guild.channels.cache.get(existingTempChannel); |
| 79 | if (tempChannel) { |
| 80 | try { |
nothing calls this directly
no test coverage detected