-
-
Notifications
You must be signed in to change notification settings - Fork 169
Channel Obfuscation #2574
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
Open
raventhyme
wants to merge
2
commits into
twilight-rs:main
Choose a base branch
from
raventhyme:channel-obfuscation-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Channel Obfuscation #2574
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| use bitflags::bitflags; | ||
| use serde::{ | ||
| de::{Deserialize, Deserializer}, | ||
| ser::{Serialize, Serializer}, | ||
| }; | ||
|
|
||
| bitflags! { | ||
| /// Gateway capabilities. | ||
| /// | ||
| /// Developers may specify capabilities when connecting to the gateway. | ||
| /// Capabilities allow applications to opt-in to gateway behavior. To | ||
| /// specify multiple capabilities, create a union using the `|` operator. See | ||
| /// [Discord Docs/Capabilities]. | ||
| /// | ||
| /// [Discord Docs/Capabilities]: https://discord.com/developers/docs/topics/gateway#identify-gateway-capabilities | ||
| #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
| pub struct Capabilities: u64 { | ||
| /// Opts the client into receiving obfuscated channel metadata over the | ||
| /// Gateway for channels it can't view. | ||
| /// | ||
| /// Discord plans to fully roll out Channel Obfuscation for all users on | ||
| /// November 16th, 2026, at which point specifying this capability would | ||
| /// have no effect. | ||
| /// | ||
| /// See [Discord Docs/Channel Obfuscation]. | ||
| /// | ||
| /// [Discord Docs/Channel Obfuscation]: https://docs.discord.com/developers/resources/channel#channel-object-obfuscated-channels | ||
| const CHANNEL_OBFUSCATION = 1 << 15; | ||
| } | ||
| } | ||
|
|
||
| impl<'de> Deserialize<'de> for Capabilities { | ||
| fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||
| Ok(Self::from_bits_truncate(u64::deserialize(deserializer)?)) | ||
| } | ||
| } | ||
|
|
||
| impl Serialize for Capabilities { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: Serializer, | ||
| { | ||
| serializer.serialize_u64(self.bits()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::Capabilities; | ||
| use serde::{Deserialize, Serialize}; | ||
| use serde_test::Token; | ||
| use static_assertions::{assert_impl_all, const_assert_eq}; | ||
| use std::{ | ||
| fmt::{Binary, Debug, LowerHex, Octal, UpperHex}, | ||
| hash::Hash, | ||
| ops::{ | ||
| BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, Sub, SubAssign, | ||
| }, | ||
| }; | ||
|
|
||
| assert_impl_all!( | ||
| Capabilities: Binary, | ||
| BitAnd, | ||
| BitAndAssign, | ||
| BitOr, | ||
| BitOrAssign, | ||
| BitXor, | ||
| BitXorAssign, | ||
| Clone, | ||
| Copy, | ||
| Debug, | ||
| Deserialize<'static>, | ||
| Eq, | ||
| Extend<Capabilities>, | ||
| FromIterator<Capabilities>, | ||
| Hash, | ||
| LowerHex, | ||
| Not, | ||
| Octal, | ||
| PartialEq, | ||
| Send, | ||
| Serialize, | ||
| Sub, | ||
| SubAssign, | ||
| Sync, | ||
| UpperHex | ||
| ); | ||
| const_assert_eq!(Capabilities::CHANNEL_OBFUSCATION.bits(), 1 << 15); | ||
|
|
||
| #[test] | ||
| fn serde() { | ||
| serde_test::assert_tokens( | ||
| &Capabilities::CHANNEL_OBFUSCATION, | ||
| &[Token::U64(Capabilities::CHANNEL_OBFUSCATION.bits())], | ||
| ); | ||
| // Deserialization truncates unknown bits. | ||
| serde_test::assert_de_tokens(&Capabilities::empty(), &[Token::U64(1 << 63)]); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.