Discord rpc fixes

This commit is contained in:
fed 2023-12-19 02:31:23 +01:00
parent aef84a037e
commit 50ca5bc5c9
No known key found for this signature in database
GPG Key ID: 1D2C630F04722996
5 changed files with 46 additions and 10 deletions

2
.gitmodules vendored
View File

@ -12,7 +12,7 @@
url = https://github.com/TsudaKageyu/minhook.git url = https://github.com/TsudaKageyu/minhook.git
[submodule "deps/discord-rpc"] [submodule "deps/discord-rpc"]
path = deps/discord-rpc path = deps/discord-rpc
url = https://github.com/discord/discord-rpc.git url = https://github.com/fedddddd/discord-rpc.git
[submodule "deps/asmjit"] [submodule "deps/asmjit"]
path = deps/asmjit path = deps/asmjit
url = https://github.com/asmjit/asmjit.git url = https://github.com/asmjit/asmjit.git

View File

@ -135,12 +135,7 @@ function addrequest(request)
font = CoD.TextSettings.BodyFontBold.Font font = CoD.TextSettings.BodyFontBold.Font
}) })
local requesttext = nil local requesttext = Engine.Localize("LUA_MENU_DISCORD_REQUEST", truncatename(request.displayname, 18))
if (request.discriminator == "0") then
requesttext = Engine.Localize("LUA_MENU_DISCORD_REQUEST", truncatename(request.username, 18))
else
requesttext = Engine.Localize("LUA_MENU_DISCORD_REQUEST_DISCRIMINATOR", truncatename(request.username, 18), request.discriminator)
end
username:setText(requesttext) username:setText(requesttext)
@ -178,8 +173,8 @@ function addrequest(request)
return button return button
end end
local accepttext = Engine.Localize("LUA_MENU_DISCORD_ACCEPT", Engine.GetBinding("discord_accept")) local accepttext = Engine.Localize("LUA_MENU_DISCORD_ACCEPT", game:getcommandbind("discord_accept"))
local denytext = Engine.Localize("LUA_MENU_DISCORD_DENY", Engine.GetBinding("discord_deny")) local denytext = Engine.Localize("LUA_MENU_DISCORD_DENY", game:getcommandbind("discord_deny"))
buttons:addElement(createbutton(accepttext, true)) buttons:addElement(createbutton(accepttext, true))
buttons:addElement(createbutton(denytext)) buttons:addElement(createbutton(denytext))

2
deps/discord-rpc vendored

@ -1 +1 @@
Subproject commit 963aa9f3e5ce81a4682c6ca3d136cddda614db33 Subproject commit b3383798b353c31ea6770fee673740c27f6e3489

View File

@ -267,6 +267,22 @@ namespace discord
}, scheduler::pipeline::main); }, scheduler::pipeline::main);
} }
std::string get_display_name(const DiscordUser* user)
{
if (user->discriminator != nullptr && user->discriminator != "0"s)
{
return std::format("{}#{}", user->username, user->discriminator);
}
else if (user->globalName[0] != 0)
{
return user->globalName;
}
else
{
return user->username;
}
}
void join_request(const DiscordUser* request) void join_request(const DiscordUser* request)
{ {
console::debug("Discord: Join request from %s (%s)\n", request->username, request->userId); console::debug("Discord: Join request from %s (%s)\n", request->username, request->userId);
@ -283,6 +299,7 @@ namespace discord
const std::string avatar = request->avatar; const std::string avatar = request->avatar;
const std::string discriminator = request->discriminator; const std::string discriminator = request->discriminator;
const std::string username = request->username; const std::string username = request->username;
const auto display_name = get_display_name(request);
const auto now = std::chrono::high_resolution_clock::now(); const auto now = std::chrono::high_resolution_clock::now();
auto iter = last_requests.find(user_id); auto iter = last_requests.find(user_id);
@ -309,6 +326,7 @@ namespace discord
request_table.set("discriminator", discriminator); request_table.set("discriminator", discriminator);
request_table.set("userid", user_id); request_table.set("userid", user_id);
request_table.set("username", username); request_table.set("username", username);
request_table.set("displayname", display_name);
ui_scripting::notify("discord_join_request", ui_scripting::notify("discord_join_request",
{ {

View File

@ -335,6 +335,29 @@ namespace ui_scripting
material.data())); material.data()));
}; };
game_type["getcommandbind"] = [](const game&, const std::string& cmd)
{
const auto binding = ::game::Key_GetBindingForCmd(cmd.data());
auto key = -1;
for (auto i = 0; i < 256; i++)
{
if (::game::playerKeys[0].keys[i].binding == binding)
{
key = i;
}
}
if (key == -1)
{
return ::game::UI_SafeTranslateString("KEY_UNBOUND");
}
else
{
const auto loc_string = ::game::Key_KeynumToString(key, 1, 0);
return ::game::UI_SafeTranslateString(loc_string);
}
};
auto server_list_table = table(); auto server_list_table = table();
lua["serverlist"] = server_list_table; lua["serverlist"] = server_list_table;