Skip to content

Commit

Permalink
Finish up on Axell's work
Browse files Browse the repository at this point in the history
caching, better presentation, etc
  • Loading branch information
pizzaboxer committed Sep 29, 2024
1 parent 55f5ef4 commit 43ab562
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 77 deletions.
2 changes: 2 additions & 0 deletions Bloxstrap/GlobalCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public static class GlobalCache
{
public static readonly Dictionary<string, string?> ServerLocation = new();

public static readonly Dictionary<long, ThumbnailResponse> UserThumbnails = new();
}
}
2 changes: 1 addition & 1 deletion Bloxstrap/Integrations/ActivityWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private void ReadLogEntry(string entry)
return;
}

if (!UInt64.TryParse(match.Groups[1].Value, out ulong result))
if (!Int64.TryParse(match.Groups[1].Value, out long result))
{
App.Logger.WriteLine(LOG_IDENT, "Failed to parse userid from game join load time entry");
App.Logger.WriteLine(LOG_IDENT, match.Groups[1].Value);
Expand Down
27 changes: 5 additions & 22 deletions Bloxstrap/Integrations/DiscordRichPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,29 +227,12 @@ public async Task<bool> SetCurrentGame()

icon = universeDetails.Thumbnail.ImageUrl;

if (App.Settings.Prop.AccountShownOnProfile)
if (App.Settings.Prop.ShowAccountOnRichPresence)
{
var userPfpResponse = await Http.GetJson<ApiArrayResponse<ThumbnailResponse>>($"https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds={activity.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.First().ImageUrl;
App.Logger.WriteLine(LOG_IDENT, $"Got user thumbnail as {smallImage}");
}

var userInfoResponse = await Http.GetJson<UserInfoResponse>($"https://users.roblox.com/v1/users/{activity.UserId}");
if (userInfoResponse is null)
{
App.Logger.WriteLine(LOG_IDENT, "Could not get user info!");
}
else
{
smallImageText = userInfoResponse.DisplayName + $" (@{userInfoResponse.Username})"; //example: john doe (@johndoe)
App.Logger.WriteLine(LOG_IDENT, $"Got user info as {smallImageText}");
}
var userDetails = await UserDetails.Fetch(activity.UserId);

smallImage = userDetails.Thumbnail.ImageUrl;
smallImageText = $"Playing on {userDetails.Data.DisplayName} (@{userDetails.Data.Name})"; // i.e. "axell (@Axelan_se)"
}

if (!_activityWatcher.InGame || placeId != activity.PlaceId)
Expand Down
56 changes: 56 additions & 0 deletions Bloxstrap/Models/APIs/Roblox/GetUserResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Bloxstrap.Models.RobloxApi
{
/// <summary>
/// Roblox.Users.Api.GetUserResponse
/// </summary>
public class GetUserResponse
{
/// <summary>
/// The user description.
/// </summary>
[JsonPropertyName("description")]
public string Description { get; set; } = null!;

/// <summary>
/// When the user signed up.
/// </summary>
[JsonPropertyName("created")]
public DateTime Created { get; set; }

/// <summary>
/// Whether the user is banned
/// </summary>
[JsonPropertyName("isBanned")]
public bool IsBanned { get; set; }

/// <summary>
/// Unused, legacy attribute… rely on its existence.
/// </summary>
[JsonPropertyName("externalAppDisplayName")]
public string ExternalAppDisplayName { get; set; } = null!;

/// <summary>
/// The user's verified badge status.
/// </summary>
[JsonPropertyName("hasVerifiedBadge")]
public bool HasVerifiedBadge { get; set; }

/// <summary>
/// The user Id.
/// </summary>
[JsonPropertyName("id")]
public long Id { get; set; }

/// <summary>
/// The user name.
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; } = null!;

/// <summary>
/// The user DisplayName.
/// </summary>
[JsonPropertyName("displayName")]
public string DisplayName { get; set; } = null!;
}
}
26 changes: 0 additions & 26 deletions Bloxstrap/Models/APIs/Roblox/UserInfoResponse.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Bloxstrap/Models/Entities/ActivityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public long UniverseId
/// </summary>
public string AccessCode { get; set; } = string.Empty;

public ulong UserId { get; set; } = 0;
public long UserId { get; set; } = 0;

public string MachineAddress { get; set; } = string.Empty;

Expand Down
7 changes: 4 additions & 3 deletions Bloxstrap/Models/Entities/UniverseDetails.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Bloxstrap.Models.APIs.Roblox;

namespace Bloxstrap.Models.Entities
namespace Bloxstrap.Models.Entities
{
/// <summary>
/// Explicit loading. Load from cache before and after a fetch.
/// </summary>
public class UniverseDetails
{
private static List<UniverseDetails> _cache { get; set; } = new();
Expand Down
42 changes: 42 additions & 0 deletions Bloxstrap/Models/Entities/UserDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Bloxstrap.Models.RobloxApi;

namespace Bloxstrap.Models.Entities
{
public class UserDetails
{
private static List<UserDetails> _cache { get; set; } = new();

public GetUserResponse Data { get; set; } = null!;

public ThumbnailResponse Thumbnail { get; set; } = null!;

public static async Task<UserDetails> Fetch(long id)
{
var cacheQuery = _cache.Where(x => x.Data?.Id == id);

if (cacheQuery.Any())
return cacheQuery.First();

var userResponse = await Http.GetJson<GetUserResponse>($"https://users.roblox.com/v1/users/{id}");

if (userResponse is null)
throw new InvalidHTTPResponseException("Roblox API for User Details returned invalid data");

// we can remove '-headshot' from the url if we want a full avatar picture
var thumbnailResponse = await Http.GetJson<ApiArrayResponse<ThumbnailResponse>>($"https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds={id}&size=180x180&format=Png&isCircular=false");

if (thumbnailResponse is null || !thumbnailResponse.Data.Any())
throw new InvalidHTTPResponseException("Roblox API for Thumbnails returned invalid data");

var details = new UserDetails
{
Data = userResponse,
Thumbnail = thumbnailResponse.Data.First()
};

_cache.Add(details);

return details;
}
}
}
2 changes: 1 addition & 1 deletion Bloxstrap/Models/Persistable/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Settings
public bool EnableActivityTracking { get; set; } = true;
public bool UseDiscordRichPresence { get; set; } = true;
public bool HideRPCButtons { get; set; } = true;
public bool AccountShownOnProfile { get; set; } = true;
public bool ShowAccountOnRichPresence { get; set; } = false;
public bool ShowServerDetails { get; set; } = false;
public ObservableCollection<CustomIntegration> CustomIntegrations { get; set; } = new();

Expand Down
36 changes: 18 additions & 18 deletions Bloxstrap/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,10 @@ Selecting 'No' will ignore this warning and continue installation.</value>
<value>Allow activity joining</value>
</data>
<data name="Menu.Integrations.ShowAccountOnProfile.Description" xml:space="preserve">
<value>Shows which Roblox account you are using on your Discord profile.</value>
<value>Shows the Roblox account you're playing with on your Discord profile.</value>
</data>
<data name="Menu.Integrations.ShowAccountOnProfile.Title" xml:space="preserve">
<value>Show account on profile</value>
<value>Show Roblox account</value>
</data>
<data name="Menu.Integrations.Custom.AppLocation" xml:space="preserve">
<value>Application Location</value>
Expand Down
3 changes: 2 additions & 1 deletion Bloxstrap/UI/Elements/About/Pages/AboutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<controls:MarkdownTextBlock MarkdownText="[fxeP1](https://github.com/fxeP1)" />
<controls:MarkdownTextBlock MarkdownText="[Redusofficial](https://github.com/Redusofficial)" />
<controls:MarkdownTextBlock MarkdownText="[srthMD](https://github.com/srthMD)" />
<controls:MarkdownTextBlock MarkdownText="[axellse](https://github.com/axellse)" />
</StackPanel>
</controls:Expander>

Expand Down Expand Up @@ -133,7 +134,7 @@
<controls:MarkdownTextBlock MarkdownText="[MaximumADHD](https://github.com/MaximumADHD)" />
<controls:MarkdownTextBlock MarkdownText="[Multako](https://www.roblox.com/users/2485612194/profile)" />
<controls:MarkdownTextBlock MarkdownText="[axstin](https://github.com/axstin)" />
<controls:MarkdownTextBlock MarkdownText="[taskmanager](https://github.com/Mantaraix)" />
<controls:MarkdownTextBlock MarkdownText="[Mantaraix](https://github.com/Mantaraix)" />
<controls:MarkdownTextBlock MarkdownText="[apprehensions](https://github.com/apprehensions)" />
</StackPanel>
</controls:Expander>
Expand Down
4 changes: 2 additions & 2 deletions Bloxstrap/UI/ViewModels/Settings/IntegrationsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public bool DiscordActivityJoinEnabled

public bool DiscordAccountOnProfile
{
get => App.Settings.Prop.AccountShownOnProfile;
set => App.Settings.Prop.AccountShownOnProfile = value;
get => App.Settings.Prop.ShowAccountOnRichPresence;
set => App.Settings.Prop.ShowAccountOnRichPresence = value;
}

public bool DisableAppPatchEnabled
Expand Down

0 comments on commit 43ab562

Please sign in to comment.