From 85d5fea9fde3f12a90423ac75d27d9b2c20dc2a6 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 25 Jun 2024 15:19:27 +0200 Subject: [PATCH] Improved Rich Presence messages --- .../EliteDangerousApiDiscordRichPresence.cs | 85 +++++++++++++++++-- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/Discord/EliteAPI.Discord/EliteDangerousApiDiscordRichPresence.cs b/Discord/EliteAPI.Discord/EliteDangerousApiDiscordRichPresence.cs index 9f1e8458..ea557e0e 100644 --- a/Discord/EliteAPI.Discord/EliteDangerousApiDiscordRichPresence.cs +++ b/Discord/EliteAPI.Discord/EliteDangerousApiDiscordRichPresence.cs @@ -5,6 +5,7 @@ using EliteAPI.Abstractions.Events; using EliteAPI.Abstractions.Status; using EliteAPI.Events; +using EliteAPI.Status.Ship; using EliteAPI.Status.Ship.Events; using Microsoft.Extensions.Logging; using ILogger = DiscordRPC.Logging.ILogger; @@ -36,7 +37,7 @@ public async Task StartAsync() _client.Initialize(); - _api.Events.On(OnFileheader); + _api.Events.On(OnMusic); _api.Events.On(OnDockingGranted); _api.Events.On(OnDocked); _api.Events.On(OnUndocked); @@ -49,6 +50,8 @@ public async Task StartAsync() _api.Events.On(OnSupercruiseEntry); _api.Events.On(OnSuperCruiseExit); _api.Events.On(OnProspectedAsteroid); + _api.Events.On(OnAsteroidCracked); + _api.Events.On(OnMiningRefined); _api.Events.On(OnMarketBuy); _api.Events.On(OnMarketSell); _api.Events.On(OnDestinationStatus); @@ -85,20 +88,28 @@ public async Task StartAsync() _api.Events.On(e => _playingSince = e.Timestamp); } - - private void OnFileheader(FileheaderEvent @event, EventContext context) + + private void OnMusic(MusicEvent @event, EventContext context) { if (context.IsRaisedDuringCatchup) return; + var state = @event.MusicTrack switch + { + "MainMenu" => "In main menu", + _ => "X" + }; + + if (state == "X") + return; + _client.SetPresence(new RichPresence { - State = "Just started playing", + Details = state, Assets = new Assets { LargeImageKey = "ed", - SmallImageKey = "ed", - SmallImageText = "EliteAPI" + LargeImageText = "EliteAPI" }, Timestamps = new Timestamps { Start = _playingSince } }); @@ -124,6 +135,7 @@ private void OnDockingGranted(DockingGrantedEvent @event, EventContext context) Assets = new Assets { LargeImageKey = stationImage, + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -152,6 +164,7 @@ private void OnDocked(DockedEvent @event, EventContext context) Assets = new Assets { LargeImageKey = stationImage, + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -179,6 +192,7 @@ private void OnUndocked(UndockedEvent @event, EventContext context) Assets = new Assets { LargeImageKey = stationImage, + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -210,6 +224,7 @@ private void OnStartJump(StartJumpEvent @event, EventContext context) Assets = new Assets { LargeImageKey = image, + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -232,6 +247,7 @@ private void OnFsdJump(FsdJumpEvent @event, EventContext context) Assets = new Assets { LargeImageKey = "route", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -251,6 +267,7 @@ private void OnApproachBody(ApproachBodyEvent @event, EventContext context) Assets = new Assets { LargeImageKey = "loading", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -270,6 +287,7 @@ private void OnLeaveBody(LeaveBodyEvent @event, EventContext context) Assets = new Assets { LargeImageKey = "loading", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -289,6 +307,7 @@ private void OnTouchdown(TouchdownEvent @event, EventContext context) Assets = new Assets { LargeImageKey = "exploration", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -308,6 +327,7 @@ private void OnLiftoff(LiftoffEvent @event, EventContext context) Assets = new Assets { LargeImageKey = "exploration", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -327,6 +347,7 @@ private void OnSupercruiseEntry(SupercruiseEntryEvent @event, EventContext conte Assets = new Assets { LargeImageKey = "loading", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -341,11 +362,12 @@ private void OnSuperCruiseExit(SupercruiseExitEvent @event, EventContext context _client.SetPresence(new RichPresence { - Details = "Travelling in space", + Details = "Travelling in deep space", State = $"near {@event.BodyType.ToLower().Replace("planetaryring", "ring")} {@event.Body.Replace("Ring", "")}", Assets = new Assets { LargeImageKey = "exploration", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -360,11 +382,52 @@ private void OnProspectedAsteroid(ProspectedAsteroidEvent @event, EventContext c _client.SetPresence(new RichPresence { - Details = "Mining asteroids", + Details = "Prospecting asteroids", State = $"around {_currentBody.Replace("Ring", "")}", Assets = new Assets { - LargeImageKey = "exploration", + LargeImageKey = "mining", + LargeImageText = _currentSystem, + SmallImageKey = "ed", + SmallImageText = "EliteAPI" + }, + Timestamps = new Timestamps { Start = _playingSince } + }); + } + + private void OnAsteroidCracked(AsteroidCrackedEvent @event, EventContext context) + { + if (context.IsRaisedDuringCatchup) + return; + + _client.SetPresence(new RichPresence + { + Details = "Cracking open an asteroid", + State = $"Caround {_currentBody.Replace("Ring", "")}", + Assets = new Assets + { + LargeImageKey = "mining", + LargeImageText = _currentSystem, + SmallImageKey = "ed", + SmallImageText = "EliteAPI" + }, + Timestamps = new Timestamps { Start = _playingSince } + }); + } + + private void OnMiningRefined(MiningRefinedEvent @event, EventContext context) + { + if (context.IsRaisedDuringCatchup) + return; + + _client.SetPresence(new RichPresence + { + Details = $"Mining {@event.Type.Local}", + State = $"in {_currentBody.Replace("Ring", "")}", + Assets = new Assets + { + LargeImageKey = "mining", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -384,6 +447,7 @@ private void OnMarketBuy(MarketBuyEvent @event, EventContext context) Assets = new Assets { LargeImageKey = "trading", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -403,6 +467,7 @@ private void OnMarketSell(MarketSellEvent @event, EventContext context) Assets = new Assets { LargeImageKey = "trading", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -428,6 +493,7 @@ private void OnDestinationStatus(DestinationStatusEvent @event, EventContext con Assets = new Assets { LargeImageKey = "loading", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" }, @@ -447,6 +513,7 @@ private void OnUnderAttack(UnderAttackEvent @event, EventContext context) Assets = new Assets { LargeImageKey = "combat", + LargeImageText = _currentSystem, SmallImageKey = "ed", SmallImageText = "EliteAPI" },