[V3 Cleanup] refactor internals #2013

Merged
mikeshardmind merged 5 commits from cleanup-oneshot into V3/develop 2018-08-21 04:31:49 +02:00
mikeshardmind commented 2018-08-13 13:33:17 +02:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

Per discussion with @Tobotimus in discord, an alt to #1980 , #2006 , #2007 since deprecating the current usage shouldn't be necessary.

This reverts the hotfix #2004 , and refactors get_messages_for_deletion. This also adds a note in the doc string about the unsafe usage case no core code uses, and how to handle that case should we care about it in the future, rather than apply any special casing here.

### Type - [X] Bugfix - [ ] Enhancement - [ ] New feature ### Description of the changes Per discussion with @Tobotimus in discord, an alt to #1980 , #2006 , #2007 since deprecating the current usage shouldn't be necessary. This reverts the hotfix #2004 , and refactors `get_messages_for_deletion`. This also adds a note in the doc string about the unsafe usage case no core code uses, and how to handle that case should we care about it in the future, rather than apply any special casing here.
palmtree5 (Migrated from github.com) reviewed 2018-08-13 13:33:17 +02:00
tekulvw (Migrated from github.com) reviewed 2018-08-13 13:33:17 +02:00
Twentysix26 (Migrated from github.com) reviewed 2018-08-13 13:33:17 +02:00
Tobotimus commented 2018-08-19 09:59:19 +02:00 (Migrated from github.com)

On #1980 you stated this:

Because it's a timedelta, being out of sync on the base time isnt a concern, and I'd prefer removing ctx as we don't need it, so it opens up for event based usage without mocking an object.

I agree we should remove ctx and I like that change. However discord's time being out of sync with the system time can still cause problems, see this example, simply achieved by changing my PC's system time:
image

discord.errors.HTTPException: BAD REQUEST (status code: 400): You can only bulk delete messages that are under 14 days old.

To be honest I'm not too concerned about it, but it could be resolved by adding an optional now parameter to get_messages_for_deletion for callers to pass in ctx.message.created_at, but falls back to datetime.utcnow() if not provided.

On #1980 you stated this: > Because it's a timedelta, being out of sync on the base time isnt a concern, and I'd prefer removing ctx as we don't need it, so it opens up for event based usage without mocking an object. I agree we should remove ctx and I like that change. However discord's time being out of sync with the system time can still cause problems, see this example, simply achieved by changing my PC's system time: ![image](https://user-images.githubusercontent.com/7438501/44306794-365b8b80-a3d9-11e8-969b-b69b3137ea65.png) ``` discord.errors.HTTPException: BAD REQUEST (status code: 400): You can only bulk delete messages that are under 14 days old. ``` To be honest I'm not *too* concerned about it, but it could be resolved by adding an optional `now` parameter to `get_messages_for_deletion` for callers to pass in `ctx.message.created_at`, but falls back to `datetime.utcnow()` if not provided.
mikeshardmind commented 2018-08-19 16:59:19 +02:00 (Migrated from github.com)

You're right, the timedelta still gets compared to a snowflake, which isn't isolated, I think a better solution is if the first message the bot receives seems more than 2 minutes out of sync (discord.utils.snowflake_time, compared to datetime.utcnow()) to raise a warning. It shouldn't be a burden for each time sensitive piece of code to handle, but we can still take steps to alert users to that issue.

You're right, the timedelta still gets compared to a snowflake, which isn't isolated, I think a better solution is if the first message the bot receives seems more than 2 minutes out of sync (`discord.utils.snowflake_time`, compared to `datetime.utcnow()`) to raise a warning. It shouldn't be a burden for each time sensitive piece of code to handle, but we can still take steps to alert users to that issue.
mikeshardmind commented 2018-08-20 20:56:15 +02:00 (Migrated from github.com)

@Tobotimus I still don't believe that handling bad system clock times should be handled here, and have opened up #2036 to handle this instead.

@Tobotimus I still don't believe that handling bad system clock times should be handled here, and have opened up #2036 to handle this instead.
Tobotimus (Migrated from github.com) requested changes 2018-08-21 03:31:31 +02:00
Tobotimus (Migrated from github.com) left a comment

Will give the tick of approval after this change

Will give the tick of approval after this change
Tobotimus (Migrated from github.com) commented 2018-08-21 03:31:14 +02:00

This still needs to be in a try/except

This still needs to be in a try/except
Tobotimus (Migrated from github.com) approved these changes 2018-08-21 04:30:38 +02:00
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!2013
No description provided.