From d0326ad680088c315b80dcb9c24120e449d9a641 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 5 Jul 2017 13:31:41 +0200 Subject: [PATCH] readded %playing% and %queued% placeholders --- .../Replacements/ReplacementBuilder.cs | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/NadekoBot/DataStructures/Replacements/ReplacementBuilder.cs b/src/NadekoBot/DataStructures/Replacements/ReplacementBuilder.cs index e7e7d2d4..0dc367a6 100644 --- a/src/NadekoBot/DataStructures/Replacements/ReplacementBuilder.cs +++ b/src/NadekoBot/DataStructures/Replacements/ReplacementBuilder.cs @@ -89,25 +89,26 @@ namespace NadekoBot.DataStructures.Replacements return this; } - //public ReplacementBuilder WithMusic(MusicService ms) - //{ - // _reps.TryAdd("%playing%", () => - // { - // var cnt = ms.MusicPlayers.Count(kvp => kvp.Value.CurrentSong != null); - // if (cnt != 1) return cnt.ToString(); - // try - // { - // var mp = ms.MusicPlayers.FirstOrDefault(); - // return mp.Value.CurrentSong.SongInfo.Title; - // } - // catch - // { - // return "No songs"; - // } - // }); - // _reps.TryAdd("%queued%", () => ms.MusicPlayers.Sum(kvp => kvp.Value.Playlist.Count).ToString()); - // return this; - //} + public ReplacementBuilder WithMusic(MusicService ms) + { + _reps.TryAdd("%playing%", () => + { + var cnt = ms.MusicPlayers.Count(kvp => kvp.Value.Current.Current != null); + if (cnt != 1) return cnt.ToString(); + try + { + var mp = ms.MusicPlayers.FirstOrDefault(); + var title = mp.Value?.Current.Current?.Title; + return title ?? "No songs"; + } + catch + { + return "error"; + } + }); + _reps.TryAdd("%queued%", () => ms.MusicPlayers.Sum(kvp => kvp.Value.QueueArray().Songs.Length).ToString()); + return this; + } public ReplacementBuilder WithRngRegex() {