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 22 commits
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
24 changes: 24 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,32 @@ async def on_ready(self):
print(Fore.RED + Style.BRIGHT + 'WARNING - The GUILD_ID provided does not exist!' + Style.RESET_ALL)
else:
await self.threads.populate_cache()
await self.config.update()

closures = self.config.closures.copy()

for recipient_id, items in closures.items():
after = (datetime.datetime.fromisoformat(items['time']) -
datetime.datetime.utcnow()).total_seconds()
if after < 0:
after = 0
recipient = self.get_user(int(recipient_id))

thread = await self.threads.find(
recipient=recipient)

if not thread:
# If the recipient is gone or channel is deleted
self.config.closures.pop(str(recipient_id))
await self.config.update()
continue

# TODO: Retrieve messages/replies when bot is down, from history?
Taaku18 marked this conversation as resolved.
Show resolved Hide resolved
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'],
delete_channel=items['delete_channel'],
message=items['message'])

async def process_modmail(self, message):
"""Processes messages sent to the bot."""
Expand Down
18 changes: 12 additions & 6 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ class ConfigManager:
"""Class that manages a cached configuration"""

allowed_to_change_in_command = {
'activity_message', 'activity_type', 'log_channel_id', 'mention', 'disable_autoupdates', 'prefix',
'main_category_id', 'sent_emoji', 'blocked_emoji', 'thread_creation_response', 'twitch_url'
'activity_message', 'activity_type', 'log_channel_id',
'mention', 'disable_autoupdates', 'prefix',
'main_category_id', 'sent_emoji', 'blocked_emoji',
'thread_creation_response', 'twitch_url'
}

internal_keys = {
'snippets', 'aliases', 'blocked', 'notification_squad', 'subscriptions'
'snippets', 'aliases', 'blocked',
'notification_squad', 'subscriptions',
'closures'
}

protected_keys = {
'token', 'owners', 'modmail_api_token', 'guild_id', 'modmail_guild_id',
'mongo_uri', 'github_access_token', 'log_url'
}

valid_keys = allowed_to_change_in_command.union(internal_keys).union(protected_keys)
valid_keys = allowed_to_change_in_command | internal_keys | protected_keys

def __init__(self, bot):
self.bot = bot
Expand All @@ -38,7 +42,8 @@ def populate_cache(self):
'aliases': {},
'blocked': {},
'notification_squad': {},
'subscriptions': {}
'subscriptions': {},
Taaku18 marked this conversation as resolved.
Show resolved Hide resolved
'closures': {},
}

try:
Expand All @@ -47,7 +52,8 @@ def populate_cache(self):
pass
finally:
data.update(os.environ)
data = {k.lower(): v for k, v in data.items() if k.lower() in self.valid_keys}
data = {k.lower(): v for k, v in data.items()
if k.lower() in self.valid_keys}
self.cache = data

async def update(self, data=None):
Expand Down
Loading