Current section
Files
Jump to
Current section
Files
src/discord_gleam@discord@snowflake.erl
-module(discord_gleam@discord@snowflake).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/discord_gleam/discord/snowflake.gleam").
-export([from_string/1, to_string/1, decoder/0, compare/2, coerce/1]).
-export_type([snowflake/1, user/0, guild/0, channel/0, message/0, role/0, application/0, interaction/0, emoji/0, sku/0, webhook/0, attachment/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Snowflakes is discord's type for unique identifiers. \\\n"
" They are 64-bit unsigned integers, represented as strings. \\\n"
" See https://discord.com/developers/docs/reference#snowflakes\n"
).
-opaque snowflake(IQS) :: {snowflake, binary()} | {gleam_phantom, IQS}.
-type user() :: any().
-type guild() :: any().
-type channel() :: any().
-type message() :: any().
-type role() :: any().
-type application() :: any().
-type interaction() :: any().
-type emoji() :: any().
-type sku() :: any().
-type webhook() :: any().
-type attachment() :: any().
-file("src/discord_gleam/discord/snowflake.gleam", 37).
-spec from_string(binary()) -> snowflake(any()).
from_string(Value) ->
{snowflake, Value}.
-file("src/discord_gleam/discord/snowflake.gleam", 41).
-spec to_string(snowflake(any())) -> binary().
to_string(Snowflake) ->
erlang:element(2, Snowflake).
-file("src/discord_gleam/discord/snowflake.gleam", 46).
?DOC(" API should not give a int, but incase it does we will convert to string.\n").
-spec decoder() -> gleam@dynamic@decode:decoder(snowflake(any())).
decoder() ->
_pipe@1 = gleam@dynamic@decode:one_of(
{decoder, fun gleam@dynamic@decode:decode_string/1},
[begin
_pipe = {decoder, fun gleam@dynamic@decode:decode_int/1},
gleam@dynamic@decode:map(_pipe, fun erlang:integer_to_binary/1)
end]
),
gleam@dynamic@decode:map(_pipe@1, fun(Field@0) -> {snowflake, Field@0} end).
-file("src/discord_gleam/discord/snowflake.gleam", 51).
-spec compare(snowflake(IRA), snowflake(IRA)) -> gleam@order:order().
compare(A, B) ->
case gleam@int:compare(
string:length(erlang:element(2, A)),
string:length(erlang:element(2, B))
) of
eq ->
gleam@string:compare(erlang:element(2, A), erlang:element(2, B));
Other ->
Other
end.
-file("src/discord_gleam/discord/snowflake.gleam", 58).
-spec coerce(snowflake(any())) -> snowflake(any()).
coerce(S) ->
case S of
{snowflake, Value} ->
{snowflake, Value}
end.