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_option/0, interaction_user/0, interaction_create_member/0, interaction_command/0, interaction_create_data/0, interaction_create/0]).
-type interaction_option() :: {interaction_option,
binary(),
integer(),
binary()}.
-type interaction_user() :: {interaction_user, binary(), binary()}.
-type interaction_create_member() :: {interaction_create_member,
interaction_user()}.
-type interaction_command() :: {interaction_command,
integer(),
binary(),
binary()}.
-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()}.
-file("src/discord_gleam/ws/packets/interaction_create.gleam", 40).
-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>>,
begin
gleam@dynamic@decode:field(
<<"username"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Username
) ->
gleam@dynamic@decode:field(
<<"id"/utf8>>,
discord_gleam@discord@snowflake:decoder(
),
fun(
Id
) ->
gleam@dynamic@decode:success(
{interaction_user,
Username,
Id}
)
end
)
end
)
end,
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@1) ->
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@2
) ->
gleam@dynamic@decode:success(
{interaction_command,
Type_,
Name,
Id@2}
)
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@1,
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(Err) ->
logging:log(error, <<"Failed to decode InteractionCreate: "/utf8>>),
gleam@io:debug(Err),
<<"Failed to decode InteractionCreate"/utf8>>
end
).