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 15 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
21 changes: 19 additions & 2 deletions Bloxstrap/Integrations/ActivityWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class ActivityWatcher : IDisposable
private const string GameTeleportingEntry = "[FLog::SingleSurfaceApp] initiateTeleport";
private const string GameMessageEntry = "[FLog::Output] [BloxstrapRPC]";
private const string GameLeavingEntry = "[FLog::SingleSurfaceApp] leaveUGCGameInternal";

private const string GameJoinLoadTimeEntry = "[FLog::GameJoinLoadTime] Report game_join_loadtime:";
axellse marked this conversation as resolved.
Show resolved Hide resolved

private const string GameJoinLoadTimeEntryPattern = ", userid:([0-9]+)";
axellse marked this conversation as resolved.
Show resolved Hide resolved
private const string GameJoiningEntryPattern = @"! Joining game '([0-9a-f\-]{36})' place ([0-9]+) at ([0-9\.]+)";
private const string GameJoiningUDMUXPattern = @"UDMUX Address = ([0-9\.]+), Port = [0-9]+ \| RCC Server Address = ([0-9\.]+), Port = [0-9]+";
private const string GameJoinedEntryPattern = @"serverId: ([0-9\.]+)\|[0-9]+";
Expand All @@ -39,6 +41,7 @@ public class ActivityWatcher : IDisposable
public bool ActivityInGame = false;
public long ActivityPlaceId = 0;
public string ActivityJobId = "";
public string ActivityUserId = "";
public string ActivityMachineAddress = "";
public bool ActivityMachineUDMUX = false;
public bool ActivityIsTeleport = false;
Expand Down Expand Up @@ -143,6 +146,19 @@ private void ExamineLogEntry(string entry)
process.CloseMainWindow();
}

if (ActivityUserId == "" && 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;
}

ActivityUserId = match.Groups[1].Value;
}
if (!ActivityInGame && ActivityPlaceId == 0)
{
if (entry.Contains(GameJoiningPrivateServerEntry))
Expand Down Expand Up @@ -229,7 +245,8 @@ private void ExamineLogEntry(string entry)
ActivityMachineUDMUX = false;
ActivityIsTeleport = false;
ActivityServerType = ServerType.Public;

ActivityUserId = "";

OnGameLeave?.Invoke(this, new EventArgs());
}
else if (entry.Contains(GameTeleportingEntry))
Expand Down
35 changes: 32 additions & 3 deletions Bloxstrap/Integrations/DiscordRichPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ public async Task<bool> SetCurrentGame()
}

string icon = "roblox";
string smallimagetext = "Roblox";
axellse marked this conversation as resolved.
Show resolved Hide resolved
string smallimage = "roblox";
axellse marked this conversation as resolved.
Show resolved Hide resolved

long placeId = _activityWatcher.ActivityPlaceId;

string userId = _activityWatcher.ActivityUserId;

App.Logger.WriteLine(LOG_IDENT, $"Setting presence for Place ID {placeId}");

var universeIdResponse = await Http.GetJson<UniverseIdResponse>($"https://apis.roblox.com/universes/v1/places/{placeId}/universe");
Expand Down Expand Up @@ -231,6 +235,31 @@ public async Task<bool> SetCurrentGame()
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)
axellse marked this conversation as resolved.
Show resolved Hide resolved
{
var userPfpResponse = await Http.GetJson<ApiArrayResponse<ThumbnailResponse>>($"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<UserInfoResponse>($"https://users.roblox.com/v1/users/{userId}");
if (userInfoResponse is null)
{
App.Logger.WriteLine(LOG_IDENT, "Could not get user info!");
} else {
axellse marked this conversation as resolved.
Show resolved Hide resolved
smallimagetext = userInfoResponse.DisplayName + $" (@{userInfoResponse.Username})"; //example: john doe (@johndoe)
App.Logger.WriteLine(LOG_IDENT, $"Got user info as {smallimagetext}");
}
}


List<Button> buttons = new();

if (!App.Settings.Prop.HideRPCButtons && _activityWatcher.ActivityServerType == ServerType.Public)
Expand Down Expand Up @@ -274,8 +303,8 @@ public async Task<bool> SetCurrentGame()
{
LargeImageKey = icon,
LargeImageText = universeDetails.Name,
SmallImageKey = "roblox",
SmallImageText = "Roblox"
SmallImageKey = smallimage,
SmallImageText = smallimagetext
}
};

Expand Down
26 changes: 26 additions & 0 deletions Bloxstrap/Models/RobloxApi/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!;
}
}