From d25690c83b04b9ef7307dd2d81ce44bdea124877 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Tue, 15 Mar 2016 17:33:53 +0100 Subject: [PATCH] Showing current time on !m np --- NadekoBot/Classes/Music/Song.cs | 16 ++++++++++++---- NadekoBot/Commands/SelfAssignedRolesCommand.cs | 6 +----- NadekoBot/Modules/Music.cs | 5 ++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/NadekoBot/Classes/Music/Song.cs b/NadekoBot/Classes/Music/Song.cs index 0586f73d..54a001fc 100644 --- a/NadekoBot/Classes/Music/Song.cs +++ b/NadekoBot/Classes/Music/Song.cs @@ -130,6 +130,13 @@ namespace NadekoBot.Classes.Music { private bool prebufferingComplete { get; set; } = false; public MusicPlayer MusicPlayer { get; set; } + public string PrettyCurrentTime() { + var time = TimeSpan.FromSeconds(bytesSent / 3840 / 50); + return $"【{(int)time.TotalMinutes}m {time.Seconds}s】"; + } + + private ulong bytesSent { get; set; } = 0; + private Song(SongInfo songInfo) { this.SongInfo = songInfo; } @@ -186,8 +193,7 @@ namespace NadekoBot.Classes.Music { var bufferTask = new ConfiguredTaskAwaitable(); try { bufferTask = BufferSong(cancelToken).ConfigureAwait(false); - } - catch (Exception ex) { + } catch (Exception ex) { var clr = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"ERR BUFFER START : {ex.Message}\n{ex}"); @@ -207,13 +213,15 @@ namespace NadekoBot.Classes.Music { //Console.WriteLine($"Read: {songBuffer.ReadPosition}\nWrite: {songBuffer.WritePosition}\nContentLength:{songBuffer.ContentLength}\n---------"); byte[] buffer = new byte[blockSize]; var read = songBuffer.Read(buffer, blockSize); + unchecked { + bytesSent += (ulong)read; + } if (read == 0) if (attempt++ == 20) { voiceClient.Wait(); Console.WriteLine($"Song finished. [{songBuffer.ContentLength}]"); break; - } - else + } else await Task.Delay(100, cancelToken); else attempt = 0; diff --git a/NadekoBot/Commands/SelfAssignedRolesCommand.cs b/NadekoBot/Commands/SelfAssignedRolesCommand.cs index ea22197e..f1354ca0 100644 --- a/NadekoBot/Commands/SelfAssignedRolesCommand.cs +++ b/NadekoBot/Commands/SelfAssignedRolesCommand.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.Eventing.Reader; +using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; -using Discord; using Discord.Commands; using NadekoBot.Classes; using NadekoBot.Classes.Permissions; diff --git a/NadekoBot/Modules/Music.cs b/NadekoBot/Modules/Music.cs index 0e48e940..a6187a32 100644 --- a/NadekoBot/Modules/Music.cs +++ b/NadekoBot/Modules/Music.cs @@ -121,7 +121,10 @@ namespace NadekoBot.Modules { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return; - await e.Channel.SendMessage($"🎵`Now Playing` {musicPlayer.CurrentSong.PrettyName}"); + var currentSong = musicPlayer.CurrentSong; + if (currentSong != null) + await e.Channel.SendMessage($"🎵`Now Playing` {currentSong.PrettyName} " + + $"{currentSong.PrettyCurrentTime()}"); }); cgb.CreateCommand("vol")