From 0d36495cfca7d79a3b81f51550613f82a551823a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 15 Jun 2022 02:25:06 +0900 Subject: [PATCH] Fix up code quality, use more correct URL and update button text --- osu.Desktop/DiscordRichPresence.cs | 37 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/osu.Desktop/DiscordRichPresence.cs b/osu.Desktop/DiscordRichPresence.cs index 6700184e0b..27c6062bb3 100644 --- a/osu.Desktop/DiscordRichPresence.cs +++ b/osu.Desktop/DiscordRichPresence.cs @@ -9,6 +9,7 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Logging; +using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Extensions; using osu.Game.Online.API; @@ -102,11 +103,17 @@ private void updateStatus() presence.State = truncate(activity.Value.Status); presence.Details = truncate(getDetails(activity.Value)); - if (getOnlineID(activity.Value) != null) + if (getBeatmap(activity.Value) is IBeatmapInfo beatmap && beatmap.OnlineID > 0) { - presence.Buttons = new Button[] + string rulesetShortName = (activity.Value as UserActivity.InGame)?.Ruleset.ShortName ?? string.Empty; + + presence.Buttons = new[] { - new Button() { Label = "Open Beatmap", Url = $"https://osu.ppy.sh/b/{getOnlineID(activity.Value)}" } + new Button + { + Label = "View beatmap", + Url = $@"{api.WebsiteRootUrl}/beatmapsets/{beatmap.BeatmapSet?.OnlineID}#{rulesetShortName}/{beatmap.OnlineID}" + } }; } else @@ -159,6 +166,20 @@ private string truncate(string str) }); } + private IBeatmapInfo getBeatmap(UserActivity activity) + { + switch (activity) + { + case UserActivity.InGame game: + return game.BeatmapInfo; + + case UserActivity.Editing edit: + return edit.BeatmapInfo; + } + + return null; + } + private string getDetails(UserActivity activity) { switch (activity) @@ -176,16 +197,6 @@ private string getDetails(UserActivity activity) return string.Empty; } - private int? getOnlineID(UserActivity activity) - { - if (activity is UserActivity.InGame game && game.BeatmapInfo.OnlineID > 0) - { - return game.BeatmapInfo.OnlineID; - } - - return null; - } - protected override void Dispose(bool isDisposing) { client.Dispose();