-
Notifications
You must be signed in to change notification settings - Fork 150
decode message flags #718
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
lara-rium
wants to merge
5
commits into
Kraigie:master
Choose a base branch
from
lara-rium:message-flags
base: master
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
decode message flags #718
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9adca78
undo temporary duplicate lint disable for latest version compatibility
lara-rium d9d7fde
Revert "support @me for modify_member"
lara-rium 07bfcdd
apply requested changes
lara-rium 9f3caa3
Merge branch 'master' into message-flags
lara-rium dfe4cfd
remove redundant test
lara-rium 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| defmodule Nostrum.Struct.Message.Flags do | ||
| @moduledoc """ | ||
| Struct representing the flags a message can have | ||
| """ | ||
|
lara-rium marked this conversation as resolved.
|
||
| @moduledoc since: "NEXTVERSION" | ||
|
|
||
| import Bitwise | ||
|
|
||
| defstruct crossposted: false, | ||
| is_crosspost: false, | ||
| suppress_embeds: false, | ||
| source_message_deleted: false, | ||
| urgent: false, | ||
| has_thread: false, | ||
| ephemeral: false, | ||
| loading: false, | ||
| failed_to_mention_some_roles_in_thread: false, | ||
| suppress_notifications: false, | ||
| is_voice_message: false, | ||
| has_snapshot: false, | ||
| is_components_v2: false | ||
|
|
||
| @typedoc """ | ||
| Message has been published to subscribed channels (via Channel Following) | ||
| """ | ||
| @type crossposted :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message originated from a message in another channel (via Channel Following) | ||
| """ | ||
| @type is_crosspost :: boolean | ||
|
|
||
| @typedoc """ | ||
| Do not include any embeds when serializing message | ||
| """ | ||
| @type suppress_embeds :: boolean | ||
|
|
||
| @typedoc """ | ||
| The source message for a crosspost has been deleted (via Channel Following) | ||
| """ | ||
| @type source_message_deleted :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message came from the urgent message system | ||
| """ | ||
| @type urgent :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message has an associated thread, with the same id as the message | ||
| """ | ||
| @type has_thread :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message is only visible to the user who invoked the Interaction | ||
| """ | ||
| @type ephemeral :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message is an Interaction Response and the bot is "thinking" | ||
| """ | ||
| @type loading :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message failed to mention some roles and add their members to the thread | ||
| """ | ||
| @type failed_to_mention_some_roles_in_thread :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message will not trigger push and desktop notifications | ||
| """ | ||
| @type suppress_notifications :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message is a voice message | ||
| """ | ||
| @type is_voice_message :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message has a snapshot (via Message Forwarding) | ||
| """ | ||
| @type has_snapshot :: boolean | ||
|
|
||
| @typedoc """ | ||
| Message uses components v2 | ||
| """ | ||
| @type is_components_v2 :: boolean | ||
|
|
||
| @type flags :: %__MODULE__{ | ||
| crossposted: crossposted, | ||
| is_crosspost: is_crosspost, | ||
| suppress_embeds: suppress_embeds, | ||
| source_message_deleted: source_message_deleted, | ||
| urgent: urgent, | ||
| has_thread: has_thread, | ||
| ephemeral: ephemeral, | ||
| loading: loading, | ||
| failed_to_mention_some_roles_in_thread: failed_to_mention_some_roles_in_thread, | ||
| suppress_notifications: suppress_notifications, | ||
| is_voice_message: is_voice_message, | ||
| has_snapshot: has_snapshot, | ||
| is_components_v2: is_components_v2 | ||
| } | ||
|
|
||
| @type t :: flags | ||
|
|
||
| @typedoc "Raw message flags as sent by the Discord API" | ||
| @type raw_flags :: integer() | ||
|
|
||
| @flag_values [ | ||
| crossposted: 1 <<< 0, | ||
| is_crosspost: 1 <<< 1, | ||
| suppress_embeds: 1 <<< 2, | ||
| source_message_deleted: 1 <<< 3, | ||
| urgent: 1 <<< 4, | ||
| has_thread: 1 <<< 5, | ||
| ephemeral: 1 <<< 6, | ||
| loading: 1 <<< 7, | ||
| failed_to_mention_some_roles_in_thread: 1 <<< 8, | ||
| suppress_notifications: 1 <<< 12, | ||
| is_voice_message: 1 <<< 13, | ||
| has_snapshot: 1 <<< 14, | ||
| is_components_v2: 1 <<< 15 | ||
| ] | ||
|
|
||
| @doc """ | ||
| Constructs a flag struct based on an integer from the Discord API. | ||
|
|
||
| ## Examples | ||
|
|
||
| ```elixir | ||
| iex> Nostrum.Struct.Message.Flags.from_integer(258) | ||
| %Nostrum.Struct.Message.Flags{ | ||
| crossposted: false, | ||
| is_crosspost: true, | ||
| suppress_embeds: false, | ||
| source_message_deleted: false, | ||
| urgent: false, | ||
| has_thread: false, | ||
| ephemeral: false, | ||
| loading: false, | ||
| failed_to_mention_some_roles_in_thread: true, | ||
| suppress_notifications: false, | ||
| is_voice_message: false, | ||
| has_snapshot: false, | ||
| is_components_v2: false | ||
| } | ||
| ``` | ||
|
lara-rium marked this conversation as resolved.
|
||
| """ | ||
| @spec from_integer(raw_flags()) :: t | ||
| def from_integer(flag_value) do | ||
| boolean_list = | ||
| Enum.map(@flag_values, fn {flag, value} -> | ||
| {flag, (flag_value &&& value) == value} | ||
| end) | ||
|
|
||
| struct(__MODULE__, boolean_list) | ||
| end | ||
|
|
||
| @doc """ | ||
| Convert a flag struct to an integer value. | ||
|
|
||
| ## Examples | ||
|
|
||
| ```elixir | ||
| iex> my_flags = %Nostrum.Struct.Message.Flags{ | ||
| ...> crossposted: false, | ||
| ...> is_crosspost: true, | ||
| ...> suppress_embeds: false, | ||
| ...> source_message_deleted: false, | ||
| ...> urgent: false, | ||
| ...> has_thread: false, | ||
| ...> ephemeral: false, | ||
| ...> loading: false, | ||
| ...> failed_to_mention_some_roles_in_thread: true, | ||
| ...> suppress_notifications: false, | ||
| ...> is_voice_message: false, | ||
| ...> has_snapshot: false, | ||
| ...> is_components_v2: false | ||
| ...> } | ||
| iex> Nostrum.Struct.Message.Flags.to_integer(my_flags) | ||
| 258 | ||
| ``` | ||
| """ | ||
| @spec to_integer(t) :: raw_flags() | ||
| def to_integer(flag_struct) do | ||
| booleans = | ||
| flag_struct | ||
| |> Map.from_struct() | ||
| |> Map.to_list() | ||
|
|
||
| Enum.reduce(booleans, 0, fn {flag, enabled}, flag_value -> | ||
| case enabled do | ||
| true -> flag_value ||| @flag_values[flag] | ||
| false -> flag_value | ||
| end | ||
| end) | ||
| end | ||
| end | ||
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.
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 looks to now be undoing some of your latest changes to
masteraround the@meendpoint support, I assume this is unintentional and should get reverted.Uh oh!
There was an error while loading. Please reload this page.
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.
my thinking was that this pr is solely for decoding message flags so other features i added should be reverted. this conflict should probably be fixed while merging #717 or this pr. this wouldnt have happened if i hadnt forgotten to create a sole branch for #717 but it is what it is. lmk if u dont agree w this revert
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 would be best if you could drop these unrelated commits from the history of this branch, could you do that?
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.
hmm, how do i do that?
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.
So the basic idea would be something like this:
git checkout -b message-flags-backup, thengit checkout message-flagsgit rebase -i mastergit reset --hard message-flags-backupgit push -fBut I'm really struggling to see which commit actually intoduces the message flag decoding without other changes. It would maybe be best if you open a new pull request with only the message flag changes cherry picked out of here.
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 unfortunately don't have time for this right now.. anyone else is welcome to take this on