Skip to content

Commit

Permalink
Use the method where possible to tidy up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwerty-133 committed Sep 21, 2021
1 parent e87669c commit 0e4c374
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ async def on_ready(self):
continue

await thread.close(
closer=self.get_user(items["closer_id"]) or await self.fetch_user(items["closer_id"]),
closer=await self.get_or_fetch_user(items["closer_id"]),
after=after,
silent=items["silent"],
delete_channel=items["delete_channel"],
Expand Down
19 changes: 8 additions & 11 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ async def logs(self, ctx, *, user: User = None):
thread = ctx.thread
if not thread:
raise commands.MissingRequiredArgument(SimpleNamespace(name="member"))
user = thread.recipient or await self.bot.fetch_user(thread.id)
user = thread.recipient or await self.bot.get_or_fetch_user(thread.id)

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

user = self.bot.get_user(int(id_))
if user:
users.append((user.mention, reason))
try:
user = await self.bot.get_or_fetch_user(int(id_))
except discord.NotFound:
users.append((id_, reason))
else:
try:
user = await self.bot.fetch_user(id_)
users.append((user.mention, reason))
except discord.NotFound:
users.append((id_, reason))
users.append((user.mention, reason))

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

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

other_recipients = match_other_recipients(ctx.channel.topic)
for n, uid in enumerate(other_recipients):
other_recipients[n] = self.bot.get_user(uid) or await self.bot.fetch_user(uid)
other_recipients[n] = await self.bot.get_or_fetch_user(uid)

if recipient is None:
self.bot.threads.cache[user.id] = thread = Thread(
Expand Down
8 changes: 4 additions & 4 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ async def from_channel(cls, manager: "ThreadManager", channel: discord.TextChann
if recipient_id in manager.cache:
thread = manager.cache[recipient_id]
else:
recipient = manager.bot.get_user(recipient_id) or await manager.bot.fetch_user(recipient_id)
recipient = await manager.bot.get_or_fetch_user(recipient_id)

other_recipients = []
for uid in match_other_recipients(channel.topic):
try:
other_recipient = manager.bot.get_user(uid) or await manager.bot.fetch_user(uid)
other_recipient = await manager.bot.get_or_fetch_user(uid)
except discord.NotFound:
continue
other_recipients.append(other_recipient)
Expand Down Expand Up @@ -1243,14 +1243,14 @@ async def _find_from_channel(self, channel):
return self.cache[user_id]

try:
recipient = self.bot.get_user(user_id) or await self.bot.fetch_user(user_id)
recipient = await self.bot.get_or_fetch_user(user_id)
except discord.NotFound:
recipient = None

other_recipients = []
for uid in match_other_recipients(channel.topic):
try:
other_recipient = self.bot.get_user(uid) or await self.bot.fetch_user(uid)
other_recipient = await self.bot.get_or_fetch_user(uid)
except discord.NotFound:
continue
other_recipients.append(other_recipient)
Expand Down

0 comments on commit 0e4c374

Please sign in to comment.