-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Continuation from #110: Add get_guild_ban and fix typo, cast into str…
…uct. (#224) * Add get_guild_ban and fix typo. * Decode into `Guild.Ban` struct. Co-authored-by: Juan <[email protected]>
- Loading branch information
1 parent
3a22f2b
commit 2adbb30
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,34 @@ | ||
defmodule Nostrum.Struct.Guild.Ban do | ||
@moduledoc """ | ||
Represents a guild ban. | ||
""" | ||
|
||
alias Nostrum.Struct.User | ||
alias Nostrum.Util | ||
|
||
defstruct [ | ||
:reason, | ||
:user | ||
] | ||
|
||
@typedoc "The reason for the ban" | ||
@type reason :: String.t() | nil | ||
|
||
@typedoc "The banned user" | ||
@type user :: User.t() | ||
|
||
@type t :: %__MODULE__{ | ||
reason: reason, | ||
user: user | ||
} | ||
|
||
@doc false | ||
def to_struct(map) do | ||
new = | ||
map | ||
|> Map.new(fn {k, v} -> {Util.maybe_to_atom(k), v} end) | ||
|> Map.update(:user, nil, &Util.cast(&1, {:struct, User})) | ||
|
||
struct(__MODULE__, new) | ||
end | ||
end |