-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
391 lines (370 loc) · 12.1 KB
/
Copy pathbot.js
File metadata and controls
391 lines (370 loc) · 12.1 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
require("dotenv/config");
const { DateTime } = require("luxon");
const timezoneMap = {
// US
PST: "America/Los_Angeles",
PDT: "America/Los_Angeles",
MST: "America/Denver",
MDT: "America/Denver",
CST: "America/Chicago",
CDT: "America/Chicago",
EST: "America/New_York",
EDT: "America/New_York",
// UK/EU
GMT: "Etc/GMT",
BST: "Europe/London",
CET: "Europe/Paris",
CEST: "Europe/Paris",
// AU/NZ
AEST: "Australia/Sydney",
AEDT: "Australia/Sydney",
ACST: "Australia/Adelaide",
ACDT: "Australia/Adelaide",
AWST: "Australia/Perth",
NZST: "Pacific/Auckland",
NZDT: "Pacific/Auckland",
// Asia
IST: "Asia/Kolkata",
JST: "Asia/Tokyo",
// Global
UTC: "Etc/UTC",
};
const Discord = require("discord.js");
const client = new Discord.Client({
intents: [
"Guilds",
"GuildMessagePolls",
"GuildVoiceStates",
"GuildMembers",
"GuildMessages",
"MessageContent",
],
partials: [Discord.Partials.Message, Discord.Partials.Reaction],
});
const BLANK = "1250623077214191678";
const Member = "1250627277868240936";
const Booster = "1397533833783410779";
const CREATE_CHANNEL_ID = '1397809101345525760';
const CATEGORY_ID = '1250018152826408962';
//turning bot on
client.on("ready", async () => {
// console.log(Logged in as ${client.user.tag}!)
client.user.setPresence({
activities: [
{
type: Discord.ActivityType.Custom,
name: "custom", // name is exposed through the API but not shown in the client for ActivityType.Custom
state:"use me so Fox can go broke",
},
],
});
console.log("Bot turned on");
});
//minimising LFG clutter
client.on("messageCreate", async (message) => {
if (message.channel.name.includes("lfg")) {
if (message.mentions.roles.size > 0) {
if (
message.mentions.roles.each((role) => {
return role.mentionable;
})
) {
//parse integers
const regex = /\d{1,2}(?!<)(?!\d)(?!>)/;
// Test the message and extract the integer if present
const match = message.content.match(regex);
// If a match is found, return the integer, otherwise return null
try {
if (match) {
const lfg_count = parseInt(match[0], 10);
const thread = await message.startThread({
name:
message.author.displayName +
" needs " +
lfg_count +
" people for " +
message.mentions.roles.first().name,
autoArchiveDuration: 60,
reason: "Thread for LFGs",
});
thread.send("Auto archives after 60min of inactivity");
} else {
const thread = await message.startThread({
name:
message.author.displayName +
" needs people for " +
message.mentions.roles.first().name,
autoArchiveDuration: 60,
reason: "Thread for LFGs",
});
thread.send("Auto archives after 60min of inactivity");
}
} catch (e) {
console.log(" " + e + " ");
}
}
}
}
});
client.on("messagePollVoteAdd", async (pollVote, userID) => {
const poll = await pollVote.poll;
const total = await poll.answers.reduce(
(aggregate, answer) => aggregate + answer.voteCount,
0
);
const totalYes = await poll.answers.at(0).voteCount;
const totalNo = await poll.answers.at(1).voteCount;
const guild = await client.guilds.cache.get(process.env.GUILD_ID);
const voter = await guild.members.fetch(userID);
await guild.members.fetch();
const splitMessage = await poll.question.text.split(" ", 2);
const nominee = await (
await guild.members.search({
query: splitMessage[1],
limit: 1,
cache: true,
})
).at(0);
try {
if (poll.question.text.includes("BLANK")) {
const role = await guild.roles.fetch(BLANK);
const roleCompare = await voter.roles.highest.comparePositionTo(role);
if ((await roleCompare) >= 0) {
if (total / role.members.size >= 0.7) {
if (total / totalYes >= 0.6) {
await poll.message
.reply({
content: "Successful Promotion: " + nominee.displayName,
ephemeral: false,
})
.then(async () => {
await nominee.roles.add(role);
})
.then(async () => {
await poll.message.thread.setLocked(true);
await poll.message.thread.setArchived(true);
await poll.message.delete();
});
} else if (total / totalNo >= 0.6) {
await poll.message
.reply({
content: "Unsuccessful Promotion: " + nominee.displayName,
ephemeral: false,
})
.then(async () => {
await poll.message.thread.setLocked(true);
await poll.message.thread.setArchived(true);
await poll.message.delete();
});
}
}
}
} else if (poll.question.text.includes("Member")) {
const role = await guild.roles.fetch(Member);
const roleCompare = await voter.roles.highest.comparePositionTo(role);
if (roleCompare >= 1) {
await poll.message
.reply({
content: voter.nickname + " overwrote this poll's results",
ephemeral: false,
})
.then(async () => {
if (pollVote.text == "Yes") {
await nominee.roles.add(role);
}
})
.then(async () => {
await poll.message.thread.setLocked(true);
await poll.message.thread.setArchived(true);
await poll.message.delete();
});
} else if ((await roleCompare) >= 0) {
if (total / role.members.size >= 0.7) {
if (total / totalYes >= 0.6) {
await poll.message
.reply({
content: "Successful Promotion: " + nominee.displayName,
ephemeral: false,
})
.then(async () => {
await nominee.roles.add(role);
})
.then(async () => {
await poll.message.thread.setLocked(true);
await poll.message.thread.setArchived(true);
await poll.message.delete();
});
} else if (total / totalNo >= 0.6) {
await poll.message
.reply({
content: "Unsuccessful Promotion: " + nominee.displayName,
ephemeral: false,
})
.then(async () => {
await poll.message.thread.setLocked(true);
await poll.message.thread.setArchived(true);
await poll.message.delete();
});
}
}
}
}
} catch (e) {
console.log(e);
}
});
client.on("interactionCreate", async (interaction) => {
if (
(await interaction.isCommand()) &&
(await interaction.commandName) === "nominate"
) {
const roleCompare =
await interaction.member.roles.highest.comparePositionTo(
interaction.options.getString("role")
);
try {
const nominee = await interaction.options.getMember("member");
const role = await interaction.guild.roles.cache.get(
interaction.options.getString("role")
);
const nomineeName = await nominee.displayName;
const roleName = await role.name;
const poll = (Discord.PollData = {
question: {
text: "Should " + nomineeName + " be promoted to " + roleName + "?",
},
answers: [
{
text: "Yes",
emoji: "💪",
},
{
text: "No",
emoji: "📉",
},
],
duration: 100, // 100 hours
allowMultiselect: false,
layoutType: Discord.PollLayoutType.Default, // Single type (optional)
});
if (roleCompare >= 1 && role.id == Member) {
await interaction
.reply({
content: "You promoted: " + nomineeName + " to: " + roleName,
ephemeral: false,
})
.then(async () => {
nominee.roles.add(role);
});
} else if ((await roleCompare) >= 0) {
await interaction
.reply({
content:
"You nominated: " +
nomineeName +
" for promotion to: " +
roleName,
ephemeral: true,
})
.then(async () => {
await interaction.channel
.send({ content: "", poll: poll })
.then(async (message) => {
await message.startThread({
name: "Nominated: " + nomineeName + " for " + roleName,
autoArchiveDuration: 60,
reason: "Thread for voting on member promotion",
});
});
});
} else {
await interaction.reply({
content:
"You cannot nominate someone for a role higher than your own",
ephemeral: true,
});
}
} catch (error) {
// console.log(error)
console.log("double fire");
}
}
if (
(await interaction.isCommand()) &&
(await interaction.commandName) === "timestamp"
) {
const time = interaction.options.getString('time');
const date = interaction.options.getString('date');
const tzAbbr = interaction.options.getString('tz');
const tzFull = interaction.options.getString('timezone');
var zone;
if(tzAbbr){zone = timezoneMap[tzAbbr.trim()?.toUpperCase()]}
else if(tzFull){zone = tzFull.trim()}
if (!zone) {
await interaction.reply({
content: `❌ Please provide a valid \`tz\` (abbreviation) or \`timezone\` (e.g. America/New_York).`,
ephemeral: true,
});
return;
}
const [hour, minute] = time.split(":").map(Number);
const [year, month, day] = date.split("-").map(Number);
const dt = DateTime.fromObject(
{ year, month, day, hour, minute },
{ zone }
);
if (!dt.isValid) {
await interaction.reply({
content: `❌ Invalid date, time, or timezone. Make sure you're using 24-hour format, didn't forget any - or : and are using a supported timezone.`,
ephemeral: true,
});
return;
}
const unix = Math.floor(dt.toSeconds());
await interaction.reply({
content: `<t:${unix}:F>, (<t:${unix}:R>)`,
ephemeral: false,
});
}
});
// Voice channel creator
client.on('voiceStateUpdate', async (oldState, newState) => {
// Only act when a user joins the "Create Channel"
if (newState.channelId === CREATE_CHANNEL_ID && oldState.channelId !== CREATE_CHANNEL_ID) {
const guild = newState.guild;
const user = newState.member;
// Create a new temporary voice channel
const tempChannel = await guild.channels.create({
name: `${user.user.username}'s Channel`,
type: Discord.ChannelType.GuildVoice,
parent: CATEGORY_ID || null,
permissionOverwrites: [
{
id: guild.roles.everyone,
allow: [Discord.PermissionsBitField.Flags.Connect, Discord.PermissionsBitField.Flags.ViewChannel],
},
{
id: user.id,
allow: [Discord.PermissionsBitField.Flags.MuteMembers, Discord.PermissionsBitField.Flags.MoveMembers],
},
],
});
// Move the user to the new voice channel
await user.voice.setChannel(tempChannel);
// Optional: Monitor when the channel becomes empty
const checkEmpty = setInterval(async () => {
const freshChannel = await guild.channels.fetch(tempChannel.id);
if (freshChannel && freshChannel.members.size === 0) {
await tempChannel.delete().catch(console.error);
clearInterval(checkEmpty);
}
}, 1000); // Check every 1 seconds
}
});
//Server booster benefits
client.login(process.env.BOT_TOKEN);
// Testing member caching
// const guild = await client.guilds.fetch(process.env.GUILD_ID)
// await guild.members.fetch()
// const role = await guild.roles.fetch(BLANK)
// console.log(role.members.size)