-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
224 lines (202 loc) · 8.14 KB
/
setup.js
File metadata and controls
224 lines (202 loc) · 8.14 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
const { Client, GatewayIntentBits, PermissionFlagsBits, ChannelType } = require('discord.js');
const config = require('./config');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function question(query) {
return new Promise(resolve => rl.question(query, resolve));
}
async function setup() {
console.log('=================================');
console.log('Discord Bot Setup Wizard');
console.log('=================================\n');
// Get bot token
let token = config.getToken();
if (!token) {
token = await question('Enter your bot token: ');
config.setToken(token);
console.log('✅ Token saved and encrypted!\n');
} else {
console.log('✅ Token already configured!\n');
}
// Get guild ID
let guildId = config.guildId;
if (!guildId) {
guildId = await question('Enter your server (guild) ID: ');
config.setGuildId(guildId);
console.log('✅ Server ID saved!\n');
} else {
console.log('✅ Server ID already configured!\n');
}
console.log('Connecting to Discord...\n');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
]
});
client.once('clientReady', async () => {
console.log(`✅ Connected as ${client.user.tag}\n`);
const guild = client.guilds.cache.get(guildId);
if (!guild) {
console.error('❌ Could not find server with that ID!');
process.exit(1);
}
console.log(`Found server: ${guild.name}\n`);
try {
// Create or get jail role
let jailRole = guild.roles.cache.find(r => r.name === 'Jailed');
if (!jailRole) {
console.log('Creating "Jailed" role...');
jailRole = await guild.roles.create({
name: 'Jailed',
color: 0x808080,
permissions: [],
reason: 'Bot setup - jail role'
});
console.log('✅ Jail role created!');
} else {
console.log('✅ Jail role already exists!');
}
config.setJailRole(jailRole.id);
// Create category
let category = guild.channels.cache.find(
c => c.type === ChannelType.GuildCategory && c.name === 'voice channels'
);
if (!category) {
console.log('\nCreating "Voice Channels" category...');
category = await guild.channels.create({
name: 'voice channels',
type: ChannelType.GuildCategory,
reason: 'Bot setup - voice category'
});
console.log('✅ Category created!');
} else {
console.log('\n✅ Category already exists!');
}
config.setCategoryId(category.id);
// Create Join to Create channel
let jtcChannel = guild.channels.cache.find(
c => c.type === ChannelType.GuildVoice && c.name === 'join to create'
);
if (!jtcChannel) {
console.log('\nCreating "Join to Create" voice channel...');
jtcChannel = await guild.channels.create({
name: 'join to create',
type: ChannelType.GuildVoice,
parent: category.id,
reason: 'Bot setup - join to create channel'
});
console.log('✅ Join to Create channel created!');
} else {
console.log('\n✅ Join to Create channel already exists!');
}
config.setJoinToCreateChannel(jtcChannel.id);
// Welcome channel setup
console.log('\n=================================');
console.log('Welcome Channel Setup');
console.log('=================================');
const welcomeChoice = await question('Do you want to set up a welcome channel? (yes/no): ');
if (welcomeChoice.toLowerCase() === 'yes' || welcomeChoice.toLowerCase() === 'y') {
const welcomeOption = await question('Enter channel ID, or type "create" to make a new channel: ');
if (welcomeOption.toLowerCase() === 'create') {
const welcomeName = await question('Enter name for welcome channel (default: welcomes): ') || 'welcomes';
console.log(`Creating "${welcomeName}" channel...`);
const welcomeChannel = await guild.channels.create({
name: welcomeName,
type: ChannelType.GuildText,
reason: 'Bot setup - welcome channel'
});
config.setWelcomeChannel(welcomeChannel.id);
console.log('✅ Welcome channel created!');
} else {
config.setWelcomeChannel(welcomeOption);
console.log('✅ Welcome channel set!');
}
} else {
console.log('⏭️ Skipped welcome channel setup');
}
// Leave channel setup
console.log('\n=================================');
console.log('Leave Channel Setup');
console.log('=================================');
const leaveChoice = await question('Do you want to set up a leave channel? (yes/no): ');
if (leaveChoice.toLowerCase() === 'yes' || leaveChoice.toLowerCase() === 'y') {
const leaveOption = await question('Enter channel ID, or type "create" to make a new channel: ');
if (leaveOption.toLowerCase() === 'create') {
const leaveName = await question('Enter name for leave channel (default: goodbyes): ') || 'goodbyes';
console.log(`Creating "${leaveName}" channel...`);
const leaveChannel = await guild.channels.create({
name: leaveName,
type: ChannelType.GuildText,
reason: 'Bot setup - leave channel'
});
config.setLeaveChannel(leaveChannel.id);
console.log('✅ Leave channel created!');
} else {
config.setLeaveChannel(leaveOption);
console.log('✅ Leave channel set!');
}
} else {
console.log('⏭️ Skipped leave channel setup');
}
// Booster channel setup
console.log('\n=================================');
console.log('Booster Channel Setup');
console.log('=================================');
const boosterChoice = await question('Do you want to set up a booster channel? (yes/no): ');
if (boosterChoice.toLowerCase() === 'yes' || boosterChoice.toLowerCase() === 'y') {
const boosterOption = await question('Enter channel ID, or type "create" to make a new channel: ');
if (boosterOption.toLowerCase() === 'create') {
const boosterName = await question('Enter name for booster channel (default: boosters): ') || 'boosters';
console.log(`Creating "${boosterName}" channel...`);
const boosterChannel = await guild.channels.create({
name: boosterName,
type: ChannelType.GuildText,
reason: 'Bot setup - booster channel'
});
config.setBoosterChannel(boosterChannel.id);
console.log('✅ Booster channel created!');
} else {
config.setBoosterChannel(boosterOption);
console.log('✅ Booster channel set!');
}
} else {
console.log('⏭️ Skipped booster channel setup');
}
// Configure jail role permissions for all channels
console.log('\n=================================');
console.log('Configuring Permissions');
console.log('=================================');
const channels = guild.channels.cache.filter(c =>
c.type === ChannelType.GuildText ||
c.type === ChannelType.GuildVoice
);
for (const [, channel] of channels) {
try {
await channel.permissionOverwrites.edit(jailRole.id, {
ViewChannel: false,
SendMessages: false,
Connect: false,
});
} catch (err) {
console.log(`⚠️ Could not update permissions for ${channel.name}`);
}
}
console.log('✅ Jail role permissions configured!');
console.log('\n=================================');
console.log('✅ Setup Complete!');
console.log('=================================');
console.log('\nConfiguration saved to config.json');
console.log('You can now run the bot with: node bot.js\n');
process.exit(0);
} catch (error) {
console.error('❌ Setup error:', error);
process.exit(1);
}
});
client.login(token);
}
setup();