Showing current time on !m np
This commit is contained in:
parent
19deee6597
commit
d25690c83b
@ -130,6 +130,13 @@ namespace NadekoBot.Classes.Music {
|
|||||||
private bool prebufferingComplete { get; set; } = false;
|
private bool prebufferingComplete { get; set; } = false;
|
||||||
public MusicPlayer MusicPlayer { get; set; }
|
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) {
|
private Song(SongInfo songInfo) {
|
||||||
this.SongInfo = songInfo;
|
this.SongInfo = songInfo;
|
||||||
}
|
}
|
||||||
@ -186,8 +193,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
var bufferTask = new ConfiguredTaskAwaitable();
|
var bufferTask = new ConfiguredTaskAwaitable();
|
||||||
try {
|
try {
|
||||||
bufferTask = BufferSong(cancelToken).ConfigureAwait(false);
|
bufferTask = BufferSong(cancelToken).ConfigureAwait(false);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
var clr = Console.ForegroundColor;
|
var clr = Console.ForegroundColor;
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine($"ERR BUFFER START : {ex.Message}\n{ex}");
|
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---------");
|
//Console.WriteLine($"Read: {songBuffer.ReadPosition}\nWrite: {songBuffer.WritePosition}\nContentLength:{songBuffer.ContentLength}\n---------");
|
||||||
byte[] buffer = new byte[blockSize];
|
byte[] buffer = new byte[blockSize];
|
||||||
var read = songBuffer.Read(buffer, blockSize);
|
var read = songBuffer.Read(buffer, blockSize);
|
||||||
|
unchecked {
|
||||||
|
bytesSent += (ulong)read;
|
||||||
|
}
|
||||||
if (read == 0)
|
if (read == 0)
|
||||||
if (attempt++ == 20) {
|
if (attempt++ == 20) {
|
||||||
voiceClient.Wait();
|
voiceClient.Wait();
|
||||||
Console.WriteLine($"Song finished. [{songBuffer.ContentLength}]");
|
Console.WriteLine($"Song finished. [{songBuffer.ContentLength}]");
|
||||||
break;
|
break;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
await Task.Delay(100, cancelToken);
|
await Task.Delay(100, cancelToken);
|
||||||
else
|
else
|
||||||
attempt = 0;
|
attempt = 0;
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics.Eventing.Reader;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Discord;
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using NadekoBot.Classes.Permissions;
|
using NadekoBot.Classes.Permissions;
|
||||||
|
@ -121,7 +121,10 @@ namespace NadekoBot.Modules {
|
|||||||
MusicPlayer musicPlayer;
|
MusicPlayer musicPlayer;
|
||||||
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
|
if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer))
|
||||||
return;
|
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")
|
cgb.CreateCommand("vol")
|
||||||
|
Loading…
Reference in New Issue
Block a user