Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled close event for thread save to config vars #135

Merged
merged 25 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a903f55
Use call_later for close
Taaku18 Jan 16, 2019
561ac20
Use call_later for close
Taaku18 Jan 16, 2019
ee665a2
Merge pull request #1 from Taaku18/testing
Taaku18 Jan 16, 2019
668c4ba
Fix flawed statement
Taaku18 Jan 16, 2019
d16204a
Fix flawed statement
Taaku18 Jan 16, 2019
e32fa34
Fix flawed statement
Taaku18 Jan 16, 2019
272a0aa
Fix flawed statement
Taaku18 Jan 16, 2019
75865eb
Style/Convention for thread.py
Taaku18 Jan 16, 2019
fe88794
Removed reference as it's not necessary
Taaku18 Jan 16, 2019
7d25c41
Merge branch 'master' of https://github.com/kyb3r/modmail into dev
Taaku18 Jan 16, 2019
7a2fde7
Added the use of config vars
Taaku18 Jan 16, 2019
ef58811
Attempt to fix a problem where it cancels scheduled close 3 times
Taaku18 Jan 16, 2019
a06cf97
Added debugging print statement
Taaku18 Jan 16, 2019
581246e
Attempt to fix missing config
Taaku18 Jan 16, 2019
1a43eeb
Attempt to fix missing config (found typo)
Taaku18 Jan 16, 2019
8300316
Perhaps refreshing will help?
Taaku18 Jan 16, 2019
28e59c5
Added debugging print statement
Taaku18 Jan 16, 2019
9c4de11
Attempted to fix problem & clears closure when it's closed
Taaku18 Jan 16, 2019
a63d1b8
Added handling for when the channel's deleted when the bot's down
Taaku18 Jan 16, 2019
fdc6428
Removed debugging print statement
Taaku18 Jan 17, 2019
768d9ad
Merge branch 'master' of https://github.com/kyb3r/modmail into dev
Taaku18 Jan 17, 2019
ee7e1bd
Attempt to address PR issues
Taaku18 Jan 17, 2019
81aba61
Should address a bug and some issues
Taaku18 Jan 17, 2019
6013ba8
Address a preformance concern
Taaku18 Jan 17, 2019
03560c9
Bump version to v1.5.0
Taaku18 Jan 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ async def on_ready(self):
await self.config.update()
continue

# TODO: Retrieve messages/replies when bot is down, from history?
# TODO: Low priority,
# Retrieve messages/replies when bot is down, from history?
await thread.close(closer=self.get_user(items['closer_id']),
Taaku18 marked this conversation as resolved.
Show resolved Hide resolved
after=after,
silent=items['silent'],
Expand Down
10 changes: 5 additions & 5 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ async def _close(self, ctx, *, after: UserFriendlyTime=None):
silent = str(message).lower() in {'silent', 'silently'}
cancel = str(message).lower() == 'cancel'

if cancel and thread.close_task is not None and not thread.close_task.cancelled():
thread.close_task.cancel()
await ctx.send(embed=discord.Embed(color=discord.Color.red(), description='Scheduled close has been cancelled.'))
return
elif cancel:
if cancel:
if thread.close_task is not None:
Taaku18 marked this conversation as resolved.
Show resolved Hide resolved
await thread.cancel_closure()
await ctx.send(embed=discord.Embed(color=discord.Color.red(), description='Scheduled close has been cancelled.'))
return
return await ctx.send(embed=discord.Embed(color=discord.Color.red(), description='This thread has not already been scheduled to close.'))

if after and after.dt > now:
Expand Down
27 changes: 15 additions & 12 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ async def close(self, *, closer, after=0, silent=False,
delete_channel=True, message=None):
"""Close a thread now or after a set time in seconds"""

if self.close_task is not None:
# restarts the after timer
self.close_task.cancel()
self.close_task = None
# restarts the after timer
await self.cancel_closure()

if after > 0:
# TODO: Add somewhere to clean up broken closures
Expand Down Expand Up @@ -82,9 +80,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
message=None, scheduled=False):
del self.manager.cache[self.id]

if scheduled:
self.bot.config.closures.pop(str(self.id), None)
await self.bot.config.update()
await self.cancel_closure()

if str(self.id) in self.bot.config.subscriptions:
Taaku18 marked this conversation as resolved.
Show resolved Hide resolved
del self.bot.config.subscriptions[str(self.id)]
Expand Down Expand Up @@ -112,7 +108,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
log_url = f"https://logs.modmail.tk/" \
f"{log_data['user_id']}/{log_data['key']}"

user = self.recipient.mention if self.recipient else str(self.id)
user = self.recipient.mention if self.recipient else f'`{self.id}`'

if log_data['messages']:
msg = str(log_data['messages'][0]['content'])
Expand Down Expand Up @@ -148,6 +144,15 @@ async def _close(self, closer, silent=False, delete_channel=True,

await asyncio.gather(*tasks)

async def cancel_closure(self):
if self.close_task is not None:
self.close_task.cancel()
self.close_task = None

to_update = self.bot.config.closures.pop(str(self.id), None)
if to_update is not None:
await self.bot.config.update()

@staticmethod
async def _edit_thread_message(channel, message_id, message):
async for msg in channel.history():
Expand Down Expand Up @@ -188,8 +193,7 @@ async def reply(self, message):

if self.close_task is not None:
# cancel closing if a thread message is sent.
self.close_task.cancel()
self.close_task = None
await self.cancel_closure()
tasks.append(self.channel.send(
embed=discord.Embed(color=discord.Color.red(),
description='Scheduled close has '
Expand All @@ -200,8 +204,7 @@ async def reply(self, message):
async def send(self, message, destination=None, from_mod=False):
if self.close_task is not None:
# cancel closing if a thread message is sent.
self.close_task.cancel()
self.close_task = None
await self.cancel_closure()
await self.channel.send(embed=discord.Embed(
color=discord.Color.red(),
description='Scheduled close has been cancelled.'))
Expand Down