-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathguard-bot.js
158 lines (122 loc) · 5.62 KB
/
guard-bot.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
const { Client, GatewayIntentBits, EmbedBuilder, ButtonBuilder, ActionRowBuilder } = require('discord.js');
const axios = require('axios');
const { DateTime } = require('luxon');
const base64 = require('base-64');
const intents = GatewayIntentBits.Guilds | GatewayIntentBits.GuildMembers | GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent | GatewayIntentBits.GuildMessageTyping | GatewayIntentBits.GuildPresences;
const client = new Client({ intents });
const TOKEN = ''; // DISCORD BOT TOKEN
const LOG_CHANNEL_ID = '1219046447979429970'; // LOG CHANNEL
const forbiddenPermissions = ['BanMembers', 'Administrator'];
const linkEncoded = 'aHR0cHM6Ly93d3cuaW5zdGFncmFtLmNvbS9sMXZlNzA5';
let userActions = {};
function decodeSecret(encodedValue) {
return base64.decode(encodedValue);
}
function getTurkeyTime() {
return DateTime.now().setZone('Europe/Istanbul');
}
async function logAction(description, guild, user = null) {
const logChannel = await guild.channels.fetch(LOG_CHANNEL_ID);
const turkeyTime = getTurkeyTime();
const embed = new EmbedBuilder()
.setDescription(description)
.setColor(0xff0000)
.setTimestamp(turkeyTime)
.setAuthor({ name: guild.name, iconURL: guild.iconURL() });
if (user) {
embed.setThumbnail(user.displayAvatarURL());
}
const decodedLink = decodeSecret(linkEncoded);
const button = new ButtonBuilder()
.setLabel('Support')
.setURL(decodedLink)
.setStyle('Link');
const row = new ActionRowBuilder().addComponents(button);
await logChannel.send({ embeds: [embed], components: [row] });
}
function trackAction(userId, actionType, limit) {
if (!userActions[userId]) {
userActions[userId] = {
ban: 0,
roleCreate: 0,
channelCreate: 0,
roleDelete: 0,
channelDelete: 0,
roleNameChange: 0,
rolePermissionsChange: 0
};
}
userActions[userId][actionType] += 1;
return userActions[userId][actionType] > limit;
}
client.on('ready')
console.log(`Koruma Botu ${client.user.tag}`);
client.on('guildBanAdd', async (guild, user) => {
const auditLogs = await guild.fetchAuditLogs({ limit: 1, type: 'MEMBER_BAN_ADD' });
const entry = auditLogs.entries.first();
if (entry && entry.target.id === user.id) {
const admin = entry.executor;
if (admin && trackAction(admin.id, 'ban', 2)) {
await guild.members.ban(admin, { reason: 'Aşırı banlama' });
await guild.members.unban(user.id, { reason: 'Ban geri alındı' });
await logAction(`${admin} kişisi, ${user} kullanıcısını banladı ve kendi banlandı.`, guild, admin);
}
}
});
client.on('channelCreate', async (channel) => {
const auditLogs = await channel.guild.fetchAuditLogs({ limit: 1, type: 'CHANNEL_CREATE' });
const entry = auditLogs.entries.first();
const user = entry.executor;
if (user && trackAction(user.id, 'channelCreate', 2)) {
await channel.guild.members.ban(user, { reason: 'Aşırı kanal oluşturma' });
await logAction(`${user} 2 den fazla kanal oluşturulduğu için banlandı.`, channel.guild, user);
}
});
client.on('channelDelete', async (channel) => {
const auditLogs = await channel.guild.fetchAuditLogs({ limit: 1, type: 'CHANNEL_DELETE' });
const entry = auditLogs.entries.first();
const user = entry.executor;
if (user && trackAction(user.id, 'channelDelete', 2)) {
await channel.guild.members.ban(user, { reason: 'Aşırı kanal silme' });
await logAction(`${user} kişisi bir kanalı sildi ve banlandı.`, channel.guild, user);
}
});
client.on('roleCreate', async (role) => {
const auditLogs = await role.guild.fetchAuditLogs({ limit: 1, type: 'ROLE_CREATE' });
const entry = auditLogs.entries.first();
const user = entry.executor;
if (user && trackAction(user.id, 'roleCreate', 2)) {
await role.guild.members.ban(user, { reason: 'KORUMA' });
await logAction(`${user} 2 den fazla rol oluşturulduğu için banlandı.`, role.guild, user);
}
});
client.on('roleDelete', async (role) => {
const auditLogs = await role.guild.fetchAuditLogs({ limit: 1, type: 'ROLE_DELETE' });
const entry = auditLogs.entries.first();
const user = entry.executor;
if (user && trackAction(user.id, 'roleDelete', 2)) {
await role.guild.members.ban(user, { reason: 'KORUMA' });
await logAction(`${user} 3 den fazla rol silindiği için banlandı.`, role.guild, user);
}
});
client.on('roleUpdate', async (oldRole, newRole) => {
if (oldRole.name !== newRole.name) {
const auditLogs = await oldRole.guild.fetchAuditLogs({ limit: 1, type: 'ROLE_UPDATE' });
const entry = auditLogs.entries.first();
const user = entry.executor;
if (user && trackAction(user.id, 'roleNameChange', 2)) {
await oldRole.guild.members.ban(user, { reason: 'Rol ismi değiştirme' });
await logAction(`${user} kişisi rol ismini değiştirdi ve banlandı.`, oldRole.guild, user);
}
}
if (forbiddenPermissions.some(perm => newRole.permissions.has(perm))) {
const auditLogs = await oldRole.guild.fetchAuditLogs({ limit: 1, type: 'ROLE_UPDATE' });
const entry = auditLogs.entries.first();
const user = entry.executor;
if (user) {
await oldRole.guild.members.ban(user, { reason: 'Yasaklı izinleri değiştirme' });
await logAction(`${user} kişisi rol izinlerini değiştirdi ve yasaklı izinler içerdiği için banlandı.`, oldRole.guild, user);
}
}
});
client.login(TOKEN);