Skip to content

Commit 5836df2

Browse files
committed
Use the utility everywhere else to tidy up code.
1 parent 6754869 commit 5836df2

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

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 get_or_fetch_user(self.bot, 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 get_or_fetch_user(self.bot, id=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 get_or_fetch_user(self.bot, id=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 get_or_fetch_user(self.bot, id=uid)
18971894

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

core/thread.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from core.models import DMDisabled, DummyMessage, getLogger
1616
from core.time import human_timedelta
1717
from core.utils import (
18+
get_or_fetch_user,
1819
is_image_url,
1920
days,
2021
match_title,
@@ -126,12 +127,12 @@ async def from_channel(cls, manager: "ThreadManager", channel: discord.TextChann
126127
if recipient_id in manager.cache:
127128
thread = manager.cache[recipient_id]
128129
else:
129-
recipient = manager.bot.get_user(recipient_id) or await manager.bot.fetch_user(recipient_id)
130+
recipient = await get_or_fetch_user(manager.bot, id=recipient_id)
130131

131132
other_recipients = []
132133
for uid in match_other_recipients(channel.topic):
133134
try:
134-
other_recipient = manager.bot.get_user(uid) or await manager.bot.fetch_user(uid)
135+
other_recipient = await get_or_fetch_user(manager.bot, id=uid)
135136
except discord.NotFound:
136137
continue
137138
other_recipients.append(other_recipient)
@@ -1243,14 +1244,14 @@ async def _find_from_channel(self, channel):
12431244
return self.cache[user_id]
12441245

12451246
try:
1246-
recipient = self.bot.get_user(user_id) or await self.bot.fetch_user(user_id)
1247+
recipient = await get_or_fetch_user(self.bot, id=user_id)
12471248
except discord.NotFound:
12481249
recipient = None
12491250

12501251
other_recipients = []
12511252
for uid in match_other_recipients(channel.topic):
12521253
try:
1253-
other_recipient = self.bot.get_user(uid) or await self.bot.fetch_user(uid)
1254+
other_recipient = await get_or_fetch_user(self.bot, id=uid)
12541255
except discord.NotFound:
12551256
continue
12561257
other_recipients.append(other_recipient)

0 commit comments

Comments
 (0)