Skip to content

Commit 3300762

Browse files
committed
Adress changes
1 parent 2e349a0 commit 3300762

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

core/decorators.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
from discord.ext import commands
55

66

7-
async def ignore(coro):
8-
try:
9-
await coro
10-
except:
11-
pass
12-
137
def trigger_typing(func):
148
@functools.wraps(func)
159
async def wrapper(self, ctx: commands.Context, *args, **kwargs):

core/thread.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
from discord.ext.commands import UserInputError, CommandError
99

1010
from core.models import Bot, ThreadManagerABC, ThreadABC
11-
from core.utils import is_image_url, days, match_user_id, truncate
12-
from core.decorators import ignore
11+
from core.utils import is_image_url, days, match_user_id, truncate, ignore
1312

1413

1514
class Thread(ThreadABC):
1615
"""Represents a discord Modmail thread"""
1716

1817
def __init__(self, manager: 'ThreadManager',
19-
recipient: typing.Union[discord.Member, discord.User,
20-
int],
18+
recipient: typing.Union[discord.Member, discord.User, int],
2119
channel: typing.Union[discord.DMChannel,
22-
discord.TextChannel]=None):
20+
discord.TextChannel] = None):
2321
self.manager = manager
2422
self.bot = manager.bot
2523
if isinstance(recipient, int):
@@ -72,9 +70,9 @@ def ready(self, flag):
7270
self._ready_event.set()
7371
else:
7472
self._ready_event.clear()
75-
73+
7674
async def setup(self, *, creator=None, category=None):
77-
"""Create the thread channel and other io related initilisation tasks"""
75+
"""Create the thread channel and other io related initialisation tasks"""
7876

7977
recipient = self.recipient
8078

@@ -105,8 +103,9 @@ async def setup(self, *, creator=None, category=None):
105103
)
106104

107105
log_count = sum(1 for log in log_data if not log['open'])
108-
info_embed = self.manager._format_info_embed(recipient, log_url, log_count,
109-
discord.Color.green())
106+
info_embed = self.manager._format_info_embed(recipient, log_url,
107+
log_count,
108+
discord.Color.green())
110109

111110
topic = f'User ID: {recipient.id}'
112111
if creator:
@@ -118,7 +117,7 @@ async def setup(self, *, creator=None, category=None):
118117
channel.edit(topic=topic),
119118
channel.send(mention, embed=info_embed)
120119
)
121-
120+
122121
self.ready = True
123122

124123
# Once thread is ready, tell the recipient.
@@ -213,7 +212,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
213212
sneak_peak = 'No content'
214213

215214
desc = f"[`{log_data['key']}`]({log_url}): "
216-
desc += truncate(sneak_peak, max=75-13)
215+
desc += truncate(sneak_peak, max=75 - 13)
217216
else:
218217
desc = "Could not resolve log url."
219218

@@ -306,14 +305,14 @@ async def reply(self, message, anonymous=False):
306305
description='Your message could not be delivered since'
307306
'the recipient shares no servers with the bot'
308307
))
309-
308+
310309
tasks = []
311-
310+
312311
try:
313312
await self.send(message,
314-
destination=self.recipient,
315-
from_mod=True,
316-
anonymous=anonymous)
313+
destination=self.recipient,
314+
from_mod=True,
315+
anonymous=anonymous)
317316
except Exception as e:
318317
print(e)
319318
tasks.append(message.channel.send(
@@ -329,16 +328,16 @@ async def reply(self, message, anonymous=False):
329328
# Send the same thing in the thread channel.
330329
tasks.append(
331330
self.send(message,
332-
destination=self.channel,
333-
from_mod=True,
334-
anonymous=anonymous)
335-
)
331+
destination=self.channel,
332+
from_mod=True,
333+
anonymous=anonymous)
334+
)
336335

337336
tasks.append(
338337
self.bot.api.append_log(message,
339-
self.channel.id,
340-
type_='anonymous' if anonymous else 'thread_message'
341-
))
338+
self.channel.id,
339+
type_='anonymous' if anonymous else 'thread_message'
340+
))
342341

343342
if self.close_task is not None:
344343
# cancel closing if a thread message is sent.
@@ -363,7 +362,7 @@ async def send(self, message, destination=None,
363362
self.channel.send(embed=discord.Embed(
364363
color=discord.Color.red(),
365364
description='Scheduled close has been cancelled.'
366-
)))
365+
)))
367366
self.bot.loop.create_task(tasks)
368367

369368
if not from_mod and not note:
@@ -372,7 +371,7 @@ async def send(self, message, destination=None,
372371
)
373372

374373
if not self.ready:
375-
self.wait_until_ready()
374+
await self.wait_until_ready()
376375

377376
destination = destination or self.channel
378377

@@ -433,7 +432,7 @@ async def send(self, message, destination=None,
433432
for att in images: # TODO: Logic needs review
434433
if not prioritize_uploads or (
435434
is_image_url(*att) and not
436-
embedded_image and
435+
embedded_image and
437436
att[1]
438437
):
439438
embed.set_image(url=att[0])

core/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,10 @@ def match_user_id(text: str) -> int:
175175
if match is not None:
176176
return int(match.group(1))
177177
return -1
178+
179+
180+
async def ignore(coro):
181+
try:
182+
await coro
183+
except Exception:
184+
pass

0 commit comments

Comments
 (0)