Skip to content

Commit 6421496

Browse files
committed
refactor: Auto code audit
Tools used: Sorcery Ruff Black
1 parent 316388b commit 6421496

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+274
-431
lines changed

interactions/api/events/discord.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,7 @@ class MessageReactionAdd(BaseEvent):
534534
@property
535535
def reaction_count(self) -> int:
536536
"""Times the emoji in the event has been used to react"""
537-
if self.reaction is None:
538-
return 0
539-
return self.reaction.count
537+
return 0 if self.reaction is None else self.reaction.count
540538

541539

542540
@attrs.define(eq=False, order=False, hash=False, kw_only=False)

interactions/api/events/internal.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ class ExtensionLoad(BaseEvent):
236236
@property
237237
def metadata(self) -> "Type[Extension.Metadata] | None":
238238
"""The metadata of the extension, if it has any."""
239-
if self.extension.Metadata:
240-
return self.extension.Metadata
241-
return None
239+
return self.extension.Metadata or None
242240

243241

244242
@attrs.define(eq=False, order=False, hash=False, kw_only=True)

interactions/api/events/processors/guild_events.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ async def _on_raw_guild_create(self, event: "RawGatewayEvent") -> None:
3333
event: raw guild create event
3434
3535
"""
36-
new_guild: bool = True
37-
if self.cache.get_guild(event.data["id"]):
38-
# guild already cached, most likely an unavailable guild coming back online
39-
new_guild = False
40-
36+
new_guild = not self.cache.get_guild(event.data["id"])
4137
guild = self.cache.place_guild_data(event.data)
4238

4339
self._user._guild_ids.add(to_snowflake(event.data.get("id")))

interactions/api/http/http_requests/channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ async def create_tag(
575575
payload: PAYLOAD_TYPE = {
576576
"name": name,
577577
"emoji_id": int(emoji_id) if emoji_id else None,
578-
"emoji_name": emoji_name if emoji_name else None,
578+
"emoji_name": emoji_name or None,
579579
}
580580
payload = dict_filter_none(payload)
581581

interactions/api/http/http_requests/members.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async def modify_current_member(
138138
reason: An optional reason for the audit log
139139
140140
"""
141-
payload: PAYLOAD_TYPE = {"nick": nickname if not isinstance(nickname, Missing) else None}
141+
payload: PAYLOAD_TYPE = {"nick": None if isinstance(nickname, Missing) else nickname}
142142
await self.request(
143143
Route("PATCH", f"/guilds/{int(guild_id)}/members/@me"),
144144
payload=payload,

interactions/api/voice/audio.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ def _max_buffer_size(self) -> int:
220220
@property
221221
def audio_complete(self) -> bool:
222222
"""Uses the state of the subprocess to determine if more audio is coming"""
223-
if self.process:
224-
if self.process.poll() is None:
225-
return False
226-
return True
223+
return not self.process or self.process.poll() is not None
227224

228225
def _create_process(self, *, block: bool = True) -> None:
229226
before = (

interactions/api/voice/recorder.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ def run(self) -> None:
170170
# purge any data that is already in the socket
171171
readable, _, _ = select.select([sock], [], [], 0)
172172
log.debug("Purging socket buffer")
173-
while readable:
174-
if not sock.recv(4096):
175-
break
173+
while readable and sock.recv(4096):
176174
readable, _, _ = select.select([sock], [], [], 0)
177175
log.debug("Socket buffer purged, starting recording")
178176

interactions/api/voice/voice_gateway.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ async def run(self) -> None:
9292

9393
op = msg.get("op")
9494
data = msg.get("d")
95-
seq = msg.get("s")
96-
97-
if seq:
95+
if seq := msg.get("s"):
9896
self.sequence = seq
9997

10098
# This may try to reconnect the connection so it is best to wait

interactions/client/auto_shard_client.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ class AutoShardedClient(Client):
3131
"""
3232

3333
def __init__(self, *args, **kwargs) -> None:
34-
if "total_shards" not in kwargs:
35-
self.auto_sharding = True
36-
else:
37-
self.auto_sharding = False
38-
34+
self.auto_sharding = "total_shards" not in kwargs
3935
super().__init__(*args, **kwargs)
4036

4137
self._connection_state = None

interactions/client/client.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,12 @@ def _sanity_check(self) -> None:
560560
def _queue_task(self, coro: Listener, event: BaseEvent, *args, **kwargs) -> asyncio.Task:
561561
async def _async_wrap(_coro: Listener, _event: BaseEvent, *_args, **_kwargs) -> None:
562562
try:
563-
if not isinstance(_event, (events.Error, events.RawGatewayEvent)):
564-
if coro.delay_until_ready and not self.is_ready:
565-
await self.wait_until_ready()
563+
if (
564+
not isinstance(_event, (events.Error, events.RawGatewayEvent))
565+
and coro.delay_until_ready
566+
and not self.is_ready
567+
):
568+
await self.wait_until_ready()
566569

567570
if len(_event.__attrs_attrs__) == 2 and coro.event != "event":
568571
# override_name & bot & logging
@@ -1046,11 +1049,7 @@ async def wait_for_modal(
10461049
def predicate(event) -> bool:
10471050
if modal.custom_id != event.ctx.custom_id:
10481051
return False
1049-
if not author:
1050-
return True
1051-
if author != to_snowflake(event.ctx.author):
1052-
return False
1053-
return True
1052+
return author == to_snowflake(event.ctx.author) if author else True
10541053

10551054
resp = await self.wait_for("modal_completion", predicate, timeout)
10561055
return resp.ctx
@@ -1085,7 +1084,7 @@ async def wait_for_component(
10851084
asyncio.TimeoutError: if timed out
10861085
10871086
"""
1088-
if not (messages or components):
1087+
if not messages and not components:
10891088
raise ValueError("You must specify messages or components (or both)")
10901089

10911090
message_ids = (
@@ -1105,9 +1104,7 @@ def _check(event: events.Component) -> bool:
11051104
)
11061105
wanted_component = not custom_ids or ctx.custom_id in custom_ids
11071106
if wanted_message and wanted_component:
1108-
if check is None or check(event):
1109-
return True
1110-
return False
1107+
return bool(check is None or check(event))
11111108
return False
11121109

11131110
return await self.wait_for("component", checks=_check, timeout=timeout)
@@ -1242,7 +1239,7 @@ def add_interaction(self, command: InteractionCommand) -> bool:
12421239

12431240
if group is None or isinstance(command, ContextMenu):
12441241
self.interaction_tree[scope][command.resolved_name] = command
1245-
elif group is not None:
1242+
else:
12461243
if not (current := self.interaction_tree[scope].get(base)) or isinstance(current, SlashCommand):
12471244
self.interaction_tree[scope][base] = {}
12481245
if sub is None:
@@ -1754,9 +1751,7 @@ def get_ext(self, name: str) -> Extension | None:
17541751
Returns:
17551752
A extension, if found
17561753
"""
1757-
if ext := self.get_extensions(name):
1758-
return ext[0]
1759-
return None
1754+
return ext[0] if (ext := self.get_extensions(name)) else None
17601755

17611756
def __load_module(self, module, module_name, **load_kwargs) -> None:
17621757
"""Internal method that handles loading a module."""

0 commit comments

Comments
 (0)