-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.py
281 lines (242 loc) · 9.57 KB
/
commands.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
import requests
import json
from time import sleep
from AMuteUsSettings import *
def setup() -> None:
"""
Sets up the program by fetching all usernames from the server and creating a user dictionary.
This function should only be called once, at the start of the program.
"""
global unamesList, userDict, UIDs
print("Fetching Usernames...")
for user in range(len(UIDs)):
print(f"Fetching Username {user+1} of {len(UIDs)}")
i = requests.get(f"https://discord.com/api/v9/guilds/{guildID}/members/{UIDs[user]}", headers={'Authorization': dcToken})
temp = json.loads(i.text)
print(i.reason)
unamesList.append(temp['user']['username'])
print(f"User {temp['user']['username']} fetched!")
print("All Usernames Fetched!")
print("Creating User Dictionary...")
userDict = {}.fromkeys(unamesList)
print("Adding UIDs to User Dictionary...")
index = 0
for where in userDict:
print(f"Adding UID {index+1} of {len(unamesList)}")
userDict[where] = UIDs[index]
index += 1
print("User Dictionary Created!")
print("Optimizing User List...")
reloadIgnoredList()
print("Starting AMuteUs...")
print("\n+-----------------------------------------------+\n| ___ __ ___ __ __ __ |\n| / | / |/ /_ __/ /____ / / / /____|\n| / /| | / /|_/ / / / / __/ _ \\ / / / / ___/|\n| / ___ |/ / / / /_/ / /_/ __/ / /_/ (__ ) |\n|/_/ |_/_/ /_/\\__,_/\\__/\\___/ \\____/____/ |\n+-----------------------------------------------+\nType '61' for command list\nType '60' to exit\n\n\n")
def unmuteAll() -> None:
"""
Unmutes all users in the user dictionary.
Notes
-----
This function loops through the user dictionary and calls `unmuteUser` on each user. It then waits for `wait` seconds before continuing.
"""
print("Unmuting All Users...")
for user in userDict:
unmuteUser(user)
sleep(wait)
print("All Users Unmuted!")
def muteAll() -> None:
"""
Mutes all users in the user dictionary.
Notes
-----
This function loops through the user dictionary and calls `muteUser` on each user. It then waits for `wait` seconds before continuing.
"""
print("Muting All Users...")
for user in userDict:
muteUser(user)
sleep(wait)
print("All Users Muted!")
def unmuteUndead() -> None:
"""
Unmutes all users with the status 'LIVE' in the user dictionary.
Notes
-----
This function checks each user in the user dictionary. If a user's status is 'LIVE' (status code 1),
it unmutes the user by calling `unmuteUser`. The function waits for `wait` seconds after each unmute operation.
If the user is not 'LIVE', and developer mode is enabled, it will print a developer message indicating the user's status.
Users in the ignored list are not affected by this function.
"""
print("Unmuting Undead...")
for user in userDict:
if getUserStatus(user) == 1:
unmuteUser(user)
sleep(wait)
else:
if(dev==True):{print(f"[DEV] {user:-<32} [{userIndicator[getUserStatus(user)]:^4}]")}
print("Unmuted Undead")
def muteUndead() -> None:
"""
Mutes all users with the status 'LIVE' in the user dictionary.
Notes
-----
This function checks each user in the user dictionary. If a user's status is 'LIVE' (status code 1),
it mutes the user by calling `muteUser`. The function waits for `wait` seconds after each mute operation.
If the user is not 'LIVE', and developer mode is enabled, it will print a developer message indicating the user's status.
Users in the ignored list are not affected by this function.
"""
print("Muting Undead...")
for user in userDict:
if getUserStatus(user) == 1:
muteUser(user)
sleep(wait)
else:
if(dev==True):{print(f"[DEV] {user:-<32} [{userIndicator[getUserStatus(user)]:^4}]")}
print("Muted Undead")
def unmuteUser(username: str) -> None:
"""
Unmutes the specified user on the Discord server.
Parameters
----------
username : str
The username of the user to be unmuted.
Notes
-----
This function sends a PATCH request to the Discord API to unmute the user. If developer mode is enabled,
it will print a developer message indicating the request's result.
"""
i = requests.patch(f"https://discord.com/api/v9/guilds/{guildID}/members/{userDict[username]}", json={"mute": False}, headers={'Authorization': dcToken})
if(dev==True):{print(f"[DEV] {username:-<32} [{i.reason:^4}]")}
def muteUser(username: str) -> None:
"""
Mutes the specified user on the Discord server.
Parameters
----------
username : str
The username of the user to be muted.
Notes
-----
This function sends a PATCH request to the Discord API to mute the user. If developer mode is enabled,
it will print a developer message indicating the request's result.
"""
i = requests.patch(f"https://discord.com/api/v9/guilds/{guildID}/members/{userDict[username]}", json={"mute": True}, headers={'Authorization': dcToken})
if(dev==True):{print(f"[DEV] {username:-<32} [{i.reason:^4}]")}
def listAllUsers() -> None:
"""
Lists all users with their respective statuses.
Notes
-----
This function iterates through the list of usernames (`unamesList`) and prints each user's
index, name, and status. The status is determined using the `getUserStatus` function and is
displayed using the `userIndicator` list. The output is formatted to align the indices and usernames.
"""
for index, user in enumerate(unamesList):
print(f"[{index+1:->3}] {user:-<32} [{userIndicator[getUserStatus(user)]:^4}]")
def selectUser() -> str:
"""
Lists all users and asks the user to select a user number.
Notes
-----
Returns a blank string if the user enters in a non-digit character.
"""
listAllUsers()
uInput = input("Enter User Number: ")
if uInput.isdigit():
return unamesList[int(uInput)-1]
else:
return ""
def listStatus(statusCode: int) -> None:
"""
Lists all users with a given status.
Parameters
----------
statusCode : int
The status code to list users for.
Notes
-----
This function iterates through the list of usernames (`unamesList`) and prints each user's
index, name, and status if the user's status matches the given status code. The output is
formatted to align the indices and usernames.
"""
print(f"{userIndicator[statusCode]} Users:")
for index, user in enumerate(unamesList):
if getUserStatus(user) == statusCode:
print(f"[{index+1:->3}] {user:-<32} [{userIndicator[getUserStatus(user)]:^4}]")
def getUserStatus(username: str) -> int:
"""
Gets the status of the specified user.
Parameters
----------
username : str
The username of the user to get the status of.
Returns
-------
int
The status of the user. The status codes are as follows:
0 - Dead
1 - Alive
2 - Ignored
Notes
-----
This function checks if the user is in the dead list or ignored list and returns the appropriate status.
If the user is not in either list, it returns a status of 1, indicating the user is alive.
"""
if username in ignoredList:
return 2
if username in deadList:
return 0
return 1
def userOnline(username: str) -> bool:
"""
Checks if a user is online.
Parameters
----------
username : str
The username of the user to check.
Returns
-------
bool
True if the user is online, False otherwise.
Notes
-----
This function sends a GET request to the Discord API to get the user's status, and then sends a PATCH request with the same
mute status to check if the request is successful. If the request is successful, it returns True, otherwise it returns False.
"""
i = requests.get(f"https://discord.com/api/v9/guilds/{guildID}/members/{userDict[username]}", headers={'Authorization': dcToken})
temp = json.loads(i.text)
i = requests.patch(f"https://discord.com/api/v9/guilds/{guildID}/members/{userDict[username]}", json={"mute": temp['mute']}, headers={'Authorization': dcToken})
if(dev==True):{print(f"[DEV] {username:-<32} [{i.reason:^4}]")}
if i.reason == "Bad Request":
return False
return True
def reloadIgnoredList() -> None:
"""
Reloads the ignored list by going through all users in the user dictionary and checking if they are online.
If a user is not online, they are added to the ignored list.
"""
global ignoredList
print("Reloading Ignored List...")
for i in range(len(ignoredList)):
ignoredList.pop()
for user in userDict:
if userOnline(user) == False:
ignoredList.append(user)
print("Ignored List Reloaded")
def clearDeadList() -> None:
"""
Clears the dead list by unmuting all users in the list and then emptying the list.
"""
global deadList
print("Clearing Deadlist...")
for i in range(len(deadList)):
unmuteUser(deadList.pop())
print("Deadlist Cleared!")
def delay(secs: int) -> None:
"""
Delays the program for the specified number of seconds.
Parameters
----------
secs : int
The number of seconds to delay the program.
"""
print(f"Delaying for {secs} seconds...")
sleep(secs)
if __name__ == "__main__":
print("This file is not intended to be run directly. Please run main.py instead.")