diff --git a/DiscordMediaRP/DisMediaRP.cs b/DiscordMediaRP/DisMediaRP.cs index 6a5c5ec..28bbd27 100644 --- a/DiscordMediaRP/DisMediaRP.cs +++ b/DiscordMediaRP/DisMediaRP.cs @@ -18,16 +18,24 @@ public class DisMediaRP : IDisposable private readonly ILogger? _logger; private readonly MediaManager _mediaManager = new(); private readonly DiscordRpcClient _discordRpcClient; - private readonly RichPresence _currentStatus = new(); + private readonly RichPresence _currentStatus = new() + { + Assets = new() + { + LargeImageText = "C9Glax/DiscordMediaRichPresence", + SmallImageText = "https://www.flaticon.com/de/autoren/alfanz" + } + }; private bool _running = true; - public DisMediaRP(string applicationId, LogLevel? logLevel) : this(applicationId, new Logger(logLevel ?? LogLevel.Information)) + public DisMediaRP(string applicationId, LogLevel? logLevel, string? largeImageKey = null) : this(applicationId, new Logger(logLevel ?? LogLevel.Information), largeImageKey) { } - public DisMediaRP(string applicationId, ILogger? logger) + public DisMediaRP(string applicationId, ILogger? logger = null, string? largeImageKey = null) { this._logger = logger; + this._currentStatus.Assets.LargeImageKey = largeImageKey ?? "cat"; this._discordRpcClient = new DiscordRpcClient(applicationId, logger: new DisLogger(this._logger)); this._discordRpcClient.Initialize(); this._discordRpcClient.OnError += (sender, args) => @@ -79,12 +87,12 @@ public class DisMediaRP : IDisposable return; - string? playbackState = playbackInfo.PlaybackStatus switch + string playbackState = playbackInfo.PlaybackStatus switch { - GlobalSystemMediaTransportControlsSessionPlaybackStatus.Paused => "\u23f8", - GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing => "\u25b6", - GlobalSystemMediaTransportControlsSessionPlaybackStatus.Stopped => "\u23f9", - _ => null + GlobalSystemMediaTransportControlsSessionPlaybackStatus.Paused => "pause", + GlobalSystemMediaTransportControlsSessionPlaybackStatus.Playing => "play", + GlobalSystemMediaTransportControlsSessionPlaybackStatus.Stopped => "stop", + _ => "music" }; string? repeatMode = playbackInfo.AutoRepeatMode switch @@ -96,7 +104,8 @@ public class DisMediaRP : IDisposable string? shuffle = (playbackInfo.IsShuffleActive ?? false) ? "\ud83d\udd00" : null; - this._currentStatus.State = string.Join(' ', playbackState, repeatMode, shuffle, mediaSession.Id); + this._currentStatus.State = string.Join(' ', repeatMode, shuffle); + this._currentStatus.Assets.SmallImageKey = playbackState; this._discordRpcClient.SetPresence(this._currentStatus); } diff --git a/DiscordMediaRP/Program.cs b/DiscordMediaRP/Program.cs index 0b3a1ba..0d39e41 100644 --- a/DiscordMediaRP/Program.cs +++ b/DiscordMediaRP/Program.cs @@ -3,10 +3,30 @@ using DiscordMediaRP; using Microsoft.Extensions.Logging; -int loglevelIndex = Array.IndexOf(args, "-l") + 1; -LogLevel? level = loglevelIndex >= 0 && loglevelIndex < args.Length ? Enum.Parse(args[loglevelIndex]) : null; -int discordKeyIndex = Array.IndexOf(args, "-d") + 1; -if (discordKeyIndex < 1 || discordKeyIndex >= args.Length) - throw new IndexOutOfRangeException("No Discord ApplicationKey provided"); -string discordKey = args[discordKeyIndex]; -DisMediaRP _ = new (discordKey, level); \ No newline at end of file +int loglevelIndex = Array.IndexOf(args, "-l"); +LogLevel? level = null; +if(loglevelIndex > -1) + if(loglevelIndex + 1 < args.Length) + level = loglevelIndex < args.Length ? Enum.Parse(args[loglevelIndex + 1]) : null; + else + throw new IndexOutOfRangeException(nameof(loglevelIndex)); + +int discordKeyIndex = Array.IndexOf(args, "-d"); +string discordKey; +if (loglevelIndex > -1) + if(discordKeyIndex + 1 < args.Length) + discordKey = args[discordKeyIndex + 1]; + else + throw new IndexOutOfRangeException("No Discord ApplicationKey provided"); +else + throw new ArgumentNullException(nameof(discordKey)); + +int imageKeyIndex = Array.IndexOf(args, "-i"); +string? imageKey = null; +if(imageKeyIndex > -1) + if (imageKeyIndex + 1 < args.Length) + imageKey = args[imageKeyIndex + 1]; + else + throw new IndexOutOfRangeException(nameof(imageKeyIndex)); + +DisMediaRP _ = new (discordKey, level, imageKey); \ No newline at end of file diff --git a/DiscordMediaRP/media/icons.txt b/DiscordMediaRP/media/icons.txt new file mode 100644 index 0000000..7aa686d --- /dev/null +++ b/DiscordMediaRP/media/icons.txt @@ -0,0 +1 @@ +https://www.flaticon.com/de/autoren/alfanz \ No newline at end of file diff --git a/DiscordMediaRP/media/music.png b/DiscordMediaRP/media/music.png new file mode 100644 index 0000000..27a3b7f Binary files /dev/null and b/DiscordMediaRP/media/music.png differ diff --git a/DiscordMediaRP/media/pause.png b/DiscordMediaRP/media/pause.png new file mode 100644 index 0000000..61b8530 Binary files /dev/null and b/DiscordMediaRP/media/pause.png differ diff --git a/DiscordMediaRP/media/play.png b/DiscordMediaRP/media/play.png new file mode 100644 index 0000000..888ef4b Binary files /dev/null and b/DiscordMediaRP/media/play.png differ diff --git a/DiscordMediaRP/media/stop.png b/DiscordMediaRP/media/stop.png new file mode 100644 index 0000000..d51aba3 Binary files /dev/null and b/DiscordMediaRP/media/stop.png differ