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
Migrate to Discord 2.0a0 #1815
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this 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.
bot/exts/moderation/defcon.py
Outdated
create_private_threads=None, | ||
create_public_threads=None, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
count=None, | ||
reconnect=True, | ||
loop=None, | ||
time=MISSING |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Co-authored-by: Bluenix <bluenixdev@gmail.com>
Co-authored-by: Bluenix <bluenixdev@gmail.com>
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
Defcon won't touch global thread perms anymore
There was a problem hiding this 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.
Policy is now enforced by review bot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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:
- https://github.com/python-discord/bot/blob/main/bot/exts/moderation/defcon.py#L114
now
is datetime.utcnow() so it naive - https://github.com/python-discord/bot/blob/main/bot/exts/moderation/voice_gate.py#L168
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 |
There was a problem hiding this 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.
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:
Additionally, this PR adds the following:
or defcon shutdown is usedThe 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.