Crux v2020-03-17 17:55:51Z Crux.Rest.Util View Source
Collection of util functions.
Link to this section Summary
Types
Used to attach files via Crux.Rest.create_message/2
or Crux.Rest.execute_webhook/3
.
All available types that can be resolved into a channel id.
All available types that can be resolved into a channel position.
All available types that can be resolved into an emoji id.
All available types that can be resolved into an emoji identifier.
All available types that can be resolved into a guild id.
All available types which can be resolved into a role position.
Used for functions setting an icon / image / etc.
Can be either a binary()
of an image or a data url.
All available types that can be resolved into a message id.
All available types that can be resolved into a target for a permission overwrite.
All available types that can be resolved into a role id.
All available types that can be resolved into a user id.
Functions
Updates a value in map
with the given fun
.
Is a noop if key
is not in map
.
Resolves a channel_id_resolvable/0
into a channel id.
Resolves a channel_position_resolvable/0
into a channel position.
Resolves a emoji_id_resolvable/0
into an emoji id.
Resolves a guild_id_resolvable/0
into a guild id.
Resolves a guild_role_position_resolvable/0
into a role position.
Used for functions resolving a image/0
into base64 image data urls.
Internally used to transform a image/0
within a map to a base64 image data urls.
Resolves a message_id_resolvable/0
into a message id.
Internally used to transform Crux.Rest.execute_webhook_options/0
and Crux.Rest.create_message_data/0
to a tuple of {body, extra_headers}
Resolves a t:overwrite_target_resolvabe/0
into an overwrite target.
Resolves a role_id_resolvable/0
into a role id.
Resolves a user_id_resolvable/0
into a user id.
Link to this section Types
attachment() View Source (since 0.2.0)
Used to attach files via Crux.Rest.create_message/2
or Crux.Rest.execute_webhook/3
.
This can be one of:
Example | |
---|---|
binary | <<0, 0, 0, 0>> (will be named "file.jpg") |
{binary, name} | {<<104, 101, 108, 108, 111>>, "hello.txt"} |
channel_id_resolvable()
View Source
(since 0.1.1)
channel_id_resolvable() ::
Crux.Structs.Message.t() | Crux.Structs.Channel.t() | Crux.Rest.snowflake()
channel_id_resolvable() :: Crux.Structs.Message.t() | Crux.Structs.Channel.t() | Crux.Rest.snowflake()
All available types that can be resolved into a channel id.
Deprecated: Use
Crux.Structs.CHannel.id_resolvable()
instead
channel_position_resolvable()
View Source
(since 0.1.1)
channel_position_resolvable() ::
Crux.Structs.Channel.t()
| %{channel: Crux.Structs.Channel.t(), position: integer()}
| {Crux.Rest.snowflake(), integer()}
| %{id: Crux.Rest.snowflake(), position: integer()}
channel_position_resolvable() :: Crux.Structs.Channel.t() | %{channel: Crux.Structs.Channel.t(), position: integer()} | {Crux.Rest.snowflake(), integer()} | %{id: Crux.Rest.snowflake(), position: integer()}
All available types that can be resolved into a channel position.
Deprecated: Use
Crux.Structs.Channel.position_resolvable()
instead
emoji_id_resolvable()
View Source
(since 0.1.1)
emoji_id_resolvable() ::
Crux.Structs.Reaction.t() | Crux.Structs.Emoji.t() | String.t()
emoji_id_resolvable() :: Crux.Structs.Reaction.t() | Crux.Structs.Emoji.t() | String.t()
All available types that can be resolved into an emoji id.
Deprecated: Use
Crux.Structs.Emoji.id_resolvable()
instead
emoji_identifier_resolvable()
View Source
(since 0.1.1)
emoji_identifier_resolvable() ::
Crux.Structs.Reaction.t() | Crux.Structs.Emoji.t() | String.t()
emoji_identifier_resolvable() :: Crux.Structs.Reaction.t() | Crux.Structs.Emoji.t() | String.t()
All available types that can be resolved into an emoji identifier.
Deprecated: Use
Crux.Structs.Emoji.identifier_resolvable()
instead
guild_id_resolvable()
View Source
(since 0.1.1)
guild_id_resolvable() ::
Crux.Structs.Guild.t()
| Crux.Structs.Channel.t()
| Crux.Structs.Message.t()
| Crux.Rest.snowflake()
guild_id_resolvable() :: Crux.Structs.Guild.t() | Crux.Structs.Channel.t() | Crux.Structs.Message.t() | Crux.Rest.snowflake()
All available types that can be resolved into a guild id.
Deprecated: Use
Crux.Structs.Guild.id_resolvable()
instead
guild_role_position_resolvable()
View Source
(since 0.1.2)
guild_role_position_resolvable() ::
{Crux.Structs.Role.t(), integer()}
| %{id: Crux.Rest.snowflake(), position: integer()}
| {Crux.Rest.snowflake(), integer()}
| %{role: Crux.Structs.Role.t(), position: integer()}
guild_role_position_resolvable() :: {Crux.Structs.Role.t(), integer()} | %{id: Crux.Rest.snowflake(), position: integer()} | {Crux.Rest.snowflake(), integer()} | %{role: Crux.Structs.Role.t(), position: integer()}
All available types which can be resolved into a role position.
Deprecated: Use
Crux.Structs.Role.position_resolvable()
instead.
image() View Source (since 0.2.0)
Used for functions setting an icon / image / etc.
Can be either a binary()
of an image or a data url.
message_id_resolvable()
View Source
(since 0.1.1)
message_id_resolvable() :: Crux.Structs.Message.t() | Crux.Rest.snowflake()
message_id_resolvable() :: Crux.Structs.Message.t() | Crux.Rest.snowflake()
All available types that can be resolved into a message id.
Deprecated: Use
Crux.Structs.Message.id_resolvable()
instead
overwrite_target_resolvable()
View Source
(since 0.1.1)
overwrite_target_resolvable() ::
Crux.Structs.Overwrite.t()
| Crux.Structs.Role.t()
| Crux.Structs.User.t()
| Crux.Structs.Member.t()
| Crux.Rest.snowflake()
overwrite_target_resolvable() :: Crux.Structs.Overwrite.t() | Crux.Structs.Role.t() | Crux.Structs.User.t() | Crux.Structs.Member.t() | Crux.Rest.snowflake()
All available types that can be resolved into a target for a permission overwrite.
Deprecated: Use
Crux.Structs.Overwrite.target_resolvable()
instead
role_id_resolvable()
View Source
(since 0.1.1)
role_id_resolvable() :: Crux.Structs.Role.t() | Crux.Rest.snowflake()
role_id_resolvable() :: Crux.Structs.Role.t() | Crux.Rest.snowflake()
All available types that can be resolved into a role id.
Deprecated: Use
Crux.Structs.Role.id_resolvable()
instead
user_id_resolvable()
View Source
(since 0.1.1)
user_id_resolvable() ::
Crux.Structs.Member.t() | Crux.Structs.User.t() | integer()
user_id_resolvable() :: Crux.Structs.Member.t() | Crux.Structs.User.t() | integer()
All available types that can be resolved into a user id.
Deprecated: Use
Crux.Structs.User.id_resolvable()
instead
Link to this section Functions
optional_update_in_map(map, key, fun) View Source (since 0.2.1)
Updates a value in map
with the given fun
.
Is a noop if key
is not in map
.
resolve_channel_id(id)
View Source
(since 0.1.1)
resolve_channel_id(channel :: channel_id_resolvable()) :: Crux.Rest.snowflake()
resolve_channel_id(channel :: channel_id_resolvable()) :: Crux.Rest.snowflake()
Resolves a channel_id_resolvable/0
into a channel id.
Examples
iex> %Crux.Structs.Channel{id: 222079895583457280}
...> |> Crux.Rest.Util.resolve_channel_id()
222079895583457280
iex> %Crux.Structs.Message{channel_id: 222079895583457280}
...> |> Crux.Rest.Util.resolve_channel_id()
222079895583457280
iex> 222079895583457280
...> |> Crux.Rest.Util.resolve_channel_id()
222079895583457280
resolve_channel_position(arg1)
View Source
(since 0.1.0)
resolve_channel_position(channel :: channel_position_resolvable()) :: %{
id: Crux.Rest.snowflake(),
position: integer()
}
resolve_channel_position(channel :: channel_position_resolvable()) :: %{ id: Crux.Rest.snowflake(), position: integer() }
Resolves a channel_position_resolvable/0
into a channel position.
Examples
iex> %Crux.Structs.Channel{id: 222079895583457280, position: 5}
...> |> Crux.Rest.Util.resolve_channel_position()
%{id: 222079895583457280, position: 5}
iex> {%Crux.Structs.Channel{id: 222079895583457280}, 5}
...> |> Crux.Rest.Util.resolve_channel_position()
%{id: 222079895583457280, position: 5}
iex> {222079895583457280, 5}
...> |> Crux.Rest.Util.resolve_channel_position()
%{id: 222079895583457280, position: 5}
iex> %{id: 222079895583457280, position: 5}
...> |> Crux.Rest.Util.resolve_channel_position()
%{id: 222079895583457280, position: 5}
resolve_emoji_id(emoji)
View Source
(since 0.1.1)
resolve_emoji_id(emoji :: emoji_id_resolvable()) :: String.t()
resolve_emoji_id(emoji :: emoji_id_resolvable()) :: String.t()
Resolves a emoji_id_resolvable/0
into an emoji id.
Examples
iex> %Crux.Structs.Emoji{id: 396521773216301056}
...> |> Crux.Rest.Util.resolve_emoji_id()
396521773216301056
iex> %Crux.Structs.Reaction{emoji: %Crux.Structs.Emoji{id: 396521773216301056}}
...> |> Crux.Rest.Util.resolve_emoji_id()
396521773216301056
iex> 396521773216301056
...> |> Crux.Rest.Util.resolve_emoji_id()
396521773216301056
resolve_guild_id(id)
View Source
(since 0.1.1)
resolve_guild_id(guild :: guild_id_resolvable()) :: Crux.Rest.snowflake()
resolve_guild_id(guild :: guild_id_resolvable()) :: Crux.Rest.snowflake()
Resolves a guild_id_resolvable/0
into a guild id.
Examples
iex> %Crux.Structs.Guild{id: 222078108977594368}
...> |> Crux.Rest.Util.resolve_guild_id()
222078108977594368
iex> %Crux.Structs.Channel{guild_id: 222078108977594368}
...> |> Crux.Rest.Util.resolve_guild_id()
222078108977594368
iex> %Crux.Structs.Message{guild_id: 222078108977594368}
...> |> Crux.Rest.Util.resolve_guild_id()
222078108977594368
iex> 222078108977594368
...> |> Crux.Rest.Util.resolve_guild_id()
222078108977594368
resolve_guild_role_position(arg1)
View Source
resolve_guild_role_position(role :: guild_role_position_resolvable()) :: %{
id: Crux.Rest.snowflake(),
position: integer()
}
resolve_guild_role_position(role :: guild_role_position_resolvable()) :: %{ id: Crux.Rest.snowflake(), position: integer() }
Resolves a guild_role_position_resolvable/0
into a role position.
Examples
iex> {%Crux.Structs.Role{id: 373405430589816834}, 5}
...> |> Crux.Rest.Util.resolve_guild_role_position()
%{id: 373405430589816834, position: 5}
iex> %{id: 373405430589816834, position: 5}
...> |> Crux.Rest.Util.resolve_guild_role_position()
%{id: 373405430589816834, position: 5}
iex> %{role: %Crux.Structs.Role{id: 373405430589816834}, position: 5}
...> |> Crux.Rest.Util.resolve_guild_role_position()
%{id: 373405430589816834, position: 5}
iex> {373405430589816834, 5}
...> |> Crux.Rest.Util.resolve_guild_role_position()
%{id: 373405430589816834, position: 5}
resolve_image(data, extension \\ "jpg") View Source (since 0.2.0)
Used for functions resolving a image/0
into base64 image data urls.
resolve_image_in_map(map, key) View Source (since 0.2.0)
Internally used to transform a image/0
within a map to a base64 image data urls.
resolve_message_id(id)
View Source
(since 0.1.0)
resolve_message_id(message :: message_id_resolvable()) :: Crux.Rest.snowflake()
resolve_message_id(message :: message_id_resolvable()) :: Crux.Rest.snowflake()
Resolves a message_id_resolvable/0
into a message id.
Examples
iex> %Crux.Structs.Message{id: 441568727302012928}
...> |> Crux.Rest.Util.resolve_message_id()
441568727302012928
iex> 441568727302012928
...> |> Crux.Rest.Util.resolve_message_id()
441568727302012928
resolve_multipart(data) View Source (since 0.2.0)
Internally used to transform Crux.Rest.execute_webhook_options/0
and Crux.Rest.create_message_data/0
to a tuple of {body, extra_headers}
resolve_overwrite_target(id)
View Source
(since 0.1.1)
resolve_overwrite_target(overwrite :: overwrite_target_resolvable()) ::
{String.t() | :unknown, Crux.Rest.snowflake()}
resolve_overwrite_target(overwrite :: overwrite_target_resolvable()) :: {String.t() | :unknown, Crux.Rest.snowflake()}
Resolves a t:overwrite_target_resolvabe/0
into an overwrite target.
Examples
iex> %Crux.Structs.Overwrite{type: "member", id: 218348062828003328}
...> |> Crux.Rest.Util.resolve_overwrite_target()
{"member", 218348062828003328}
iex> %Crux.Structs.Role{id: 376146940762783746}
...> |> Crux.Rest.Util.resolve_overwrite_target()
{"role", 376146940762783746}
iex> %Crux.Structs.User{id: 218348062828003328}
...> |> Crux.Rest.Util.resolve_overwrite_target()
{"member", 218348062828003328}
iex> %Crux.Structs.Member{user: 218348062828003328}
...> |> Crux.Rest.Util.resolve_overwrite_target()
{"member", 218348062828003328}
iex> 218348062828003328
...> |> Crux.Rest.Util.resolve_overwrite_target()
{:unknown, 218348062828003328}
resolve_role_id(role_id)
View Source
(since 0.1.0)
resolve_role_id(role :: role_id_resolvable()) :: integer()
resolve_role_id(role :: role_id_resolvable()) :: integer()
Resolves a role_id_resolvable/0
into a role id.
Examples
# A role struct
iex> %Crux.Structs.Role{id: 376146940762783746}
...> |> Crux.Rest.Util.resolve_role_id()
376146940762783746
# A role id
iex> 376146940762783746
...> |> Crux.Rest.Util.resolve_role_id()
376146940762783746
resolve_user_id(id)
View Source
(since 0.1.0)
resolve_user_id(user :: user_id_resolvable()) :: Crux.Rest.snowflake()
resolve_user_id(user :: user_id_resolvable()) :: Crux.Rest.snowflake()
Resolves a user_id_resolvable/0
into a user id.
Examples
iex> %Crux.Structs.User{id: 218348062828003328}
...> |> Crux.Rest.Util.resolve_user_id()
218348062828003328
iex> %Crux.Structs.Member{user: 218348062828003328}
...> |> Crux.Rest.Util.resolve_user_id()
218348062828003328
iex> 218348062828003328
...> |> Crux.Rest.Util.resolve_user_id()
218348062828003328