-
Notifications
You must be signed in to change notification settings - Fork 1
/
jointocreate.js
113 lines (111 loc) · 4.99 KB
/
jointocreate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const config = require("./config");
const jointocreatemap = new Map();
module.exports = function (bot) {
const description = {
name: "jointocreate",
filename: "jointocreate.js",
version: "3.2"
}
//log that the module is loaded
console.log(` :: ⬜️ Module: ${description.name} | Loaded version ${description.version} from ("${description.filename}")`)
//voice state update event to check joining/leaving channels
bot.on("voiceStateUpdate", (oldState, newState) => {
// SET CHANNEL NAME STRING
//IGNORE BUT DONT DELETE!
let oldparentname = "unknown"
let oldchannelname = "unknown"
let oldchanelid = "unknown"
if (oldState && oldState.channel && oldState.channel.parent && oldState.channel.parent.name) oldparentname = oldState.channel.parent.name
if (oldState && oldState.channel && oldState.channel.name) oldchannelname = oldState.channel.name
if (oldState && oldState.channelID) oldchanelid = oldState.channelID
let newparentname = "unknown"
let newchannelname = "unknown"
let newchanelid = "unknown"
if (newState && newState.channel && newState.channel.parent && newState.channel.parent.name) newparentname = newState.channel.parent.name
if (newState && newState.channel && newState.channel.name) newchannelname = newState.channel.name
if (newState && newState.channelID) newchanelid = newState.channelID
if (oldState.channelID) {
if (typeof oldState.channel.parent !== "undefined") oldChannelName = `${oldparentname}\n\t**${oldchannelname}**\n*${oldchanelid}*`
else oldChannelName = `-\n\t**${oldparentname}**\n*${oldchanelid}*`
}
if (newState.channelID) {
if (typeof newState.channel.parent !== "undefined") newChannelName = `${newparentname}\n\t**${newchannelname}**\n*${newchanelid}*`
else newChannelName = `-\n\t**${newchannelname}**\n*${newchanelid}*`
}
// JOINED V12
if (!oldState.channelID && newState.channelID) {
if(newState.channelID !== config.JOINTOCREATECHANNEL) return; //if its not the jointocreatechannel skip
jointocreatechannel(newState); //load the function
}
// LEFT V12
if (oldState.channelID && !newState.channelID) {
//get the jointocreatechannel id from the map
if (jointocreatemap.get(`tempvoicechannel_${oldState.guild.id}_${oldState.channelID}`)) {
//fetch it from the guild
var vc = oldState.guild.channels.cache.get(jointocreatemap.get(`tempvoicechannel_${oldState.guild.id}_${oldState.channelID}`));
//if the channel size is below one
if (vc.members.size < 1) {
//delete it from the map
jointocreatemap.delete(`tempvoicechannel_${oldState.guild.id}_${oldState.channelID}`);
//log that it is deleted
console.log(" :: " + oldState.member.user.username + "#" + oldState.member.user.discriminator + " :: Room Deleted")
//delete the voice channel
return vc.delete();
}
else {
}
}
}
// Switch v12
if (oldState.channelID && newState.channelID) {
if (oldState.channelID !== newState.channelID) {
//if its the join to create channel
if(newState.channelID===config.JOINTOCREATECHANNEL)
//make a new channel
jointocreatechannel(oldState);
//BUT if its also a channel ín the map (temp voice channel)
if (jointocreatemap.get(`tempvoicechannel_${oldState.guild.id}_${oldState.channelID}`)) {
//fetch the channel
var vc = oldState.guild.channels.cache.get(jointocreatemap.get(`tempvoicechannel_${oldState.guild.id}_${oldState.channelID}`));
//if the size is under 1
if (vc.members.size < 1) {
//delete it from the map
jointocreatemap.delete(`tempvoicechannel_${oldState.guild.id}_${oldState.channelID}`);
//log it
console.log(" :: " + oldState.member.user.username + "#" + oldState.member.user.discriminator + " :: Room wurde gelöscht")
//delete the room
return vc.delete();
}
else {
}
}
}
}
})
async function jointocreatechannel(user) {
//log it
console.log(" :: " + user.member.user.username + "#" + user.member.user.discriminator + " :: Created a Room")
//user.member.user.send("This can be used to message the member that a new room was created")
await user.guild.channels.create(`${user.member.user.username}'s Room`, {
type: 'voice',
parent: user.channel.parent.id, //or set it as a category id
}).then(async vc => {
//move user to the new channel
user.setChannel(vc);
//set the new channel to the map
jointocreatemap.set(`tempvoicechannel_${vc.guild.id}_${vc.id}`, vc.id);
//change the permissions of the channel
await vc.overwritePermissions([
{
id: user.id,
allow: ['MANAGE_CHANNELS'],
},
{
id: user.guild.id,
allow: ['VIEW_CHANNEL'],
},
]);
})
}
}
//Coded by Tomato#6966!