Skip to content

Commit 893f476

Browse files
BobDotCom requested changes
print() -> none unnecessary if len() > 0 because loop will run anyways #634 (review) Co-Authored-By: BobDotCom <[email protected]>
1 parent 863c619 commit 893f476

File tree

2 files changed

+44
-46
lines changed

2 files changed

+44
-46
lines changed

discord/bot.py

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -238,54 +238,52 @@ async def register_commands(self) -> None:
238238
registered_commands_dict = {cmd["name"]:cmd for cmd in registered_commands}
239239
global_pending_application_commands_dict = {}
240240

241-
if len(registered_commands) > 0:
242-
for command in [
243-
cmd for cmd in self.pending_application_commands if cmd.guild_ids is None
244-
]:
245-
as_dict = command.to_dict()
246-
247-
global_pending_application_commands_dict[command.name] = as_dict
248-
if command.name in registered_commands_dict:
249-
match = registered_commands_dict[command.name]
250-
else:
251-
match = None
252-
# TODO: There is probably a far more efficient way of doing this
253-
# We want to check if the registered global command on Discord servers matches the given global commands
254-
if match:
255-
as_dict["id"] = match["id"]
256-
257-
keys_to_check = {"default_permission": True, "name": True, "description": True, "options": ["type", "name", "description"]}
258-
for key, more_keys in {
259-
key:more_keys
260-
for key, more_keys in keys_to_check.items()
261-
if key in as_dict.keys()
262-
if key in match.keys()
263-
}.items():
264-
if key == "options":
265-
for i, option_dict in enumerate(as_dict[key]):
266-
for key2_change in [
267-
key2
268-
for key2 in more_keys
269-
if key2 in option_dict.keys() and key2 in match[key][i].keys()
270-
if option_dict[key2] != match[key][i][key2]
271-
]:
272-
print(f"A change in the '{key2_change}' property of '{key}' in the '{command.name}' global command was noticed, will send to Discord to update")
273-
needs_bulk = True
274-
else:
275-
if as_dict[key] != match[key]:
276-
print(f"A change in the '{key}' property of '{command.name}' global command was noticed, will send to Discord to update")
241+
for command in [
242+
cmd for cmd in self.pending_application_commands if cmd.guild_ids is None
243+
]:
244+
as_dict = command.to_dict()
245+
246+
global_pending_application_commands_dict[command.name] = as_dict
247+
if command.name in registered_commands_dict:
248+
match = registered_commands_dict[command.name]
249+
else:
250+
match = None
251+
# TODO: There is probably a far more efficient way of doing this
252+
# We want to check if the registered global command on Discord servers matches the given global commands
253+
if match:
254+
as_dict["id"] = match["id"]
255+
256+
keys_to_check = {"default_permission": True, "name": True, "description": True, "options": ["type", "name", "description"]}
257+
for key, more_keys in {
258+
key:more_keys
259+
for key, more_keys in keys_to_check.items()
260+
if key in as_dict.keys()
261+
if key in match.keys()
262+
}.items():
263+
if key == "options":
264+
for i, option_dict in enumerate(as_dict[key]):
265+
for key2_change in [
266+
key2
267+
for key2 in more_keys
268+
if key2 in option_dict.keys() and key2 in match[key][i].keys()
269+
if option_dict[key2] != match[key][i][key2]
270+
]:
271+
# When a property in the options of a pending global command is changed
277272
needs_bulk = True
278-
else:
279-
print(f"A pending global command '{command.name}' is not registered in Discord servers, will send to Discord to update")
280-
needs_bulk = True
273+
else:
274+
if as_dict[key] != match[key]:
275+
# When a property in a pending global command is changed
276+
needs_bulk = True
277+
else:
278+
# When a name of a pending global command is not registered in Discord
279+
needs_bulk = True
281280

282-
commands_to_bulk.append(as_dict)
281+
commands_to_bulk.append(as_dict)
283282

284-
if len(registered_commands_dict) > 0:
285-
for name, command in registered_commands_dict.items():
286-
if not name in global_pending_application_commands_dict.keys():
287-
print(f"A registered global command '{name}' is not found in the pending global commands, will send to Discord to update")
288-
needs_bulk = True
283+
for name, command in registered_commands_dict.items():
284+
if not name in global_pending_application_commands_dict.keys():
285+
# When a registered global command is not available in the pending global commands
286+
needs_bulk = True
289287

290288
if needs_bulk:
291289
commands = await self.http.bulk_upsert_global_commands(self.user.id, commands_to_bulk)

discord/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def __exit__(
153153
if self._unlock:
154154
self.lock.release()
155155

156-
156+
157157
# For some reason, the Discord voice websocket expects this header to be
158158
# completely lowercase while aiohttp respects spec and does it as case-insensitive
159159
aiohttp.hdrs.WEBSOCKET = 'websocket' # type: ignore

0 commit comments

Comments
 (0)