[skip ci] feat: prepare for public release
This commit is contained in:
@@ -48,6 +48,7 @@ error_code(voice_token_failed) -> <<"VOICE_TOKEN_FAILED">>;
|
||||
error_code(voice_guild_id_missing) -> <<"VOICE_GUILD_ID_MISSING">>;
|
||||
error_code(voice_invalid_guild_id) -> <<"VOICE_INVALID_GUILD_ID">>;
|
||||
error_code(voice_moderator_missing_connect) -> <<"VOICE_PERMISSION_DENIED">>;
|
||||
error_code(voice_unclaimed_account) -> <<"VOICE_UNCLAIMED_ACCOUNT">>;
|
||||
error_code(dm_channel_not_found) -> <<"DM_CHANNEL_NOT_FOUND">>;
|
||||
error_code(dm_not_recipient) -> <<"DM_NOT_RECIPIENT">>;
|
||||
error_code(dm_invalid_channel_type) -> <<"DM_INVALID_CHANNEL_TYPE">>;
|
||||
@@ -82,6 +83,7 @@ error_message(voice_token_failed) -> <<"Failed to obtain voice token">>;
|
||||
error_message(voice_guild_id_missing) -> <<"Guild ID is required">>;
|
||||
error_message(voice_invalid_guild_id) -> <<"Invalid guild ID">>;
|
||||
error_message(voice_moderator_missing_connect) -> <<"Moderator missing connect permission">>;
|
||||
error_message(voice_unclaimed_account) -> <<"Claim your account to join voice">>;
|
||||
error_message(dm_channel_not_found) -> <<"DM channel not found">>;
|
||||
error_message(dm_not_recipient) -> <<"Not a recipient of this channel">>;
|
||||
error_message(dm_invalid_channel_type) -> <<"Not a DM or Group DM channel">>;
|
||||
@@ -116,6 +118,7 @@ error_category(voice_token_failed) -> voice_error;
|
||||
error_category(voice_guild_id_missing) -> validation_error;
|
||||
error_category(voice_invalid_guild_id) -> validation_error;
|
||||
error_category(voice_moderator_missing_connect) -> permission_denied;
|
||||
error_category(voice_unclaimed_account) -> permission_denied;
|
||||
error_category(dm_channel_not_found) -> not_found;
|
||||
error_category(dm_not_recipient) -> permission_denied;
|
||||
error_category(dm_invalid_channel_type) -> validation_error;
|
||||
|
||||
@@ -346,7 +346,14 @@ get_voice_token(ChannelId, UserId, _SessionId, SessionPid, Latitude, Longitude)
|
||||
connection_id => ConnectionId
|
||||
}},
|
||||
ok;
|
||||
{error, {http_error, _Status, Body}} ->
|
||||
case parse_unclaimed_error(Body) of
|
||||
true -> SessionPid ! {voice_error, voice_unclaimed_account};
|
||||
false -> SessionPid ! {voice_error, voice_token_failed}
|
||||
end,
|
||||
error;
|
||||
{error, _Reason} ->
|
||||
SessionPid ! {voice_error, voice_token_failed},
|
||||
error
|
||||
end.
|
||||
|
||||
@@ -383,6 +390,11 @@ get_dm_voice_token_and_create_state(
|
||||
IsMobile,
|
||||
State
|
||||
);
|
||||
{error, {http_error, _Status, Body}} ->
|
||||
case parse_unclaimed_error(Body) of
|
||||
true -> {reply, gateway_errors:error(voice_unclaimed_account), State};
|
||||
false -> {reply, gateway_errors:error(voice_token_failed), State}
|
||||
end;
|
||||
{error, _Reason} ->
|
||||
{reply, gateway_errors:error(voice_token_failed), State}
|
||||
end.
|
||||
@@ -501,6 +513,17 @@ disconnect_voice_user(UserId, State) ->
|
||||
{reply, #{success => true}, NewState}
|
||||
end.
|
||||
|
||||
parse_unclaimed_error(Body) when is_binary(Body) ->
|
||||
try jsx:decode(Body, [return_maps]) of
|
||||
#{<<"code">> := <<"UNCLAIMED_ACCOUNT_RESTRICTED">>} -> true;
|
||||
#{<<"error">> := #{<<"code">> := <<"UNCLAIMED_ACCOUNT_RESTRICTED">>}} -> true;
|
||||
_ -> false
|
||||
catch
|
||||
_:_ -> false
|
||||
end;
|
||||
parse_unclaimed_error(_) ->
|
||||
false.
|
||||
|
||||
broadcast_voice_state_update(ChannelId, VoiceState, State) ->
|
||||
Channels = maps:get(channels, State, #{}),
|
||||
|
||||
|
||||
@@ -644,11 +644,33 @@ request_voice_token(GuildId, ChannelId, UserId, VoicePermissions) ->
|
||||
endpoint => maps:get(<<"endpoint">>, Data),
|
||||
connection_id => maps:get(<<"connectionId">>, Data)
|
||||
}};
|
||||
{error, {http_error, _Status, Body}} ->
|
||||
case parse_unclaimed_error(Body) of
|
||||
true ->
|
||||
{error, voice_unclaimed_account};
|
||||
false ->
|
||||
logger:error("[guild_voice_connection] RPC request failed: ~p", [{http_error, Body}]),
|
||||
{error, voice_token_failed}
|
||||
end;
|
||||
{error, Reason} ->
|
||||
logger:error("[guild_voice_connection] RPC request failed: ~p", [Reason]),
|
||||
{error, Reason}
|
||||
{error, voice_token_failed}
|
||||
end.
|
||||
|
||||
parse_unclaimed_error(Body) when is_binary(Body) ->
|
||||
try jsx:decode(Body, [return_maps]) of
|
||||
#{<<"code">> := <<"UNCLAIMED_ACCOUNT_RESTRICTED">>} ->
|
||||
true;
|
||||
#{<<"error">> := #{<<"code">> := <<"UNCLAIMED_ACCOUNT_RESTRICTED">>}} ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
catch
|
||||
_:_ -> false
|
||||
end;
|
||||
parse_unclaimed_error(_) ->
|
||||
false.
|
||||
|
||||
-spec pending_voice_connections(guild_state()) -> pending_voice_connections().
|
||||
pending_voice_connections(State) ->
|
||||
case maps:get(pending_voice_connections, State, undefined) of
|
||||
|
||||
@@ -121,10 +121,6 @@ handle_call(_Request, _From, State) ->
|
||||
{reply, ok, State}.
|
||||
|
||||
handle_cast({handle_message_create, Params}, State) ->
|
||||
ParamMap = case Params of Maps when is_map(Maps) -> Maps; _ -> #{} end,
|
||||
GuildId = maps:get(<<"guild_id">>, ParamMap, undefined),
|
||||
ChannelId = maps:get(<<"channel_id">>, ParamMap, undefined),
|
||||
MessageId = maps:get(<<"id">>, ParamMap, undefined),
|
||||
{noreply, do_handle_message_create(Params, State)};
|
||||
handle_cast({sync_user_guild_settings, UserId, GuildId, UserGuildSettings}, State) ->
|
||||
#{
|
||||
|
||||
@@ -89,7 +89,7 @@ fetch_and_cache_user_guild_settings(UserId, GuildId, _State) ->
|
||||
),
|
||||
Settings
|
||||
end;
|
||||
{error, Reason} ->
|
||||
{error, _Reason} ->
|
||||
null
|
||||
end.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user