Showing current time on !m np

This commit is contained in:
Master Kwoth 2016-03-15 17:33:53 +01:00
parent 19deee6597
commit d25690c83b
3 changed files with 17 additions and 10 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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")