-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
361 lines (281 loc) · 14.2 KB
/
Copy pathmain.py
File metadata and controls
361 lines (281 loc) · 14.2 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
#cython: language_level=3
import data
import config
import discord
import userCommands
import adminCommands
from discord import Intents
from discordHelper import newEmbed, errorMessage, RED, BLUE, GREEN, YELLOW
PREFIX = '+'
class DiscordBot(discord.Client):
def __init__(self, *args, **kwargs):
# Define the intents your bot needs (adjust as necessary)
intents = Intents.all()
intents.message_content = True # Allows access to message content for commands
intents.reactions = True # Allows handling reaction events
super().__init__(*args, **kwargs, intents=intents)
# Load data and initialize attributes
allData = data.loadJSON(data.DATABASE_FILENAME)
self.masterIDs = allData['Masters']
self.staffIDs = allData['Staff']
# Initialize logChannel
self.logChannel = self.get_channel(config.LOG_CHANNEL_ID) # Make sure LOG_CHANNEL_ID is defined in your config
async def on_ready(self):
'''
Called when the discord bot logs in
'''
print(f'{self.user.name} Logged In!')
print('--------------------\n')
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User):
# Unsubscribe from vouch notifications
description = reaction.message.embeds[0].description
if 'Received a' in description and reaction.emoji == '❌':
noNotifs = data.loadJSON(data.DATABASE_FILENAME)[
'NoNotificationIDs']
if user.id not in noNotifs:
embed = newEmbed(
description='Unsubscribed from notifications!')
embed.set_footer(
text='To resubscribe, react with ✅')
noNotifs.append(user.id)
data.updateJson(data.DATABASE_FILENAME, {
'NoNotificationIDs': noNotifs})
await user.send(embed=embed)
# Resubscribe to vouch notifications
elif 'Unsubscribed' in description and reaction.emoji == '✅':
noNotifs = data.loadJSON(data.DATABASE_FILENAME)[
'NoNotificationIDs']
if user.id in noNotifs:
embed = newEmbed(description='Resubscribed to notifications!')
embed.set_footer(text='To unsubscribe, react with ❌')
noNotifs.remove(user.id)
data.updateJson(data.DATABASE_FILENAME, {
'NoNotificationIDs': noNotifs})
await user.send(embed=embed)
async def on_message(self, message: discord.Message):
'''
Handles all the discord commands
'''
# Make sure we don't respond to ourselves
if message.author == self.user:
return
isMaster = message.author.id in self.masterIDs
isStaff = message.author.id in self.staffIDs or isMaster
loweredMsg = message.content.lower()
words = message.content.split()
# =====================================================
if loweredMsg.startswith('+vouch') or loweredMsg.startswith('-vouch'):
if len(message.mentions) == 0 or len(words) < 3:
await errorMessage('Please follow this format: [+ or -]vouch [@user] [message]',
message.channel)
return
if message.author.id == message.mentions[0].id:
await errorMessage('You cannot vouch for yourself.', message.channel)
return
vouchMessage = ' '.join(words[2:])
isPositive = loweredMsg[0] == '+'
pendingChannel = self.get_channel(config.PENDING_VOUCHES_CHANNELID)
await userCommands.vouch(message.author,
message.mentions[0],
vouchMessage,
isPositive,
message.channel,
pendingChannel)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}dwc') and isMaster:
if 'dwc1' in loweredMsg:
level = 1
elif 'dwc2' in loweredMsg:
level = 2
elif 'dwc3' in loweredMsg:
level = 3
else:
level = 0
if len(message.mentions) == 0 or (level != 0 and len(words) < 3):
await errorMessage(f'Please follow this format: {PREFIX}dwc [@user] [reason]',
message.channel)
return
reason = ' '.join(words[2:]) if level != 0 else ''
await adminCommands.dwc(message.mentions[0], level, reason, message.channel)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}scammer') and isMaster:
if len(message.mentions) == 0:
await errorMessage(f'Please follow this format: {PREFIX}scammer [@user]',
message.channel)
return
await adminCommands.scammer(message.mentions[0], message.channel)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}pending') and isStaff:
await adminCommands.pending(message.channel, self.get_user)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}leaderboard'):
await userCommands.leaderboard(message.channel, self.get_user, self.user.avatar_url)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}reply') and isStaff:
if len(words) < 3 or not words[1].isdigit():
await errorMessage(f'Please follow this format: {PREFIX}reply [vouch id] [message]',
message.channel)
return
targetUser = None
try:
vouchID = int(words[1])
pending = data.loadJSON(data.DATABASE_FILENAME)['PendingVouches']
for i in pending:
if i['ID'] == vouchID:
targetUser = self.get_user(i['Giver'])
break
else:
raise Exception('User not found')
except Exception as e:
print(e)
await errorMessage(f'Could not find user with ID {vouchID}',
message.channel)
return
replyMsg = ' '.join(words[2:])
await adminCommands.reply(targetUser, replyMsg, message.channel)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}remove') and isMaster:
if len(message.mentions) == 0 or len(words) < 2:
await errorMessage(f'Please follow this format:\n{PREFIX}remove [@user]\n**or**\n{PREFIX}remove [@user] [vouch ID]',
message.channel)
return
vouchNum = -1
if len(words) >= 3 and words[2].isdigit():
vouchNum = int(words[2])
if vouchNum < 0:
await errorMessage('Vouch ID cannot be negative!', message.channel)
return
await adminCommands.remove(message.mentions[0], message.channel, vouchNum)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}verify') and isMaster:
if len(message.mentions) == 0:
await errorMessage(f'Please follow this format: {PREFIX}verify [@user]',
message.channel)
return
await adminCommands.verify(message.mentions[0], message.channel)
# =====================================================
elif (loweredMsg.startswith('+add') or loweredMsg.startswith('-add')) and isMaster:
if len(message.mentions) == 0 or len(words) < 3:
await errorMessage(f'Please follow this format: [+ or -]add [@user] [giverID (optional)] [message]',
message.channel)
return
# Check if they specify the giver ID
hasGiverID = False
giverID = 0
if words[2].isdigit():
hasGiverID = True
giverID = int(words[2])
vouchMessage = ' '.join(
words[3:]) if hasGiverID else ' '.join(words[2:])
isPositive = loweredMsg[0] == '+'
logChannel = self.get_channel(config.LOG_CHANNEL_ID)
await adminCommands.add(message.author,
message.mentions[0],
vouchMessage,
isPositive,
message.channel,
logChannel,
giverID)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}token'):
await userCommands.token(message.author, message.channel)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}profile'):
if len(message.mentions) == 0:
user = message.author
else:
user = message.mentions[0]
await userCommands.profile(
targetUser=user,
bcGuild=self.get_guild(config.PROFILE_GUILD_ID),
channel=message.channel
)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}link'):
if len(words) < 2:
await errorMessage(
f'Please follow this format: {PREFIX}link [https://nulled.to/ link]',
message.channel)
return
if 'https://nulled.to/' not in words[1]:
await errorMessage(
'Please provide a proper nulled.to link!',
message.channel)
return
await userCommands.link(message.author, words[1], message.channel)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}redeem'):
if len(words) <= 1:
await errorMessage(f'Please follow this format: {PREFIX}redeem [token]',
message.channel)
return
await userCommands.redeem(message.author, words[1],
message.channel, self.logChannel)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}admin') and isMaster:
if len(message.mentions) == 0:
await errorMessage(f'Please follow this format: {PREFIX}admin [@user]',
message.channel)
return
await adminCommands.admin(message.mentions[0], message.channel)
if message.mentions[0].id in self.masterIDs:
self.masterIDs.remove(message.mentions[0].id)
else:
self.masterIDs.append(message.mentions[0].id)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}staff') and isMaster:
if len(message.mentions) == 0:
await errorMessage(f'Please follow this format: {PREFIX}staff [@user]',
message.channel)
return
await adminCommands.staff(message.mentions[0], message.channel)
if message.mentions[0].id in self.staffIDs:
self.staffIDs.remove(message.mentions[0].id)
else:
self.staffIDs.append(message.mentions[0].id)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}blacklist') and isMaster:
if len(message.mentions) == 0:
if len(words) >= 2 and not words[1].isdigit():
await errorMessage(f'Please follow this format: {PREFIX}blacklist [@user]',
message.channel)
return
if len(message.mentions) != 0:
id = message.mentions[0].id
else:
id = int(words[1])
await adminCommands.blacklist(id, message.channel)
# =====================================================
elif (loweredMsg.startswith(f'{PREFIX}approve') or
loweredMsg.startswith(f'{PREFIX}accept')) and isStaff:
if len(words) < 2 or not words[1].isdigit():
await errorMessage(f'Please follow this format: {PREFIX}approve [vouch ID]',
message.channel)
return
ids = [int(i) for i in words[1:] if i.isdigit()]
logChannel = self.get_channel(config.LOG_CHANNEL_ID)
for i in ids:
await adminCommands.approve(i, message.channel,
logChannel, self.get_user)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}deny') and isStaff:
if len(words) < 2 or not words[1].isdigit():
await errorMessage(f'Please follow this format: {PREFIX}deny [vouch ID]',
message.channel)
return
ids = [int(i) for i in words[1:] if i.isdigit()]
for i in ids:
await adminCommands.deny(i, message.channel)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}help'):
await userCommands.help(PREFIX,
message.channel,
isMaster)
# =====================================================
elif loweredMsg.startswith(f'{PREFIX}about'):
await userCommands.about(message.channel, self.user.avatar_url)
# =====================================================
def main():
DiscordBot().run(config.DISCORD_TOKEN)
if __name__ == '__main__':
main()