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

Migrate to Discord 2.0a0 #1815

Merged
merged 21 commits into from Oct 17, 2021
Merged

Migrate to Discord 2.0a0 #1815

merged 21 commits into from Oct 17, 2021

Conversation

Akarys42
Copy link
Contributor

@Akarys42 Akarys42 commented Sep 6, 2021

Since the Discord.py repository has been archived, we can switch to the latest commit of 2.0a0, knowing no breaking change will occur (still pinned to the commit just in case).

This PR fixes any problem related to the migration:

  • New avatar interface
  • TZ aware datetimes
  • Various internal API changes

Additionally, this PR adds the following:

  • Automatically join new threads
  • Plug threads into mod-log
  • Respect the parent channel when checking for a potential modlog blacklisting
  • Forbid threads from being silenced
  • Remove threads related perms when a channel is silenced or defcon shutdown is used

The bot will also automatically join new threads and silence cannot be used in threads due to their lack of permissions.
This was a significantly harder migration than Sir Lance, but I have tested every cog individually, we should hopefully not run into any issue.

Since the Discord.py repository has been archived, we can switch to the latest commit of 2.0a0, knowing no breaking change will occur (still pinned to the commit just in case).
This commits fixes any problem related to the migration:
- New avatar interface
- TZ aware datetimes
- Various inernal API changes
@Akarys42 Akarys42 added t: feature New feature or request a: dependencies Related to package dependencies and management p: 2 - normal Normal Priority t: enhancement Changes or improvements to existing features labels Sep 6, 2021
@Xithrius Xithrius added the s: needs review Author is waiting for someone to review and approve label Sep 8, 2021
Copy link
Contributor

@Kronifer Kronifer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@Xithrius Xithrius requested review from bast0006 and Bluenix2 and removed request for ks129 and Den4200 September 16, 2021 22:13
Copy link
Member

@Bluenix2 Bluenix2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All I could find from the diff, but I'll have to check what you didn't change as well to make sure we do not miss something.

Comment on lines 209 to 210
create_private_threads=None,
create_public_threads=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't re-enable them if they were previously enabled, or are we gonna use channel overrides here instead enabling it globally?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't think we're planning on enabling it globally atm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But considering that, I'm not sure these commands should do anything with thread permissions at all?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should, you can open threads on messages even if you don't have send message permissions.

And if you have the "Send messages in threads" then you can send messages in that thread.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, "Send messages in threads" should be changed, but these two are off by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that's two perms we want to enable per channel, not globally

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so I don't think defcon should mess with these two globally.

bot/exts/moderation/modlog.py Outdated Show resolved Hide resolved
count=None,
reconnect=True,
loop=None,
time=MISSING
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? Shouldn't MISSING be the keyword argument's default already?

Copy link
Contributor Author

@Akarys42 Akarys42 Sep 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh?

That was also my reaction :D but apparently due to how the API changed you have to set it explicitly

bot/exts/utils/bot.py Outdated Show resolved Hide resolved
bot/exts/utils/bot.py Outdated Show resolved Hide resolved
Akarys42 and others added 3 commits September 19, 2021 15:24
Co-authored-by: Bluenix <bluenixdev@gmail.com>
Co-authored-by: Bluenix <bluenixdev@gmail.com>
bot/exts/moderation/modlog.py Outdated Show resolved Hide resolved
Comment on lines +808 to +811
# If we are in the thread already we can most probably assume we already logged it?
# We don't really have a better way of doing this since the API doesn't make any difference between the two
if thread.me:
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

So this is sent when a thread is created, or we get access to a private thread by being mentioned in it.

We don't need this, when this event is received it should be from a thread being created no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you are looking at the right event. The API event for on_thread_join seems to be Thread Create, which fires both when a new thread becomes accessible by the bot and when the bot actually joins it.

Without this check, we would log the thread twice, once when it is created and the even first fires, and a second time when it actually joins the thread. That's what I could also check during my testings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also fires when anyone joins a thread.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, I took a screenshot of the right event at first but then mixed it up.

Yes, Thread Update is the one that is sent when people join. But Thread Create is only sent when a thread is made available to the bot.

thread_create.jpg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, which I believe is the one used by on_thread_join, since its behavior matches that. So we do need to have this check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, I am still not convinced. Thread Update is the one that gets sent when a thread gets updated, which it does when members join because now the list of joined members change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but I am not sure how that's relevant? I could confirm through testing that's the behaviour we want

Comment on lines +20 to +32
@Cog.listener()
async def on_thread_join(self, thread: Thread) -> None:
"""
Try to join newly created threads.

Despite the event name being misleading, this is dispatched when new threads are created.
"""
if thread.me:
# We have already joined this thread
return

with suppress(Forbidden):
await thread.join()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because we want the bot to appear in the right side?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! It first was to make it listen to messages, but we deemed that as unnecessary. I still find it nice to have the bots in the member list.

Co-authored-by: Bluenix <bluenixdev@gmail.com>
@Akarys42 Akarys42 dismissed mbaruh’s stale review October 10, 2021 15:53

Defcon won't touch global thread perms anymore

Copy link
Member

@HassanAbouelela HassanAbouelela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is not ready to be merged once reviewed, please wait for the great merge event.

@HassanAbouelela HassanAbouelela dismissed their stale review October 10, 2021 20:33

Policy is now enforced by review bot.

@Akarys42 Akarys42 added review: do not merge The PR can be reviewed but cannot be merged now and removed review: needs devops labels Oct 11, 2021
Copy link
Member

@brad90four brad90four left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@ChrisLovering ChrisLovering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we've missed some datetime comparisions here:

FWIW I think we shouldn't be stripping the tzinfo from timestamps from discord, but instead should be using arrow.utcnow() instead of datetime.utcnow() in those cases since arrow.utcnow() is aware

@Akarys42
Copy link
Contributor Author

FWIW I think we shouldn't be stripping the tzinfo from timestamps from discord, but instead should be using arrow.utcnow() instead of datetime.utcnow() in those cases since arrow.utcnow() is aware

Would there be a difference between the two?

@ChrisLovering
Copy link
Member

FWIW I think we shouldn't be stripping the tzinfo from timestamps from discord, but instead should be using arrow.utcnow() instead of datetime.utcnow() in those cases since arrow.utcnow() is aware

Would there be a difference between the two?

No functional difference with just this change, but rather since Discord.py now uses aware, it's probably better we use aware too, rather than changing Discord.py's to naive, this also encourages the use of arrow with our contribs, which has far less pitfalls that datetime, due to legacy constraints in datetime

Copy link
Member

@ChrisLovering ChrisLovering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my testing, my comment about using arrow.utcnow() rather than stripping tzinfo from D.py's dates isn't required.

@Akarys42 Akarys42 dismissed Bluenix2’s stale review October 15, 2021 09:44

Requested changes applied

@Akarys42 Akarys42 removed the review: do not merge The PR can be reviewed but cannot be merged now label Oct 17, 2021
@Akarys42 Akarys42 merged commit 4050b0c into main Oct 17, 2021
@Akarys42 Akarys42 deleted the discord-2.0 branch October 17, 2021 08:16
@Xithrius Xithrius removed the s: needs review Author is waiting for someone to review and approve label Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: dependencies Related to package dependencies and management p: 2 - normal Normal Priority t: enhancement Changes or improvements to existing features t: feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants