Current section

Files

Jump to
discord_gleam src discord_gleam@ws@packets@interaction_create.erl
Raw

src/discord_gleam@ws@packets@interaction_create.erl

-module(discord_gleam@ws@packets@interaction_create).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([string_to_data/1]).
-export_type([interaction_create_member/0, interaction_command/0, interaction_option/0, interaction_create_data/0, interaction_create/0, option_value/0]).
-type interaction_create_member() :: {interaction_create_member,
discord_gleam@types@user:user()}.
-type interaction_command() :: {interaction_command,
integer(),
binary(),
binary(),
gleam@option:option(list(interaction_option()))}.
-type interaction_option() :: {interaction_option,
binary(),
integer(),
option_value(),
gleam@option:option(list(interaction_option()))}.
-type interaction_create_data() :: {interaction_create_data,
binary(),
interaction_create_member(),
binary(),
binary(),
interaction_command(),
binary()}.
-type interaction_create() :: {interaction_create,
binary(),
integer(),
integer(),
interaction_create_data()}.
-type option_value() :: {string_value, binary()} |
{int_value, integer()} |
{bool_value, boolean()} |
{float_value, float()}.
-file("src/discord_gleam/ws/packets/interaction_create.gleam", 52).
-spec options_decoder() -> gleam@dynamic@decode:decoder(interaction_option()).
options_decoder() ->
gleam@dynamic@decode:field(
<<"name"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(Name) ->
gleam@dynamic@decode:field(
<<"type"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Type_) ->
gleam@dynamic@decode:field(
<<"value"/utf8>>,
gleam@dynamic@decode:one_of(
begin
_pipe = {decoder,
fun gleam@dynamic@decode:decode_string/1},
gleam@dynamic@decode:map(
_pipe,
fun(Field@0) -> {string_value, Field@0} end
)
end,
[begin
_pipe@1 = {decoder,
fun gleam@dynamic@decode:decode_int/1},
gleam@dynamic@decode:map(
_pipe@1,
fun(Field@0) -> {int_value, Field@0} end
)
end,
begin
_pipe@2 = {decoder,
fun gleam@dynamic@decode:decode_bool/1},
gleam@dynamic@decode:map(
_pipe@2,
fun(Field@0) -> {bool_value, Field@0} end
)
end,
begin
_pipe@3 = {decoder,
fun gleam@dynamic@decode:decode_float/1},
gleam@dynamic@decode:map(
_pipe@3,
fun(Field@0) -> {float_value, Field@0} end
)
end]
),
fun(Value) ->
gleam@dynamic@decode:optional_field(
<<"options"/utf8>>,
none,
gleam@dynamic@decode:optional(
gleam@dynamic@decode:list(options_decoder())
),
fun(Options) ->
gleam@dynamic@decode:success(
{interaction_option,
Name,
Type_,
Value,
Options}
)
end
)
end
)
end
)
end
).
-file("src/discord_gleam/ws/packets/interaction_create.gleam", 73).
-spec string_to_data(binary()) -> {ok, interaction_create()} | {error, binary()}.
string_to_data(Encoded) ->
Decoder = begin
gleam@dynamic@decode:field(
<<"t"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_string/1},
fun(T) ->
gleam@dynamic@decode:field(
<<"s"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(S) ->
gleam@dynamic@decode:field(
<<"op"/utf8>>,
{decoder, fun gleam@dynamic@decode:decode_int/1},
fun(Op) ->
gleam@dynamic@decode:field(
<<"d"/utf8>>,
begin
gleam@dynamic@decode:field(
<<"token"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(Token) ->
gleam@dynamic@decode:field(
<<"member"/utf8>>,
begin
gleam@dynamic@decode:field(
<<"user"/utf8>>,
discord_gleam@types@user:from_json_decoder(
),
fun(User) ->
gleam@dynamic@decode:success(
{interaction_create_member,
User}
)
end
)
end,
fun(Member) ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
discord_gleam@discord@snowflake:decoder(
),
fun(Id) ->
gleam@dynamic@decode:field(
<<"guild_id"/utf8>>,
discord_gleam@discord@snowflake:decoder(
),
fun(
Guild_id
) ->
gleam@dynamic@decode:field(
<<"data"/utf8>>,
begin
gleam@dynamic@decode:field(
<<"type"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(
Type_
) ->
gleam@dynamic@decode:field(
<<"name"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Name
) ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
discord_gleam@discord@snowflake:decoder(
),
fun(
Id@1
) ->
gleam@dynamic@decode:optional_field(
<<"options"/utf8>>,
none,
gleam@dynamic@decode:optional(
gleam@dynamic@decode:list(
options_decoder(
)
)
),
fun(
Options
) ->
gleam@dynamic@decode:success(
{interaction_command,
Type_,
Name,
Id@1,
Options}
)
end
)
end
)
end
)
end
)
end,
fun(
Data
) ->
gleam@dynamic@decode:field(
<<"channel_id"/utf8>>,
discord_gleam@discord@snowflake:decoder(
),
fun(
Channel_id
) ->
gleam@dynamic@decode:success(
{interaction_create_data,
Token,
Member,
Id,
Guild_id,
Data,
Channel_id}
)
end
)
end
)
end
)
end
)
end
)
end
)
end,
fun(D) ->
gleam@dynamic@decode:success(
{interaction_create, T, S, Op, D}
)
end
)
end
)
end
)
end
)
end,
_pipe = gleam@json:parse(Encoded, Decoder),
gleam@result:map_error(
_pipe,
fun(_) -> <<"Failed to decode InteractionCreate packet"/utf8>> end
).