forked from FastestMolasses/Vouch-Pro-Discord-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminCommands.py
305 lines (252 loc) · 9.72 KB
/
adminCommands.py
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
#cython: language_level=3
import data
import discord
from discordHelper import User, Vouch, newEmbed, errorMessage, RED, BLUE, GREEN, YELLOW
async def admin(targetUser: discord.User, channel: discord.TextChannel):
'''
Toggles Master privileges to mentioned user
'''
masters = data.loadJSON(data.DATABASE_FILENAME)['Masters']
if targetUser.id in masters:
masters.remove(targetUser.id)
embed = newEmbed(description='Removed admin!', color=GREEN)
else:
masters.append(targetUser.id)
embed = newEmbed(description='Added admin!', color=GREEN)
data.updateJson(data.DATABASE_FILENAME, {'Masters': masters})
await channel.send(embed=embed)
async def add(user: discord.User,
targetUser: discord.User,
message: str,
isPositive: bool,
curChannel: discord.TextChannel,
logChannel: discord.TextChannel,
giverID: int = 0):
'''
Leaves a vouch for a user
'''
u = User(user.id)
# Create a new vouch
d = data.loadJSON(data.DATABASE_FILENAME)
vouchNum: int = d['VouchCount'] + 1
vouch = {
'ID': vouchNum,
'Giver': user.id if giverID == 0 else giverID,
'Receiver': targetUser.id,
'IsPositive': isPositive,
'Message': message,
}
vouch = Vouch(vouch)
u.addVouch(vouch)
# Message the user when their vouch is approved
# and only if they haven't opted out of notifications
if not u.ignoreNotifications:
vouchType = 'positive' if isPositive else 'negative'
msg = f'Received a {vouchType} vouch!'
embed = newEmbed(description=msg, color=(GREEN if isPositive else RED))
embed.set_footer(
text='React with ❌ to stop receiving vouch notifications')
await targetUser.send(embed=embed)
# Send confirmation message
embed = newEmbed(
description=f'Added vouch to {targetUser.mention}', color=GREEN)
await curChannel.send(embed=embed)
# Send embed to log channel
embed = newEmbed(description='', title=f'Vouch ID: {vouchNum}')
embed.add_field(name='Type', value=(
'Pos' if isPositive else 'Neg'), inline=False)
embed.add_field(name='Receiver', value=targetUser.name, inline=False)
embed.add_field(name='Giver', value=user.name, inline=False)
embed.add_field(name='Comment', value=message, inline=False)
embed.set_footer(
text='Added Vouch')
await logChannel.send(embed=embed)
async def staff(targetUser: discord.User, channel: discord.TextChannel):
'''
Toggles staff privileges to mentioned user
'''
masters = data.loadJSON(data.DATABASE_FILENAME)['Staff']
if targetUser.id in masters:
masters.remove(targetUser.id)
embed = newEmbed(description='Removed staff!', color=GREEN)
else:
masters.append(targetUser.id)
embed = newEmbed(description='Added staff!', color=GREEN)
data.updateJson(data.DATABASE_FILENAME, {'Staff': masters})
await channel.send(embed=embed)
async def dwc(targetUser: discord.User,
level: int,
reason: str,
channel: discord.TextChannel):
'''
Toggles Deal With Caution role to mentioned user
'''
u = User(targetUser.id)
u.setDWC(level, reason)
if level != 0:
embed = newEmbed(
description=f'Added DWC{level} to {targetUser.mention}!',
color=GREEN)
else:
embed = newEmbed(
description=f'Removed DWC for {targetUser.mention}!',
color=GREEN)
await channel.send(embed=embed)
async def scammer(targetUser: discord.User, channel: discord.TextChannel):
'''
Toggles Scammer role to mentioned user
'''
u = User(targetUser.id)
u.setScammer(not u.isScammer)
if u.isScammer:
embed = newEmbed(
description=f'Added Scammer to {targetUser.mention}!',
color=GREEN)
else:
embed = newEmbed(
description=f'Removed Scammer for {targetUser.mention}!',
color=GREEN)
await channel.send(embed=embed)
async def blacklist(targetUserID: int, channel: discord.TextChannel):
'''
Toggles the blacklist for the mentioned
user from vouching other people
'''
blacklist: list = data.loadJSON(data.DATABASE_FILENAME)['Blacklist']
if targetUserID in blacklist:
blacklist.remove(targetUserID)
embed = newEmbed(
description='Removed user from blacklist!', color=GREEN)
else:
blacklist.append(targetUserID)
embed = newEmbed(
description=f'Added to blacklist!',
color=GREEN)
data.updateJson(data.DATABASE_FILENAME, {'Blacklist': blacklist})
await channel.send(embed=embed)
async def remove(targetUser: discord.User,
channel: discord.TextChannel,
vouchID: int = -1):
'''
Lists vouches for a person and
deletes a specific vouch
'''
u = User(targetUser.id)
# If a vouch ID wasn't passed in, then list them out
if vouchID == -1:
vouches = u.formatVouches()
if len(vouches) == 0:
vouches = 'No vouches to show!'
embed = newEmbed(description=vouches, color=BLUE)
await channel.send(embed=embed)
return
success = u.removeVouch(vouchID)
if success:
description = 'Successfully removed vouch from profile.'
else:
description = f'Vouch #{vouchID} does not exist for this profile.'
embed = newEmbed(
description=description, color=(GREEN if success else RED))
await channel.send(embed=embed)
async def pending(channel: discord.TextChannel, getUser):
pendingVouches = data.loadJSON(data.DATABASE_FILENAME)['PendingVouches']
if len(pendingVouches) == 0:
embed = newEmbed(description='No pending vouches!', color=YELLOW)
await channel.send(embed=embed)
return
ids = ''
for i in pendingVouches:
ids += str(i['ID']) + (' | Positive' if i['IsPositive']
else ' | Negative') + '\n'
embed = newEmbed(description=ids, title='Pending vouches')
await channel.send(embed=embed)
async def verify(targetUser: discord.User, channel: discord.TextChannel):
'''
Toggles Verification for mentioned user
'''
u = User(targetUser.id)
u.setVerified(not u.verified)
if u.verified:
embed = newEmbed(
description=f'Verified {targetUser.mention}!', color=GREEN)
else:
embed = newEmbed(
description=f'Unverified {targetUser.mention}!', color=GREEN)
await channel.send(embed=embed)
async def deny(vouchID: int, channel: discord.TextChannel):
'''
Denies a vouch
'''
# Load the pending vouches
pendingVouches = data.loadJSON(data.DATABASE_FILENAME)['PendingVouches']
# Check if it exists, then delete it
for i, x in enumerate(pendingVouches):
if x['ID'] == vouchID:
del pendingVouches[i]
break
else:
await errorMessage(message=f'Could not find vouch with ID: {vouchID}')
return
data.updateJson(data.DATABASE_FILENAME, {'PendingVouches': pendingVouches})
embed = newEmbed(description=f'Deleted vouch #{vouchID}!', color=GREEN)
await channel.send(embed=embed)
async def approve(vouchID: int, channel: discord.TextChannel,
logChannel: discord.TextChannel, getUser):
'''
Approves a vouch
'''
# Load the pending vouches
allData = data.loadJSON(data.DATABASE_FILENAME)
pendingVouches = allData['PendingVouches']
# Check if the vouch exists, then delete it
for i, x in enumerate(pendingVouches):
if x['ID'] == vouchID:
# vouch = x
vouch = Vouch(x)
del pendingVouches[i]
break
else:
await errorMessage(message=f'Could not find vouch with ID: {vouchID}')
return
u = User(vouch.receiverID, allData)
u.addVouch(vouch)
receiverUser: discord.User = getUser(vouch.receiverID)
giverUser: discord.User = getUser(vouch.giverID)
# Message the user when their vouch is approved
# and only if they haven't opted out of notifications
if not u.ignoreNotifications:
isPositive = vouch.isPositive
vouchType = 'positive' if isPositive else 'negative'
msg = f'Received a {vouchType} vouch!'
embed = newEmbed(description=msg, color=(GREEN if isPositive else RED))
embed.set_footer(
text='React with ❌ to stop receiving vouch notifications')
await receiverUser.send(embed=embed)
# Save the vouch and send embed
data.updateJson(data.DATABASE_FILENAME,
{'PendingVouches': pendingVouches})
embed = newEmbed(description=f'Approved vouch #{vouchID}!', color=GREEN)
await channel.send(embed=embed)
# Send embed to log channel
embed = newEmbed(description='', title=f'Vouch ID: {vouchID}')
embed.add_field(name='Type', value=(
'Pos' if isPositive else 'Neg'), inline=False)
embed.add_field(name='Receiver', value=receiverUser.name, inline=False)
embed.add_field(name='Giver', value=giverUser.name, inline=False)
embed.add_field(name='Comment', value=vouch.message, inline=False)
embed.set_footer(
text='Approved Vouch')
await logChannel.send(embed=embed)
async def reply(targetUser: discord.User,
message: str,
channel: discord.TextChannel):
'''
Sends a message to a user, through the bot
'''
try:
await targetUser.send(message)
embed = newEmbed(description='Sent message!', color=GREEN)
await channel.send(embed=embed)
except Exception as e:
print(e)
await errorMessage('Could not send message to user!', channel)