Skip to content

Commit

Permalink
Improved Rich Presence messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Somfic committed Jun 25, 2024
1 parent 60abb01 commit 85d5fea
Showing 1 changed file with 76 additions and 9 deletions.
85 changes: 76 additions & 9 deletions Discord/EliteAPI.Discord/EliteDangerousApiDiscordRichPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,7 +37,7 @@ public async Task StartAsync()

_client.Initialize();

_api.Events.On<FileheaderEvent>(OnFileheader);
_api.Events.On<MusicEvent>(OnMusic);
_api.Events.On<DockingGrantedEvent>(OnDockingGranted);
_api.Events.On<DockedEvent>(OnDocked);
_api.Events.On<UndockedEvent>(OnUndocked);
Expand All @@ -49,6 +50,8 @@ public async Task StartAsync()
_api.Events.On<SupercruiseEntryEvent>(OnSupercruiseEntry);
_api.Events.On<SupercruiseExitEvent>(OnSuperCruiseExit);
_api.Events.On<ProspectedAsteroidEvent>(OnProspectedAsteroid);
_api.Events.On<AsteroidCrackedEvent>(OnAsteroidCracked);
_api.Events.On<MiningRefinedEvent>(OnMiningRefined);
_api.Events.On<MarketBuyEvent>(OnMarketBuy);
_api.Events.On<MarketSellEvent>(OnMarketSell);
_api.Events.On<DestinationStatusEvent>(OnDestinationStatus);
Expand Down Expand Up @@ -85,20 +88,28 @@ public async Task StartAsync()

_api.Events.On<FileheaderEvent>(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 }
});
Expand All @@ -124,6 +135,7 @@ private void OnDockingGranted(DockingGrantedEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = stationImage,
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand Down Expand Up @@ -152,6 +164,7 @@ private void OnDocked(DockedEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = stationImage,
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand Down Expand Up @@ -179,6 +192,7 @@ private void OnUndocked(UndockedEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = stationImage,
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand Down Expand Up @@ -210,6 +224,7 @@ private void OnStartJump(StartJumpEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = image,
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -232,6 +247,7 @@ private void OnFsdJump(FsdJumpEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = "route",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -251,6 +267,7 @@ private void OnApproachBody(ApproachBodyEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = "loading",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -270,6 +287,7 @@ private void OnLeaveBody(LeaveBodyEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = "loading",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -289,6 +307,7 @@ private void OnTouchdown(TouchdownEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = "exploration",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -308,6 +327,7 @@ private void OnLiftoff(LiftoffEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = "exploration",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -327,6 +347,7 @@ private void OnSupercruiseEntry(SupercruiseEntryEvent @event, EventContext conte
Assets = new Assets
{
LargeImageKey = "loading",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand All @@ -384,6 +447,7 @@ private void OnMarketBuy(MarketBuyEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = "trading",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -403,6 +467,7 @@ private void OnMarketSell(MarketSellEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = "trading",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -428,6 +493,7 @@ private void OnDestinationStatus(DestinationStatusEvent @event, EventContext con
Assets = new Assets
{
LargeImageKey = "loading",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand All @@ -447,6 +513,7 @@ private void OnUnderAttack(UnderAttackEvent @event, EventContext context)
Assets = new Assets
{
LargeImageKey = "combat",
LargeImageText = _currentSystem,
SmallImageKey = "ed",
SmallImageText = "EliteAPI"
},
Expand Down

0 comments on commit 85d5fea

Please sign in to comment.