From 62ccc1d229ee154854f2c568eaff9e435ddd59b8 Mon Sep 17 00:00:00 2001 From: axell Date: Fri, 5 Jul 2024 23:44:36 +0200 Subject: [PATCH] add user pfp small image thingy --- Bloxstrap/Integrations/DiscordRichPresence.cs | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/Bloxstrap/Integrations/DiscordRichPresence.cs b/Bloxstrap/Integrations/DiscordRichPresence.cs index ab920d1..4477c11 100644 --- a/Bloxstrap/Integrations/DiscordRichPresence.cs +++ b/Bloxstrap/Integrations/DiscordRichPresence.cs @@ -190,8 +190,12 @@ namespace Bloxstrap.Integrations } string icon = "roblox"; + string smallimagetext = "Roblox"; + string smallimage = "roblox"; + long placeId = _activityWatcher.ActivityPlaceId; - + string userId = _activityWatcher.ActivityUserId; + App.Logger.WriteLine(LOG_IDENT, $"Setting presence for Place ID {placeId}"); var universeIdResponse = await Http.GetJson($"https://apis.roblox.com/universes/v1/places/{placeId}/universe"); @@ -231,6 +235,34 @@ namespace Bloxstrap.Integrations App.Logger.WriteLine(LOG_IDENT, $"Got Universe thumbnail as {icon}"); } + //right now this is configured in a way so that it will only show your avatar and username if you have chosen to allow people to join you from their profile. + if (!App.Settings.Prop.HideRPCButtons) + { + var userPfpResponse = await Http.GetJson>($"https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds={userId}&size=180x180&format=Png&isCircular=false"); //we can remove '-headshot' from the url if we want a full avatar picture + if (userPfpResponse is null || !userPfpResponse.Data.Any()) + { + App.Logger.WriteLine(LOG_IDENT, "Could not get user thumbnail info!"); + } + else + { + smallimage = userPfpResponse.Data.ToArray()[0].ImageUrl; + App.Logger.WriteLine(LOG_IDENT, $"Got user thumbnail as {smallimage}"); + } + + var userInfoResponse = await Http.GetJson>($"https://users.roblox.com/v1/users/{userId}"); + if (userInfoResponse is null || !userInfoResponse.Data.Any()) + { + App.Logger.WriteLine(LOG_IDENT, "Could not get user info!"); + } + else + { + smallimagetext = userInfoResponse.Data.ToArray()[0].DisplayName + " (@{userInfoResponse.Data.ToArray()[0].Username})"; //example: john doe (@johndoe) + App.Logger.WriteLine(LOG_IDENT, $"Got user info as {smallimagetext}"); + } + + } + + List