diff --git a/README.md b/README.md index f588472..1606b21 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ clean up p/vileimagery, its horrendous **_Note:_** _versions before this were not uploaded to the repo, this is not the first version._ 1.15 - added p/recent and p/rejoin, p/recent sends the most recently deleted message, p/rejoin calls rejoin function on voice connections. also added some broken code for a voiceStateUpdate event but im too lazy to fix it so ill do that basically never. also deleted some useless line from .gitignore - 1.15.1 - fixed exploit with recurring p/recents + 1.15.1 - fixed exploit with recursive p/recents + 1.15.2 - fixed voiceStateUpdate event, also errors now ping me (please don't abuse i will disable it if you do) --- diff --git a/src/events/voiceStateUpdate.js b/src/events/voiceStateUpdate.js index 74305a9..62743b0 100644 --- a/src/events/voiceStateUpdate.js +++ b/src/events/voiceStateUpdate.js @@ -1,16 +1,49 @@ import { getVoiceConnection } from "@discordjs/voice"; -export default async function (oldState, newState) { - if ((oldState.channelId = getVoiceConnection(oldState.guild.id))) { - if ((newState.channelId = undefined)) { - let channel = await client.channels.cache.get(oldState.channelId); - if (!channel) { - console.log("unable to find voice channel "); - return; - } - memberCount = channel.members.size; - if (MemberCount <= 1) { - channel.leave(); +export default async function (oldState, newState, client) { + if (oldState.channelId === null || typeof oldState.channelId == "undefined") { + console.log(`voice state update for joining vc, ignoring`); + return; + } + const guild = oldState.guild; + + let connection; + try { + connection = getVoiceConnection(guild.id); + } catch (err) { + console.log(err); + const debugchannel = client.channels.cache.get("1148814162273763418"); + debugchannel.send( + "invalid voiceStateUpdate: no guild found. check console for details" + ); + return; + } + if (connection) { + if (connection.joinConfig.channelId === oldState.channelId) { + if (newState.channelId !== undefined) { + console.log( + oldState.guild.members.cache.filter( + (member) => + member.voice.channelId === connection.joinConfig.channelId + ) + ); + console.log( + oldState.guild.members.cache.filter( + (member) => + member.voice.channelId === connection.joinConfig.channelId + ).size + ); + if ( + guild.members.cache.filter( + (member) => + member.voice.channelId === connection.joinConfig.channelId + ).size <= 1 + ) { + connection.destroy(); + console.log( + `destroyed voice connection for guild ${guild.id} in channel ${connection.joinConfig.channelId}` + ); + } } } } diff --git a/src/index.js b/src/index.js index 3413c49..6f81886 100644 --- a/src/index.js +++ b/src/index.js @@ -23,7 +23,7 @@ client.on("guildMemberAdd", (member) => { }); client.on("messageDelete", async (message) => { - events.messageDelete(message); + events.messageDelete(message, client); }); client.on("messageCreate", async (message) => { @@ -31,11 +31,11 @@ client.on("messageCreate", async (message) => { }); client.on("interactionCreate", (interaction) => { - events.interactionCreate(interaction); + events.interactionCreate(interaction, client); }); client.on("voiceStateUpdate", (oldState, newState) => { - events.voiceStateUpdate(oldState, newState); + events.voiceStateUpdate(oldState, newState, client); }); register(); diff --git a/src/util/discordAction.js b/src/util/discordAction.js index 162f0df..6097ce4 100644 --- a/src/util/discordAction.js +++ b/src/util/discordAction.js @@ -20,10 +20,10 @@ export function sendError(message) { const channel = client.channels.cache.get("1148814162273763418"); let msg; try { - msg = channel.send(`**error:** ${message}`); + msg = channel.send(`**error:** ${message} +<@440163494529073152> you fucked something`); console.log(message); } catch (err) { - sendError(err.rawError.message); console.log(err); return undefined; }