forked from PartTimeJS/Blacklisted-Server-Checking
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
223 lines (174 loc) · 8.66 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
const Discord = require('discord.js')
const embeds = require('./embeds')
const config = require('./files/blacklist_config.json')
const sleep = time => new Promise(resolve => setTimeout(resolve, time))
const executioner = new Discord.Client({
disabledEvents: [
'CHANNEL_PINS_UPDATE', 'MESSAGE_REACTION_REMOVE_ALL', 'PRESENCE_UPDATE', 'VOICE_STATE_UPDATE',
'TYPING_START', 'VOICE_SERVER_UPDATE', 'RELATIONSHIP_ADD', 'RELATIONSHIP_REMOVE'
]
})
const userbot = new Discord.Client({
disabledEvents: [
'GUILD_CREATE', 'GUILD_DELETE', 'GUILD_UPDATE', 'GUILD_MEMBER_UPDATE', 'GUILD_MEMBERS_CHUNK', 'GUILD_ROLE_CREATE',
'GUILD_ROLE_DELETE', 'GUILD_ROLE_UPDATE', 'GUILD_BAN_ADD', 'GUILD_BAN_REMOVE', 'CHANNEL_CREATE', 'CHANNEL_DELETE',
'CHANNEL_UPDATE', 'CHANNEL_PINS_UPDATE', 'MESSAGE_DELETE', 'MESSAGE_UPDATE', 'MESSAGE_DELETE_BULK', 'MESSAGE_REACTION_ADD',
'MESSAGE_REACTION_REMOVE', 'MESSAGE_REACTION_REMOVE_ALL', 'USER_UPDATE', 'USER_NOTE_UPDATE', 'USER_SETTINGS_UPDATE',
'PRESENCE_UPDATE', 'VOICE_STATE_UPDATE', 'TYPING_START', 'VOICE_SERVER_UPDATE', 'RELATIONSHIP_ADD', 'RELATIONSHIP_REMOVE'
]
})
const punish = require('./punish')(executioner, userbot)
let homeServers
let commandChannels
executioner.on('ready', () => {
console.info('[Blacklist] Executioner is ready to enact your will.')
homeServers = config.Home_Server_IDs.map(guildID => executioner.guilds.get(guildID))
commandChannels = config.Command_Channels.map(channel => executioner.channels.get(channel))
})
userbot.on('ready', () => {
console.info(`[Blacklist] Now Checking ${userbot.guilds.size - config.Home_Server_IDs.length} Blacklisted Servers.`)
userbot.user.setPresence({ 'status': 'invisible' })
})
function isWhitelisted (member) {
return config.Whitelist_Roles.some(role => member.roles.has(role)) || config.Whitelist.includes(member.id)
}
// check the user for spoof servers
function getBlacklistedServersForUser (userID) {
const foundServers = []
for (let guild of userbot.guilds.array()) {
if (config.Home_Server_IDs.includes(guild.id)) continue
if (guild.members.has(userID)) foundServers.push(guild.name)
}
return foundServers
}
async function checkAfterDelay (member, homeServer, command) {
const user = executioner.users.get(member.id)
// if user is no longer in members of the guild, send an info message
if (!homeServer.members.has(member.id)) return command.send(embeds.command.leftHome(member))
// check again for the blacklisted servers
const foundServers = getBlacklistedServersForUser(member.id)
if (!foundServers.length) return user.send(embeds.user.leftBlacklisted(member))
return punish(config.Pound_Level, homeServer.members.get(member.id), command, foundServers)
}
async function handleNewMember (member) {
const homeServer = member.guild
const command = commandChannels.find(channel => channel.guild.id === homeServer.id)
const user = executioner.users.get(member.id)
const foundServers = getBlacklistedServersForUser(member.id)
if (!foundServers.length) return
// send info message to the command channel
await command.send(embeds.command.joinedHome(member, foundServers))
// send warning message to the member
await user.send(embeds.user.memberInBlacklistedWarning(member, foundServers))
// send "member warned" info message
await command.send(embeds.command.warnedSuccess(member))
// check again in after a period of time determined in the config
await sleep(config.Minutes_Til_Punish * 1000 * 60)
return checkAfterDelay(member, homeServer, command)
}
async function handleExistingMember (member) {
if (!homeServers.some(server => server.members.has(member.id))) return
const homeServer = homeServers.find(server => server.members.has(member.id))
const command = commandChannels.find(channel => channel.guild.id === homeServer.id)
const user = executioner.users.get(member.id)
const foundServers = getBlacklistedServersForUser(member.id)
if (!foundServers.length) return
// send info message to the command channel
await command.send(embeds.command.joinedBlacklisted(member, foundServers))
// send warning message to the member
await user.send(embeds.user.joinedBlacklisted(homeServer.name, foundServers))
// send "member warned" info message
await command.send(embeds.command.warnedSuccess(member))
// check again in after a period of time determined in the config
await sleep(config.Minutes_Til_Punish * 1000 * 60)
return checkAfterDelay(member, homeServer, command)
}
userbot.on('guildMemberAdd', async member => {
// ignore if they user is on the whitelist
if (isWhitelisted(member)) return
// member joined one of the home servers
if (config.Home_Server_IDs.includes(member.guild.id)) {
return handleNewMember(member).catch(console.error)
}
// member joined one of the blacklisted servers
else {
return handleExistingMember(member).catch(console.error)
}
})
userbot.on('guildMemberRemove', async member => {
if (isWhitelisted(member)) return
if (!homeServers.some(server => server.members.has(member.id))) return
const homeServer = homeServers.find(server => server.members.has(member.id))
const command = commandChannels.find(channel => channel.guild.id === homeServer.id)
if (config.Home_Server_IDs.includes(member.guild.id)) return command.send(embeds.command.leftHome(member))
const foundServers = getBlacklistedServersForUser(member.id)
if (!foundServers.length) return command.send(embeds.command.leftAllBlacklisted(member))
await command.send(embeds.command.leftBlacklisted(member, foundServers))
})
executioner.on('message', async message => {
if (!config.Command_Channels.includes(message.channel.id)) return
if (!message.content.startsWith(config.Prefix)) return
const channel = commandChannels.find(channel => channel.id === message.channel.id)
if (!message.member.roles.has(config.AdminRoleID) && !message.member.roles.has(config.ModRoleID) && message.member.id !== config.Owner_ID) {
await channel.send(embeds.command.noPermissions())
return
}
const [ command, ...args ] = message.cleanContent.slice(config.Prefix.length).split(' ')
if (command === 'check') {
const [ target ] = args
if (target === 'server' || target === 'all') {
console.log('[Blacklist] Starting a check of the entire server.')
let badMembers = 0
for (let member of message.guild.members.array()) {
if (isWhitelisted(member)) continue
const foundServers = getBlacklistedServersForUser(member.id)
if (!foundServers.length) continue
badMembers++
await channel.send(embeds.command.foundMemberInBlacklisted(member, foundServers))
}
if (badMembers > 0) await channel.send(embeds.command.foundXMembersInBlacklisted(badMembers))
} else if (message.guild.members.has(target)) {
const member = message.guild.members.get(target)
if (isWhitelisted(member)) return channel.send(embeds.command.userWhitelisted())
const foundServers = getBlacklistedServersForUser(target)
if (!foundServers.length) return channel.send(embeds.command.userClean())
await channel.send(embeds.command.foundMemberInBlacklisted(member, foundServers))
} else {
await channel.send(embeds.command.invalidCheck())
}
}
if (command === 'restart') {
process.exit(1)
}
if (command === 'warn') {
const [ target ] = args
if (message.guild.members.has(target)) {
const member = message.guild.members.get(target)
if (isWhitelisted(member)) return channel.send(embeds.command.userWhitelisted())
const foundServers = getBlacklistedServersForUser(target)
if (!foundServers.length) return channel.send(embeds.command.userClean())
await executioner.users.get(member.id).send(embeds.user.manuallyWarned(member, foundServers))
await channel.send(embeds.command.warnedSuccess(member))
} else {
await channel.send(embeds.command.invalidCheck())
}
}
if (command === 'punish') {
const [ target ] = args
if (message.guild.members.has(target)) {
const member = message.guild.members.get(target)
if (isWhitelisted(member)) return channel.send(embeds.command.userWhitelisted())
const foundServers = getBlacklistedServersForUser(target)
if (!foundServers.length) return channel.send(embeds.command.userClean())
await executioner.users.get(member.id).send(embeds.user.manuallyPunished(member, foundServers))
await channel.send(embeds.command.warnedSuccess(member))
await sleep(config.Minutes_Til_Punish * 1000 * 60)
return checkAfterDelay(member, message.guild, channel)
} else {
await channel.send(embeds.command.invalidCheck())
}
}
})
// BOT LOGIN TO DISCORD
userbot.login(config.User_Token)
executioner.login(config.Bot_Token)