bloxstrap/Bloxstrap/Helpers/Integrations/DiscordRichPresence.cs
pizzaboxer 92b159d682 Updates and bugfixes for v1.3.0
- Features
    - Added integration with rbxfpsunlocker
    - Added support for user-applicable mods
    - Added ability to disable auto-update checking

 - Misc
    - Removed Bloxstrap branding from Discord Rich Presence
    - Mod presets for old death sound and mouse cursor are now statically stored as base64 strings, eliminating reliance on the website and the old cursors still existing

 - Bugfixes
    - Fixed vista bootstrapper style not hiding properly and improper behavior when closed
    - Fixed forms not being brought to the front when shown

 - Code
    - Reconsolidated Bootstrapper to a single file, using regions instead of partials
2022-08-21 22:41:16 +01:00

75 lines
1.8 KiB
C#

using Newtonsoft.Json.Linq;
using DiscordRPC;
namespace Bloxstrap.Helpers.Integrations
{
internal class DiscordRichPresence : IDisposable
{
readonly DiscordRpcClient RichPresence = new("1005469189907173486");
public async Task<bool> SetPresence(string placeId)
{
string placeName;
string placeThumbnail;
string creatorName;
// null checking could probably be a lot more concrete here
JObject placeInfo = await Utilities.GetJson($"https://economy.roblox.com/v2/assets/{placeId}/details");
placeName = placeInfo["Name"].Value<string>();
creatorName = placeInfo["Creator"]["Name"].Value<string>();
JObject thumbnailInfo = await Utilities.GetJson($"https://thumbnails.roblox.com/v1/places/gameicons?placeIds={placeId}&returnPolicy=PlaceHolder&size=512x512&format=Png&isCircular=false");
if (thumbnailInfo["data"] is null)
return false;
placeThumbnail = thumbnailInfo["data"][0]["imageUrl"].Value<string>();
DiscordRPC.Button[]? buttons = null;
if (!Program.Settings.HideRPCButtons)
{
buttons = new DiscordRPC.Button[]
{
new DiscordRPC.Button()
{
Label = "Play",
Url = $"https://www.roblox.com/games/start?placeId={placeId}&launchData=%7B%7D"
},
new DiscordRPC.Button()
{
Label = "View Details",
Url = $"https://www.roblox.com/games/{placeId}"
}
};
}
RichPresence.Initialize();
RichPresence.SetPresence(new RichPresence()
{
Details = placeName,
State = $"by {creatorName}",
Timestamps = new Timestamps() { Start = DateTime.UtcNow },
Buttons = buttons,
Assets = new Assets()
{
LargeImageKey = placeThumbnail,
LargeImageText = placeName,
SmallImageKey = "roblox",
SmallImageText = "Roblox"
}
});
return true;
}
public void Dispose()
{
RichPresence.Dispose();
}
}
}