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, inline]).
-define(FILEPATH, "src/discord_gleam/ws/packets/interaction_create.gleam").
-export([from_json_string/1]).
-export_type([interaction_data/0, interaction_option/0, interaction_type/0, interaction_create_packet_data/0, interaction_create_packet/0, option_value/0]).
-type interaction_data() :: {application_command,
integer(),
binary(),
discord_gleam@discord@snowflake:snowflake(discord_gleam@discord@snowflake:interaction()),
gleam@option:option(list(interaction_option()))} |
{message_component,
binary(),
integer(),
gleam@option:option(list(binary())),
gleam@option:option(discord_gleam@types@component_response:resolved_data())} |
{modal_submit,
binary(),
list(discord_gleam@types@component_response:component_response()),
gleam@option:option(discord_gleam@types@component_response:resolved_data())} |
empty.
-type interaction_option() :: {interaction_option,
binary(),
integer(),
option_value(),
gleam@option:option(list(interaction_option()))}.
-type interaction_type() :: ping_type |
application_command_type |
message_component_type |
application_command_autocomplete_type |
modal_submit_type |
unknown_type.
-type interaction_create_packet_data() :: {interaction_create_packet_data,
discord_gleam@discord@snowflake:snowflake(discord_gleam@discord@snowflake:interaction()),
discord_gleam@discord@snowflake:snowflake(discord_gleam@discord@snowflake:application()),
interaction_type(),
interaction_data(),
gleam@option:option(discord_gleam@discord@snowflake:snowflake(discord_gleam@discord@snowflake:guild())),
gleam@option:option(discord_gleam@types@channel:channel()),
discord_gleam@discord@snowflake:snowflake(discord_gleam@discord@snowflake:channel()),
gleam@option:option(discord_gleam@types@guild_member:guild_member()),
gleam@option:option(discord_gleam@types@user:user()),
binary(),
gleam@option:option(discord_gleam@ws@packets@message:message_packet_data()),
binary(),
gleam@option:option(binary())}.
-type interaction_create_packet() :: {interaction_create_packet,
binary(),
integer(),
integer(),
interaction_create_packet_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", 87).
-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", 108).
-spec from_json_string(binary()) -> {ok, interaction_create_packet()} |
{error, gleam@json:decode_error()}.
from_json_string(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(
<<"id"/utf8>>,
discord_gleam@discord@snowflake:decoder(
),
fun(Id) ->
gleam@dynamic@decode:field(
<<"application_id"/utf8>>,
discord_gleam@discord@snowflake:decoder(
),
fun(Application_id) ->
gleam@dynamic@decode:field(
<<"type"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(Type_int) ->
Type_ = case Type_int of
1 ->
ping_type;
2 ->
application_command_type;
3 ->
message_component_type;
4 ->
application_command_autocomplete_type;
5 ->
modal_submit_type;
_ ->
unknown_type
end,
gleam@dynamic@decode:field(
<<"data"/utf8>>,
(case Type_ of
application_command_type ->
gleam@dynamic@decode:field(
<<"type"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(
Type_@1
) ->
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(
{application_command,
Type_@1,
Name,
Id@1,
Options}
)
end
)
end
)
end
)
end
);
message_component_type ->
gleam@dynamic@decode:field(
<<"custom_id"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Custom_id
) ->
gleam@dynamic@decode:field(
<<"component_type"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_int/1},
fun(
Component_type
) ->
gleam@dynamic@decode:optional_field(
<<"values"/utf8>>,
none,
gleam@dynamic@decode:optional(
gleam@dynamic@decode:list(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
)
),
fun(
Values
) ->
gleam@dynamic@decode:optional_field(
<<"resolved"/utf8>>,
none,
gleam@dynamic@decode:optional(
discord_gleam@types@component_response:resolved_data_decoder(
)
),
fun(
Resolved
) ->
gleam@dynamic@decode:success(
{message_component,
Custom_id,
Component_type,
Values,
Resolved}
)
end
)
end
)
end
)
end
);
modal_submit_type ->
gleam@dynamic@decode:field(
<<"custom_id"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Custom_id@1
) ->
gleam@dynamic@decode:field(
<<"components"/utf8>>,
gleam@dynamic@decode:list(
discord_gleam@types@component_response:json_decoder(
)
),
fun(
Components
) ->
gleam@dynamic@decode:optional_field(
<<"resolved"/utf8>>,
none,
gleam@dynamic@decode:optional(
discord_gleam@types@component_response:resolved_data_decoder(
)
),
fun(
Resolved@1
) ->
gleam@dynamic@decode:success(
{modal_submit,
Custom_id@1,
Components,
Resolved@1}
)
end
)
end
)
end
);
_ ->
gleam@dynamic@decode:success(
empty
)
end),
fun(Data) ->
gleam@dynamic@decode:optional_field(
<<"guild_id"/utf8>>,
none,
gleam@dynamic@decode:optional(
discord_gleam@discord@snowflake:decoder(
)
),
fun(
Guild_id
) ->
gleam@dynamic@decode:optional_field(
<<"channel"/utf8>>,
none,
gleam@dynamic@decode:optional(
discord_gleam@types@channel:json_decoder(
)
),
fun(
Channel
) ->
gleam@dynamic@decode:field(
<<"channel_id"/utf8>>,
discord_gleam@discord@snowflake:decoder(
),
fun(
Channel_id
) ->
gleam@dynamic@decode:optional_field(
<<"member"/utf8>>,
none,
gleam@dynamic@decode:optional(
discord_gleam@types@guild_member:json_decoder(
)
),
fun(
Member
) ->
gleam@dynamic@decode:optional_field(
<<"user"/utf8>>,
none,
gleam@dynamic@decode:optional(
discord_gleam@types@user:json_decoder(
)
),
fun(
User
) ->
gleam@dynamic@decode:field(
<<"token"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
Token
) ->
gleam@dynamic@decode:optional_field(
<<"message"/utf8>>,
none,
gleam@dynamic@decode:optional(
discord_gleam@ws@packets@message:data_json_decoder(
)
),
fun(
Message
) ->
gleam@dynamic@decode:field(
<<"app_permissions"/utf8>>,
{decoder,
fun gleam@dynamic@decode:decode_string/1},
fun(
App_permissions
) ->
gleam@dynamic@decode:optional_field(
<<"locale"/utf8>>,
none,
gleam@dynamic@decode:optional(
{decoder,
fun gleam@dynamic@decode:decode_string/1}
),
fun(
Locale
) ->
gleam@dynamic@decode:success(
{interaction_create_packet_data,
Id,
Application_id,
Type_,
Data,
Guild_id,
Channel,
Channel_id,
Member,
User,
Token,
Message,
App_permissions,
Locale}
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end
)
end,
fun(D) ->
gleam@dynamic@decode:success(
{interaction_create_packet,
T,
S,
Op,
D}
)
end
)
end
)
end
)
end
)
end,
gleam@json:parse(Encoded, Decoder).