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

Split GuildThread from GuildChannel #3026

Open
wants to merge 184 commits into
base: next
Choose a base branch
from

Conversation

GnomedDev
Copy link
Member

@GnomedDev GnomedDev commented Nov 12, 2024

This fixes #2991, via the solution voted for on the serenity discord.

@github-actions github-actions bot added model Related to the `model` module. builder Related to the `builder` module. cache Related to the `cache`-feature. http Related to the `http` module. utils Related to the `utils` module. gateway Related to the `gateway` module. examples Related to Serenity's examples. labels Nov 12, 2024
@GnomedDev GnomedDev force-pushed the thread-split branch 4 times, most recently from d87a2db to 037c2d6 Compare November 14, 2024 01:23
@GnomedDev GnomedDev force-pushed the thread-split branch 6 times, most recently from 16cc66c to f400ac4 Compare November 17, 2024 21:36
@GnomedDev GnomedDev marked this pull request as ready for review November 17, 2024 21:38
@GnomedDev
Copy link
Member Author

GnomedDev commented Nov 17, 2024

This is ready for review, the main changes are:

  • GuildChannel is now:

    • BaseGuildChannel (shared fields)
    • GuildChannel (channel-exclusive)
    • GuildThread (thread-exclusive)
    • GenericGuildChannelRef (an enum over references to both)
  • PartialChannel is now:

    • BaseInteractionChannel (shared fields)
    • InteractionChannel (channel-exclusive)
    • InteractionThread (thread-exclusive)
    • GenericInteractionChannel (an enum over the both)
  • ChannelId is now:

    • GenericChannelId (shared purpose/methods)
    • ChannelId (channel-exclusive)
    • ThreadId (thread-exclusive)

The IDs have methods to convert between, such as:

  • GenericChannelId::expect_channel and GenericChannelId::expect_thread which casts the ID types without touching the value
  • GenericChannelId::split which calls both and returns both for when something needs to handle both cases
  • ThreadId::widen and Channelid::widen which cast to GenericChannelId for when you have a specific ID and need to "widen" the number of methods you can call.

GenericGuildChannelRef is returned from the new Guild::channel method, which looks the GenericChannelId up in both Guild::channels and Guild::threads.

@arqunis arqunis added enhancement An improvement to Serenity. breaking change The public API is changed, resulting in miscompilations or unexpected new behaviour for users labels Nov 17, 2024
Copy link
Member

@jamesbt365 jamesbt365 left a comment

Choose a reason for hiding this comment

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

This looks really good, not 100% sure if I like the name changes for PartialChannel, but I can't think of anything better right now so I think its passable.

@peanutbother
Copy link

I also think the naming could be improved since we are explicitly talking about channels and threads.
My proposal in discord was the following:

How about

enum MessageOrigin {
    Channel(ChannelId),
    Thread(ThreadId)
}

seems a better naming to me since I see Threads as their own thing so I would not name a message's origin a channel

In that naming scheme I would name Base* rather Origin* and in some contexts append or prepend Message* or Interaction* accordingly.

@GnomedDev
Copy link
Member Author

@peanutbother I don't fully understand how this "origin" naming improves things? From how I processed that I think you are saying OriginGuildChannel which doesn't make too much sense, and we already have prepended Interaction where possible (as the other types are truly generically used everywhere).

@peanutbother
Copy link

peanutbother commented Nov 19, 2024

I mean something like MessageOrigin and InteractionOrigin as base names instead of the chosen base names as for e.g. threads and channels the base name is still channel.

jamesbt365 and others added 20 commits February 13, 2025 20:44
This was missing on FullEvent but was present within the event itself.
Values are getting quite close to the u8 limit (193), so let's
preemptively bump this to avoid future breaking changes.
Moves the feature-gated collector methods on `UserId`, `MessageId`, etc.
into four traits:
- `CollectMessages` 
- `CollectReactions`
- `CollectModalInteractions` 
- `CollectComponentInteractions`

This also moves the quick modal machinery into the collector module and defines
a `QuickModal` trait. 

This fully removes any collector feature gates from the model types.
This file was removed from the module tree but never actually deleted.
…rs#3075)

Similar to message URLs, Discord also provides URLs for guild channels.

Additionally, the function is added as an alternative for parsing a `Channel` from a string. 
Private channels are not affected by this change.
The `Deserialize` implementation neglects to add the `Bot ` prefix to
the string when it is deserialised.

This adds `TryFrom` implementations for `&str` and `String` and tells
serde to deserialise `Token` using the `TryFrom<&str>` implementation,
which will prepend the `Bot ` prefix.

Fixes serenity-rs#3085
This commit refactors how the gateway connection being closed gets handled,
and also reworks how resuming is performed. If a resume fails, or if the
session id is invalid/doesn't exist, the shard will fall back to restart
+ reidentify after a 1 second delay. This behavior was only present in
some circumstances before.

Also, cleaned up the loop in `ShardRunner::run` by adding a
`ShardAction::Dispatch` variant, since event dispatch was already
mutually exclusive to hearbeating, identifying, and restarting. The
overall effect is less interleaving of control flow.

Plus, removed the `Shard::{reconnect, reset}` functions as they were
unused.

A notable change is that 4006 is no longer considered a valid close code
as it is undocumented, and neither is 1000, which tungstenite assigns as
`Normal` or "clean". We should stick to the [table of close
codes](https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes)
provided by Discord.
A regression introduced by serenity-rs#3099 was that successful resumes will break
out of the loop inside `ShardRunner::run`, but they shouldn't (or
rather, didn't before). Therefore, only break out of the loop if the
resume failed and we had to fallback to reidentifying.
xacrimon and others added 4 commits February 14, 2025 21:21
…3111)

As the title notes, this commit replaces fxhash for foldhash as used in the
cache. dashmap, due to it's sharding, has to share entropy with what's handed
down to internal maps. Since `hashbrown` and by extension `std` use various
sections of the high bit range for special grouping & sorting, dashmap is left
with the only option to shard on low bits.

This, however, presents problems, because fxhash outputs hashes of very bad
quality, with only the high bits having any real entropy. This was probably a
solid choice back in 2018 when we lacked other good fast alternatives. But
since then `ahash` matured and we've had significant research and development
in "good enough" hashing for datastructures with short keys, [the most recent
step forward coming from a rather well known face][foldhash]. This improves
shard selection quite a bit and reduces contention significantly. Using fxhash
in a dashmap specific benchmark causes contention to go up by 3-8x when keys
are k-sortable with time (Discord snowflakes) on an M1 Pro.

[foldhash]: https://github.com/orlp/foldhash
…s#3088)

This replaces the time unit that determines how many messages in a
period of X time should be deleted when a user is banned. Discord
expresses this time in seconds, whereas Serenity exposed it in days. The
limit is still 7 days, but with this, users of Serenity can be more
precise with which messages they want to delete.
@github-actions github-actions bot added the collector Related to the `collector` module. label Feb 16, 2025
@arqunis arqunis force-pushed the next branch 2 times, most recently from 57c79ff to 9a811a7 Compare March 11, 2025 22:17
@jamesbt365 jamesbt365 requested a review from mkrasnitski March 14, 2025 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change The public API is changed, resulting in miscompilations or unexpected new behaviour for users builder Related to the `builder` module. cache Related to the `cache`-feature. collector Related to the `collector` module. enhancement An improvement to Serenity. examples Related to Serenity's examples. gateway Related to the `gateway` module. http Related to the `http` module. model Related to the `model` module. utils Related to the `utils` module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet