-module(discord_gleam@ws@commands@update_presence). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/discord_gleam/ws/commands/update_presence.gleam"). -export([playing/1, streaming/2, listening/1, watching/1, custom/1, competing/1, type_to_int/1, activity_to_json/1, status_to_string/1, to_json/1, update_presence/2]). -export_type([status/0, activity_type/0, activity/0, presence/0]). -type status() :: online | idle | do_not_disturb | invisible | offline. -type activity_type() :: playing | streaming | listening | watching | custom | competing. -type activity() :: {activity, activity_type(), binary(), gleam@option:option(binary()), gleam@option:option(binary())}. -type presence() :: {presence, status(), list(activity()), boolean(), gleam@option:option(integer())}. -file("src/discord_gleam/ws/commands/update_presence.gleam", 40). -spec playing(binary()) -> activity(). playing(Name) -> {activity, playing, Name, none, none}. -file("src/discord_gleam/ws/commands/update_presence.gleam", 44). -spec streaming(binary(), binary()) -> activity(). streaming(Name, Url) -> {activity, streaming, Name, {some, Url}, none}. -file("src/discord_gleam/ws/commands/update_presence.gleam", 48). -spec listening(binary()) -> activity(). listening(Name) -> {activity, listening, Name, none, none}. -file("src/discord_gleam/ws/commands/update_presence.gleam", 52). -spec watching(binary()) -> activity(). watching(Name) -> {activity, watching, Name, none, none}. -file("src/discord_gleam/ws/commands/update_presence.gleam", 56). -spec custom(binary()) -> activity(). custom(Text) -> {activity, custom, <<"Custom Activity"/utf8>>, none, {some, Text}}. -file("src/discord_gleam/ws/commands/update_presence.gleam", 60). -spec competing(binary()) -> activity(). competing(Name) -> {activity, competing, Name, none, none}. -file("src/discord_gleam/ws/commands/update_presence.gleam", 112). -spec type_to_int(activity_type()) -> integer(). type_to_int(Type_) -> case Type_ of playing -> 0; streaming -> 1; listening -> 2; watching -> 3; custom -> 4; competing -> 5 end. -file("src/discord_gleam/ws/commands/update_presence.gleam", 97). -spec activity_to_json(activity()) -> gleam@json:json(). activity_to_json(Activity) -> gleam@json:object( [{<<"name"/utf8>>, gleam@json:string(erlang:element(3, Activity))}, {<<"type"/utf8>>, gleam@json:int(type_to_int(erlang:element(2, Activity)))}, {<<"url"/utf8>>, case erlang:element(4, Activity) of none -> gleam@json:null(); {some, Url} -> gleam@json:string(Url) end}, {<<"state"/utf8>>, case erlang:element(5, Activity) of none -> gleam@json:null(); {some, State} -> gleam@json:string(State) end}] ). -file("src/discord_gleam/ws/commands/update_presence.gleam", 87). -spec status_to_string(status()) -> binary(). status_to_string(Status) -> case Status of online -> <<"online"/utf8>>; idle -> <<"idle"/utf8>>; do_not_disturb -> <<"dnd"/utf8>>; invisible -> <<"invisible"/utf8>>; offline -> <<"offline"/utf8>> end. -file("src/discord_gleam/ws/commands/update_presence.gleam", 75). -spec to_json(presence()) -> gleam@json:json(). to_json(Presence) -> gleam@json:object([{<<"since"/utf8>>, case erlang:element(5, Presence) of none -> gleam@json:null(); {some, S} -> gleam@json:int(S) end}, {<<"status"/utf8>>, gleam@json:string(status_to_string(erlang:element(2, Presence)))}, {<<"afk"/utf8>>, gleam@json:bool(erlang:element(4, Presence))}, {<<"activities"/utf8>>, gleam@json:array( erlang:element(3, Presence), fun activity_to_json/1 )}]). -file("src/discord_gleam/ws/commands/update_presence.gleam", 64). -spec update_presence(discord_gleam@bot:bot(), presence()) -> nil. update_presence(Bot, Presence) -> Packet = begin _pipe = gleam@json:object( [{<<"op"/utf8>>, gleam@json:int(3)}, {<<"d"/utf8>>, to_json(Presence)}] ), gleam@json:to_string(_pipe) end, discord_gleam@bot:send_packet(Bot, Packet).