Skip to content

Commit 0e4c374

Browse files
committed
Use the method where possible to tidy up code.
1 parent e87669c commit 0e4c374

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

bot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ async def on_ready(self):
582582
continue
583583

584584
await thread.close(
585-
closer=self.get_user(items["closer_id"]) or await self.fetch_user(items["closer_id"]),
585+
closer=await self.get_or_fetch_user(items["closer_id"]),
586586
after=after,
587587
silent=items["silent"],
588588
delete_channel=items["delete_channel"],

cogs/modmail.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ async def logs(self, ctx, *, user: User = None):
10421042
thread = ctx.thread
10431043
if not thread:
10441044
raise commands.MissingRequiredArgument(SimpleNamespace(name="member"))
1045-
user = thread.recipient or await self.bot.fetch_user(thread.id)
1045+
user = thread.recipient or await self.bot.get_or_fetch_user(thread.id)
10461046

10471047
default_avatar = "https://cdn.discordapp.com/embed/avatars/0.png"
10481048
icon_url = getattr(user, "avatar_url", default_avatar)
@@ -1492,15 +1492,12 @@ async def blocked(self, ctx):
14921492
logger.debug("No longer blocked, user %s.", id_)
14931493
continue
14941494

1495-
user = self.bot.get_user(int(id_))
1496-
if user:
1497-
users.append((user.mention, reason))
1495+
try:
1496+
user = await self.bot.get_or_fetch_user(int(id_))
1497+
except discord.NotFound:
1498+
users.append((id_, reason))
14981499
else:
1499-
try:
1500-
user = await self.bot.fetch_user(id_)
1501-
users.append((user.mention, reason))
1502-
except discord.NotFound:
1503-
users.append((id_, reason))
1500+
users.append((user.mention, reason))
15041501

15051502
blocked_roles = list(self.bot.blocked_roles.items())
15061503
for id_, reason in blocked_roles:
@@ -1840,7 +1837,7 @@ async def repair(self, ctx):
18401837
user_id = match_user_id(message.embeds[0].footer.text)
18411838
other_recipients = match_other_recipients(ctx.channel.topic)
18421839
for n, uid in enumerate(other_recipients):
1843-
other_recipients[n] = self.bot.get_user(uid) or await self.bot.fetch_user(uid)
1840+
other_recipients[n] = await self.bot.get_or_fetch_user(uid)
18441841

18451842
if user_id != -1:
18461843
recipient = self.bot.get_user(user_id)
@@ -1893,7 +1890,7 @@ async def repair(self, ctx):
18931890

18941891
other_recipients = match_other_recipients(ctx.channel.topic)
18951892
for n, uid in enumerate(other_recipients):
1896-
other_recipients[n] = self.bot.get_user(uid) or await self.bot.fetch_user(uid)
1893+
other_recipients[n] = await self.bot.get_or_fetch_user(uid)
18971894

18981895
if recipient is None:
18991896
self.bot.threads.cache[user.id] = thread = Thread(

core/thread.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ async def from_channel(cls, manager: "ThreadManager", channel: discord.TextChann
126126
if recipient_id in manager.cache:
127127
thread = manager.cache[recipient_id]
128128
else:
129-
recipient = manager.bot.get_user(recipient_id) or await manager.bot.fetch_user(recipient_id)
129+
recipient = await manager.bot.get_or_fetch_user(recipient_id)
130130

131131
other_recipients = []
132132
for uid in match_other_recipients(channel.topic):
133133
try:
134-
other_recipient = manager.bot.get_user(uid) or await manager.bot.fetch_user(uid)
134+
other_recipient = await manager.bot.get_or_fetch_user(uid)
135135
except discord.NotFound:
136136
continue
137137
other_recipients.append(other_recipient)
@@ -1243,14 +1243,14 @@ async def _find_from_channel(self, channel):
12431243
return self.cache[user_id]
12441244

12451245
try:
1246-
recipient = self.bot.get_user(user_id) or await self.bot.fetch_user(user_id)
1246+
recipient = await self.bot.get_or_fetch_user(user_id)
12471247
except discord.NotFound:
12481248
recipient = None
12491249

12501250
other_recipients = []
12511251
for uid in match_other_recipients(channel.topic):
12521252
try:
1253-
other_recipient = self.bot.get_user(uid) or await self.bot.fetch_user(uid)
1253+
other_recipient = await self.bot.get_or_fetch_user(uid)
12541254
except discord.NotFound:
12551255
continue
12561256
other_recipients.append(other_recipient)

0 commit comments

Comments
 (0)