Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show account on discord rich presence #2255

Merged
merged 49 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8656d9d
add functionality for grabbing userid
axellse Jul 5, 2024
4acab17
Create UserInfoResponse.cs
axellse Jul 5, 2024
62ccc1d
add user pfp small image thingy
axellse Jul 5, 2024
7005b44
add missing semicolons
axellse Jul 5, 2024
6b7f08b
get rid of semicolons
axellse Jul 6, 2024
9397ebe
debugging (remove later)
axellse Jul 6, 2024
e3cfbef
make properties nullable
axellse Jul 6, 2024
8f4117c
forgot to put dollar sign before interpolated string
axellse Jul 6, 2024
0c24753
make properties that cant be nullable not nullable
axellse Jul 6, 2024
acfd8ad
more debugging
axellse Jul 6, 2024
95e58d2
remove thing
axellse Jul 6, 2024
aac398e
remove other thing
axellse Jul 6, 2024
adc962f
remove thing (again) (again)
axellse Jul 6, 2024
2efb5fa
remove thing (again) (again) (again)
axellse Jul 6, 2024
0715cc0
add space between username and displayname to make it more visually p…
axellse Jul 6, 2024
2d41955
matt review changes (better code readability)
axellse Jul 6, 2024
1ce3879
add strings for show account on profile
axellse Jul 6, 2024
fffcbe2
add AccountShownOnProfile setting
axellse Jul 6, 2024
7b019d0
add DiscordActivityJoinEnabled to integrations viewmodel
axellse Jul 6, 2024
7cda0fb
fix accidentally swapping 2 variables
axellse Jul 6, 2024
36a6793
refrence correct variables
axellse Jul 6, 2024
3871f7a
refrence correct variables (again)
axellse Jul 6, 2024
97be636
add showaccountonprofile strings
axellse Jul 6, 2024
7aa5fc2
add option to integrations page
axellse Jul 6, 2024
1305ebe
add missing < that somehow got lost
axellse Jul 6, 2024
d6bc33d
make that its own option
axellse Jul 6, 2024
f07f1c1
dont invert that value
axellse Jul 6, 2024
04c67ea
dont invert that (again)
axellse Jul 6, 2024
e854b20
Update IntegrationsViewModel.cs
axellse Jul 6, 2024
63831dd
fix grammatical issue in string
axellse Jul 6, 2024
6b71aea
move else to new line
axellse Jul 8, 2024
2920955
Merge branch 'main' into user-pfp-discord-rpc
axellse Jul 29, 2024
11c9ae1
fix merge conflicts
axellse Aug 11, 2024
7c9c3d3
Merge branch 'main' into user-pfp-discord-rpc
axellse Aug 14, 2024
11b11e0
Merge branch 'main' into user-pfp-discord-rpc
axellse Aug 19, 2024
5d5726b
Merge branch 'main' into user-pfp-discord-rpc
axellse Aug 29, 2024
b61adf1
Merge branch 'main' into user-pfp-discord-rpc
axellse Aug 30, 2024
77262dc
Merge branch 'main' into user-pfp-discord-rpc
axellse Sep 3, 2024
abb08f1
Merge branch 'main' into user-pfp-discord-rpc
axellse Sep 3, 2024
e023fa4
fix merge conflicts
axellse Sep 4, 2024
3510730
Merge branch 'main' into user-pfp-discord-rpc
axellse Sep 4, 2024
cad4ba7
move gameJoinLoadTime check
axellse Sep 4, 2024
188242f
Merge branch 'user-pfp-discord-rpc' of https://github.com/axellse/blo…
axellse Sep 4, 2024
3855ac6
Merge branch 'main' into user-pfp-discord-rpc
axellse Sep 5, 2024
530bb84
Merge remote-tracking branch 'real/main' into user-pfp-discord-rpc
axellse Sep 21, 2024
5ff1901
matt review changes
axellse Sep 21, 2024
cf11cd8
Merge branch 'main' into user-pfp-discord-rpc
axellse Sep 21, 2024
8667167
handle if parsing userid fails
axellse Sep 22, 2024
5d79a95
Merge branch 'main' into user-pfp-discord-rpc
pizzaboxer Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Bloxstrap/Integrations/ActivityWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class ActivityWatcher : IDisposable
private const string GameDisconnectedEntry = "[FLog::Network] Time to disconnect replication data:";
private const string GameTeleportingEntry = "[FLog::SingleSurfaceApp] initiateTeleport";
private const string GameLeavingEntry = "[FLog::SingleSurfaceApp] leaveUGCGameInternal";
private const string GameJoinLoadTimeEntry = "[FLog::GameJoinLoadTime] Report game_join_loadtime:";

private const string GameJoinLoadTimeEntryPattern = ", userid:([0-9]+)";
private const string GameJoiningEntryPattern = @"! Joining game '([0-9a-f\-]{36})' place ([0-9]+) at ([0-9\.]+)";
private const string GameJoiningPrivateServerPattern = @"""accessCode"":""([0-9a-f\-]{36})""";
private const string GameJoiningUniversePattern = @"universeid:([0-9]+)";
Expand Down Expand Up @@ -153,7 +155,7 @@ private void ReadLogEntry(string entry)
if (!InGame && Data.PlaceId == 0)
{
// We are not in a game, nor are in the process of joining one

if (entry.Contains(GameJoiningPrivateServerEntry))
{
// we only expect to be joining a private server if we're not already in a game
Expand Down Expand Up @@ -209,6 +211,28 @@ private void ReadLogEntry(string entry)
{
// We are not confirmed to be in a game, but we are in the process of joining one

if (entry.Contains(GameJoinLoadTimeEntry))
{
Match match = Regex.Match(entry, GameJoinLoadTimeEntryPattern);

if (match.Groups.Count != 2)
{
App.Logger.WriteLine(LOG_IDENT, "Failed to assert format for game join load time entry");
App.Logger.WriteLine(LOG_IDENT, entry);
return;
}

if (!UInt64.TryParse(match.Groups[1].Value, out ulong 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);
return;
}

Data.UserId = result;
App.Logger.WriteLine(LOG_IDENT, $"Got userid as {Data.UserId}");
}

if (entry.Contains(GameJoiningUniverseEntry))
{
var match = Regex.Match(entry, GameJoiningUniversePattern);
Expand Down Expand Up @@ -279,7 +303,6 @@ private void ReadLogEntry(string entry)
History.Insert(0, Data);

InGame = false;

Data = new();

OnGameLeave?.Invoke(this, new EventArgs());
Expand Down
38 changes: 33 additions & 5 deletions Bloxstrap/Integrations/DiscordRichPresence.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Windows;

using System.Windows;
using Bloxstrap.Models.RobloxApi;
using DiscordRPC;

namespace Bloxstrap.Integrations
Expand Down Expand Up @@ -192,6 +192,9 @@ public async Task<bool> SetCurrentGame()
}

string icon = "roblox";
string smallImageText = "Roblox";
string smallImage = "roblox";


var activity = _activityWatcher.Data;
long placeId = activity.PlaceId;
Expand Down Expand Up @@ -224,6 +227,31 @@ public async Task<bool> SetCurrentGame()

icon = universeDetails.Thumbnail.ImageUrl;

if (App.Settings.Prop.AccountShownOnProfile)
{
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}");
}
}

if (!_activityWatcher.InGame || placeId != activity.PlaceId)
{
App.Logger.WriteLine(LOG_IDENT, "Aborting presence set because game activity has changed");
Expand Down Expand Up @@ -251,9 +279,9 @@ public async Task<bool> SetCurrentGame()
Assets = new Assets
{
LargeImageKey = icon,
LargeImageText = universeName,
SmallImageKey = "roblox",
SmallImageText = "Roblox"
LargeImageText = universeDetails.Data.Name,
SmallImageKey = smallImage,
SmallImageText = smallImageText
}
};

Expand Down
26 changes: 26 additions & 0 deletions Bloxstrap/Models/APIs/Roblox/UserInfoResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Bloxstrap.Models.RobloxApi
{
/// <summary>
/// Roblox.Web.Responses.Users.UserInfoResponse
/// </summary>
public class UserInfoResponse
{
[JsonPropertyName("description")]
public string ProfileDescription { get; set; } = null!;

[JsonPropertyName("created")]
public string JoinDate { get; set; } = null!;

[JsonPropertyName("isBanned")]
public bool IsBanned { get; set; }

[JsonPropertyName("hasVerifiedBadge")]
public bool HasVerifiedBadge { get; set; }

[JsonPropertyName("name")]
public string Username { get; set; } = null!;

[JsonPropertyName("displayName")]
public string DisplayName { get; set; } = null!;
}
}
2 changes: 2 additions & 0 deletions Bloxstrap/Models/Entities/ActivityData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public long UniverseId
/// This will be empty unless the server joined is a private server
/// </summary>
public string AccessCode { get; set; } = string.Empty;

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

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

Expand Down
1 change: 1 addition & 0 deletions Bloxstrap/Models/Persistable/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +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 ShowServerDetails { get; set; } = false;
public ObservableCollection<CustomIntegration> CustomIntegrations { get; set; } = new();

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

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

6 changes: 6 additions & 0 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,12 @@ Selecting 'No' will ignore this warning and continue installation.</value>
<data name="Menu.Integrations.AllowActivityJoining.Title" xml:space="preserve">
<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>
</data>
<data name="Menu.Integrations.ShowAccountOnProfile.Title" xml:space="preserve">
<value>Show account on profile</value>
</data>
<data name="Menu.Integrations.Custom.AppLocation" xml:space="preserve">
<value>Application Location</value>
</data>
Expand Down
7 changes: 7 additions & 0 deletions Bloxstrap/UI/Elements/Settings/Pages/IntegrationsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
<ui:ToggleSwitch IsChecked="{Binding DiscordActivityJoinEnabled, Mode=TwoWay}" />
</controls:OptionControl>

<controls:OptionControl
Header="{x:Static resources:Strings.Menu_Integrations_ShowAccountOnProfile_Title}"
Description="{x:Static resources:Strings.Menu_Integrations_ShowAccountOnProfile_Description}"
IsEnabled="{Binding InnerContent.IsChecked, ElementName=DiscordActivityOption, Mode=OneWay}">
<ui:ToggleSwitch IsChecked="{Binding DiscordAccountOnProfile, Mode=TwoWay}" />
</controls:OptionControl>

<TextBlock Text="{x:Static resources:Strings.Menu_Integrations_Custom_Title}" FontSize="20" FontWeight="Medium" Margin="0,16,0,0" />
<TextBlock Text="{x:Static resources:Strings.Menu_Integrations_Custom_Description}" TextWrapping="Wrap" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<Grid Margin="0,8,0,0">
Expand Down
8 changes: 8 additions & 0 deletions Bloxstrap/UI/ViewModels/Settings/IntegrationsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public bool DiscordActivityEnabled
if (!value)
{
DiscordActivityJoinEnabled = value;
DiscordAccountOnProfile = value;
OnPropertyChanged(nameof(DiscordActivityJoinEnabled));
OnPropertyChanged(nameof(DiscordAccountOnProfile));
}
}
}
Expand All @@ -111,6 +113,12 @@ public bool DiscordActivityJoinEnabled
set => App.Settings.Prop.HideRPCButtons = !value;
}

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

public bool DisableAppPatchEnabled
{
get => App.Settings.Prop.UseDisableAppPatch;
Expand Down