-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
331 lines (237 loc) · 10.2 KB
/
index.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
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
const { AttachmentBuilder , Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed, Collection, Events, AuditLogEvent, MessageCollector, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType } = require(`discord.js`);
const fs = require('fs');
const Discord = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
],
allowedMentions: {
parse: [`users`, `roles`],
repliedUser: true,
}});
client.commands = new Collection();
require('dotenv').config();
(async () => {
for (file of functions) {
require(`./functions/${file}`)(client);
}
client.handleEvents(eventFiles, "./src/events");
client.handleCommands(commandFolders, "./src/commands");
client.login(process.env.token)
});
//level system
const levelSchema = require('./Schemas.js/level');
client.on(Events.MessageCreate, async (message) => {
const { guild, author} = message;
if (!guild || author.bot) return;
levelSchema.findOne({ Guild: guild.id, User: author.id}, async (err, data) => {
if (err) throw err;
if (!data) {
levelSchema.create({
Guild: guild.id,
User: author.id,
XP: 0,
Level: 0
})
}
})
const channel = message.channel;
const give = 1;
const data = await levelSchema.findOne({ Guild: guild.id, User: author.id});
if (!data) return;
const requiredXP = data.Level * data.Level * 20+20;
if (data.XP + give >= requiredXP) {
data.XP +- give;
data.Level += 1;
await data.save();
if (!channel) return;
const embed = new EmbedBuilder()
.setColor("Purple")
.setDescription(`${author} you reached **Level ${data.Level}**!`)
channel.send({ embeds: [embed] });
} else {
data.XP += give;
data.save()
}
})
//report system
const reportSchema = require('./Schemas.js/rep');
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isModalSubmit()) return;
if (interaction.customId === 'modal') {
const contact = interaction.fields.getTextInputValue('contact');
const issue = interaction.fields.getTextInputValue('issue');
const description = interaction.fields.getTextInputValue('description');
const member = interaction.user.id;
const tag = interaction.user.tag;
const server = interaction.guild.name;
const embed = new EmbedBuilder()
.setColor("Blue")
.setTitle("New Report")
.setDescription(`Reporting Member: ${tag} (${member})`)
.addFields({ name: "Form of Contact", value: `${contact}`, inline: false})
.addFields({ name: "Issue Reported", value: `${issue}`, inline: false})
.addFields({ name: "Description of the issue", value: `${description}`, inline: false})
reportSchema.findOne({ Guild: interaction.guild.id}, async (err, data) => {
if (!data) return;
if (data) {
const channelID = data.Channel;
const channel = interaction.guild.channels.cache.get(channelID);
channel.send({ embeds: [embed] });
await interaction.reply({ content: "Your report as been submitted", ephemeral: true})
}
})
}
})
//sticky message
const stickySchema = require('./Schemas.js/stickySchema');
client.on(Events.MessageCreate, async message => {
if (message.author.bot) return;
stickySchema.findOne({ ChannelID: message.channel.id}, async (err, data) => {
if (err) throw err;
if (!data) {
return;
}
let channel = data.ChannelID;
let cachedChannel = client.channels.cache.get(channel);
const embed = new EmbedBuilder()
.setColor("Blue")
.setDescription(data.Message)
.setFooter({ text: "This is a sticky message"})
if (message.channel.id == channel) {
data.CurrentCount += 1;
data.save();
if (data.CurrentCount > data.MaxCount) {
try {
await client.channels.cache.get(channel).messages.fetch(data.LastMessageID).then(async(m) => {
await m.delete();
})
let newMessage = await cachedChannel.send({ embeds: [embed] });
data.LastMessageID = newMessage.id;
data.CurrentCount = 0;
data.save();
} catch {
return;
}
}
}
})
})
//invite logger
const inviteSchema = require('./Schemas.js/inviteSchema');
const invites = new Collection();
const wait = require("timers/promises").setTimeout;
client.on('ready', async () => {
await wait(2000);
client.guilds.cache.forEach(async (guild) => {
const clientMember = guild.members.cache.get(client.user.id);
if (!clientMember.permissions.has(PermissionsBitField.Flags.ManageGuild)) return;
const firstInvites = await guild.invites.fetch().catch(err => {console.log(err)});
invites.set(guild.id, new Collection(firstInvites.map((invite) => [invite.code, invite.uses])));
})
})
client.on(Events.GuildMemberAdd, async member => {
const Data = await inviteSchema.findOne({ Guild: member.guild.id});
if (!Data) return;
const channelID = Data.Channel;
const channel = await member.guild.channels.cache.get(channelID);
const newInvites = await member.guild.invites.fetch();
const oldInvites = invites.get(member.guild.id);
const invite = newInvites.find(i => i.uses > oldInvites.get(i.code));
if (!invite) return await channel.send(`${member.user.tag} joined the server using an unknown invite. This could possibly a vanity invite link if your server has one.`)
const inviter = await client.users.fetch(invite.inviter.id);
const { guild } = interaction;
const { name } = guild;
const icon = guild.iconURL();
const embed1 = new EmbedBuilder()
.setTitle("New Member")
.setDescription(`${member.user.tag} joined the server!`)
.addFields(
{name: "User:", value: `<@${member.id}>`, inline: true},
{name: "Date:", value: `${Date.now}`, inline: true},
{name: "Invite:", value: `${invite.code}`, inline: true},
{name: "Invite uses:", value: `${invite.uses}`, inline: true},
{name: "Inviter:", value: `<@${inviter.id}>`, inline: true},
{name: "Member No.:", value: `${guild.memberCount}`}
)
.setColor("Green")
.setTimestamp()
.setAuthor({ name: name, iconURL: icon })
const embed2 = new EmbedBuilder()
.setTitle("New Member!")
.setDescription(`${member.user.tag} joined the server but I can't find what invite they used to do it`)
.setColor("Green")
.setTimestamp()
inviter
? channel.send({
embeds: [embed1]
}).catch(err => {
return;
})
: channel.send({
embeds: [embed2]
}).catch(err => {
return;
});
})
const ghostSchema = require("./Schemas.js/ghostpingSchema");
const numSchema = require("./Schemas.js/ghostnum");
client.on(Events.MessageDelete, async message => {
const Data = await ghostSchema.findOne({ Guild: message.guild.id});
if (!Data) return;
if (!message.author) return;
if (message.author.bot) return;
if (!message.author.id === client.user.id) return;
if (message.author === message.mentions.users.first()) return;
if (message.mentions.users.first() || message.type === MessageType.reply) {
let number;
let time = 15;
const data = await numSchema.findOne({ Guild: message.guild.id, User: message.author.id});
if (!data) {
await numSchema.create({
Guild: message.guild.id,
User: message.author.id,
Number: 1
})
number = 1;
} else {
data.Number += 1;
await data.save();
number = data.Number;
}
if (number == 2) time = 60;
if (number >= 3) time = 500;
const msg = await message.channel.send({ content: `${message.author}, you cannot ghost ping members within this server!`});
setTimeout(() => msg.delete(), 5000);
const member = message.member;
if (message.member.permissions.has(PermissionsBitField.Flags.Administrator)) {
return;
} else {
await member.timeout(timeout * 1000, "Ghost Pinging");
await member.send({ content: `You have been timed out in ${message.guild.name} for ${time} seconds due to ghost pinging members`}).catch(err => {
return;
})
}
}
})
//anti link system
const linkSchema = require('./Schemas.js/linkSchema');
client.on(Events.MessageCreate, async message => {
if (message.content.startsWith('http') || message.content.startsWith('discord.gg') || message.content.includes('https://') || message.content.includes('http://') || message.content.includes('discord.gg/')) {
const Data = await linkSchema.findOne({ Guild: message.guild.id});
if (!Data) return;
const memberPerms = Data.Perms;
const user = message.author;
const member = message.guild.members.cache.get(user.id);
if (member.permissions.has(memberPerms)) return;
else {
await message.channel.send({ content: `${message.author}, you can't send links here!`}).then(msg => {
setTimeout(() => msg.delete(), 3000)
})
;(await message).delete();
}
}
})