Skip to content

Commit

Permalink
🚀 Version 5.1.0
Browse files Browse the repository at this point in the history
Updated handler, streaming and vc create
bug fix and improvements.
  • Loading branch information
muralianand12345 committed Jun 12, 2023
1 parent 27e0813 commit 56a4957
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 258 deletions.
23 changes: 15 additions & 8 deletions commands/slash/vcCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module.exports = {
.setDescription('Category/Parent where VC to be created!')
.setRequired(true)
)
.addChannelOption(option =>
option.setName('vc-log')
.setDescription('Logs VC create')
.setRequired(true)
)
.addStringOption(option =>
option.setName('vc-name')
.setDescription('VC name to start with')
Expand All @@ -43,7 +48,7 @@ module.exports = {
const vcChan = await interaction.options.getChannel("vc-id");
if (!guildObj.channels.cache.has(vcChan.id)) {
const embedReply = new EmbedBuilder()
.setColor('Red')
.setColor('#ED4245')
.setDescription(`The Channel does not belong to this server!`)
return interaction.reply({
embeds: [embedReply],
Expand All @@ -52,7 +57,7 @@ module.exports = {
}
if (vcChan.type !== ChannelType.GuildVoice) {
const embedReply = new EmbedBuilder()
.setColor('Red')
.setColor('#ED4245')
.setDescription(`Select only voice channels!`)
return interaction.reply({
embeds: [embedReply],
Expand All @@ -63,7 +68,7 @@ module.exports = {
const vcParent = await interaction.options.getChannel("vc-category");
if (!guildObj.channels.cache.has(vcParent.id)) {
const embedReply = new EmbedBuilder()
.setColor('Red')
.setColor('#ED4245')
.setDescription(`The Category does not belong to this server!`)
return interaction.reply({
embeds: [embedReply],
Expand All @@ -72,7 +77,7 @@ module.exports = {
}
if (vcParent.type !== ChannelType.GuildCategory) {
const embedReply = new EmbedBuilder()
.setColor('Red')
.setColor('#ED4245')
.setDescription(`Select only Category channels!`)
return interaction.reply({
embeds: [embedReply],
Expand All @@ -90,29 +95,31 @@ module.exports = {
});
}

const vcLog = await interaction.options.getChannel("vc-log") || null;
const vcName = await interaction.options.getString("vc-name");

if (!vcName) {
var newData = dateSetupData({
guildID: interaction.guild.id,
vcID: vcChan.id,
parentID: vcParent.id,
name: null
name: null,
logID: vcLog.id
});
await newData.save();
} else {
var newData = dateSetupData({
guildID: interaction.guild.id,
vcID: vcChan.id,
parentID: vcParent.id,
name: vcName
name: vcName,
logID: vcLog.id
});
await newData.save();
}


const embed = new EmbedBuilder()
.setColor('Green')
.setColor("#57F287")
.setDescription(`VC Setup Successfull!`)
.setTimestamp()
return interaction.reply({
Expand Down
2 changes: 1 addition & 1 deletion config/extras/glog.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
}
}

"Note (Delete this after editing the config file)": "Get logs at your own risk. Spying on a specific user or a guild is against discord terms and conditions. You don't want logs, just ignore this update. Memory and CPU usage will be very high (still in beta version). Update will be released to reduced loads and API requests."
"This will make the API request load even worse. Only use if required.""
11 changes: 0 additions & 11 deletions config/extras/streamer.json

This file was deleted.

5 changes: 5 additions & 0 deletions config/extras/streaming.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ROLEID": "",
"GUILDID": "",
"YTROLEID": ""
}
166 changes: 125 additions & 41 deletions events/application/newvccreate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//Updated version with log system and bug fix

const {
EmbedBuilder,
Events,
Expand All @@ -7,18 +9,58 @@ const {
const vcCreateModel = require('../../events/models/vcCreate.js');
const vcCreateCount = require('../../events/models/vcCreateGuild.js');

const mutex = {
_locked: false,
lock: () => {
return new Promise((resolve) => {
const tryLock = () => {
if (!mutex._locked) {
mutex._locked = true;
resolve();
} else {
setTimeout(tryLock, 10);
}
};
tryLock();
});
},
unlock: () => {
mutex._locked = false;
},
};

const cooldowns = new Set();

module.exports = {
name: Events.VoiceStateUpdate,
execute: async (oldState, newState, client) => {

async function EmbedLog(Color, Process, UserID, logChan) {
var logembed = new EmbedBuilder()
.setColor(Color)
.setAuthor({ name: `${Process}` })
.setDescription(`User: <@${UserID}>`);

if (logChan) {
await logChan.send({ embeds: [logembed] });
} else {
console.error("logChan is undefined");
}
}

let User = client.users.cache.get(newState.id);

const vcCreateCounts = await vcCreateCount.findOne({
guildID: newState.guild.id
}).catch(err => console.log(err));
const vcCreateCounts = await vcCreateCount
.findOne({
guildID: newState.guild.id,
})
.catch((err) => console.error(err));

var vcCheckold = await vcCreateModel.findOne({
guildID: oldState.guild.id,
}).catch(err => console.log(err));
var vcCheckold = await vcCreateModel
.findOne({
guildID: oldState.guild.id,
})
.catch((err) => console.error(err));

var targetChannelId;
if (vcCheckold) {
Expand All @@ -27,56 +69,98 @@ module.exports = {

if (targetChannelId && oldState.channel?.id === targetChannelId) {
const channelToUpdate = oldState.guild.channels.cache.get(targetChannelId);
if (channelToUpdate && channelToUpdate.members.size === 0) {
await channelToUpdate.delete().then(async () => {
await vcCreateModel.findOneAndRemove({
guildID: oldState.guild.id,
userID: oldState.id
});
});
if (vcCreateCounts && vcCreateCounts.logID) {
var logChan = client.channels.cache.get(vcCreateCounts.logID);

if (channelToUpdate) {
await mutex.lock();

try {
const cooldownKey = `${oldState.guild.id}-${oldState.id}`;
if (cooldowns.has(cooldownKey) || channelToUpdate.members.size === 0) {
await vcCreateModel.findOneAndRemove({
guildID: oldState.guild.id,
vcID: targetChannelId,
});

await EmbedLog('Red', 'Channel deleted', oldState.id, logChan);

await channelToUpdate.delete().catch((err) => {
console.error(`Error deleting channel: ${err}`);
});

await vcCreateModel.findOneAndRemove({
guildID: oldState.guild.id,
userID: oldState.id,
});
cooldowns.add(cooldownKey);
setTimeout(() => {
cooldowns.delete(cooldownKey);
}, 5000);
} else {
//console.log(`Skipping channel deletion: ${channelToUpdate.name} (${channelToUpdate.id}) due to active members`);
}
} catch (err) {
console.error(err);
} finally {
mutex.unlock();
}
}
}
}

if (vcCreateCounts) {
if (vcCreateCounts && vcCreateCounts.logID) {
if (newState.channel?.id === vcCreateCounts.vcID) {
var vcChecknew = await vcCreateModel.findOne({
guildID: newState.guild.id,
userID: newState.id
}).catch(err => console.log(err));
}).catch(err => console.error(err));

const newChannel = await newState.guild.channels.create({
name: `${vcCreateCounts.name}${User.username}`, //🎤┆
name: `${vcCreateCounts.name}${User.username}`,
parent: vcCreateCounts.parentID,
userLimit: 10,
bitrate: 64000,
type: ChannelType.GuildVoice
});

await newState.setChannel(newChannel).then(async (a) => {

if (vcChecknew) {
await vcCreateModel.findOneAndRemove({
guildID: newState.guild.id,
userID: newState.id
});

var vcAdd = await new vcCreateModel({
guildID: newState.guild.id,
vcID: newState.channel.id,
userID: newState.id
});
await vcAdd.save();

} else if (!vcChecknew) {
var vcAdd = await new vcCreateModel({
guildID: newState.guild.id,
vcID: newState.channel.id,
userID: newState.id
});
await vcAdd.save();
if (newChannel) {
try {
var logChan = client.channels.cache.get(vcCreateCounts.logID);
await mutex.lock();

await newState.setChannel(newChannel);

await EmbedLog('Green', 'Channel Created', newState.id, logChan);

if (vcChecknew) {
await vcCreateModel.findOneAndRemove({
guildID: newState.guild.id,
userID: newState.id
});

var vcAdd = new vcCreateModel({
guildID: newState.guild.id,
vcID: newState.channel.id,
userID: newState.id
});
await vcAdd.save();
} else {
var vcAdd = new vcCreateModel({
guildID: newState.guild.id,
vcID: newState.channel.id,
userID: newState.id
});
await vcAdd.save();
}
} catch (err) {
console.error(err);
await newChannel.delete();
} finally {
mutex.unlock();
}
});
}
}
}
}
}
};
Loading

0 comments on commit 56a4957

Please sign in to comment.