better messages for music, stats stripped, cleanup

This commit is contained in:
Master Kwoth 2016-01-30 13:51:47 +01:00
parent efc2810f22
commit 7820f98e82
4 changed files with 32 additions and 20 deletions

View File

@ -57,6 +57,8 @@ namespace NadekoBot.Classes.Music {
private void ResolveStreamLink() { private void ResolveStreamLink() {
VideoInfo video = null; VideoInfo video = null;
try { try {
if (OnResolving != null)
OnResolving();
Console.WriteLine("Resolving video link"); Console.WriteLine("Resolving video link");
video = DownloadUrlResolver.GetDownloadUrls(Searches.FindYoutubeUrlByKeywords(Query)) video = DownloadUrlResolver.GetDownloadUrls(Searches.FindYoutubeUrlByKeywords(Query))
.Where(v => v.AdaptiveType == AdaptiveType.Audio) .Where(v => v.AdaptiveType == AdaptiveType.Audio)
@ -68,6 +70,8 @@ namespace NadekoBot.Classes.Music {
Title = video.Title.Substring(0,video.Title.Length-10); // removing trailing "- You Tube" Title = video.Title.Substring(0,video.Title.Length-10); // removing trailing "- You Tube"
} catch (Exception ex) { } catch (Exception ex) {
privateState = StreamState.Completed; privateState = StreamState.Completed;
if (OnResolvingFailed != null)
OnResolvingFailed(ex.Message);
Console.WriteLine($"Failed resolving the link.{ex.Message}"); Console.WriteLine($"Failed resolving the link.{ex.Message}");
return; return;
} }
@ -83,6 +87,8 @@ namespace NadekoBot.Classes.Music {
public Action OnBuffering = null; public Action OnBuffering = null;
public Action OnStarted = null; public Action OnStarted = null;
public Action OnCompleted = null; public Action OnCompleted = null;
public Action OnResolving = null;
public Action<string> OnResolvingFailed = null;
//todo maybe add remove, in order to create remove at position command //todo maybe add remove, in order to create remove at position command
@ -238,20 +244,18 @@ namespace NadekoBot.Classes.Music {
} }
// prebuffering wait stuff end // prebuffering wait stuff end
//Task.Run(async () => { while (true) { Console.WriteLine($"Title: {parent.Title} State:{State}"); await Task.Delay(200); } });
if (parent.OnStarted != null)
parent.OnStarted();
if (buffer.Length > 0) { if (buffer.Length > 0) {
Console.WriteLine("Prebuffering complete."); Console.WriteLine("Prebuffering complete.");
} else { } else {
Console.WriteLine("Didn't buffer jack shit."); Console.WriteLine("Didn't buffer jack shit.");
} }
//for now wait for 3 seconds before starting playback.
int blockSize = 1920 * NadekoBot.client.Audio().Config.Channels; int blockSize = 1920 * NadekoBot.client.Audio().Config.Channels;
byte[] voiceBuffer = new byte[blockSize]; byte[] voiceBuffer = new byte[blockSize];
if (parent.OnStarted != null)
parent.OnStarted();
int attempt = 0; int attempt = 0;
while (!IsCanceled) { while (!IsCanceled) {
int readCount = 0; int readCount = 0;

View File

@ -47,18 +47,18 @@ namespace NadekoBot
public void LoadStats() { public void LoadStats() {
_statsCache = _statsCache =
"Author: Kwoth" + "`Author: Kwoth`" +
$"\nDiscord.Net version: {DiscordConfig.LibVersion}" + //$"\nDiscord.Net version: {DiscordConfig.LibVersion}" +
$"\nRuntime: {_client.GetRuntime()}" + //$"\nRuntime: {_client.GetRuntime()}" +
$"\nBot Version: {BotVersion}" + $"\n`Bot Version: {BotVersion}`" +
$"\nLogged in as: {_client.CurrentUser.Name}" + //$"\nLogged in as: {_client.CurrentUser.Name}" +
$"\nBot id: {_client.CurrentUser.Id}" + $"\n`Bot id: {_client.CurrentUser.Id}`" +
$"\nUptime: {GetUptimeString()}" + $"\n`Uptime: {GetUptimeString()}`" +
$"\nServers: {_client.Servers.Count()}" + $"\n`Servers: {_client.Servers.Count()}`" +
$"\nChannels: {_client.Servers.Sum(s => s.AllChannels.Count())}" + $"\n`Channels: {_client.Servers.Sum(s => s.AllChannels.Count())}`" +
$"\nUsers: {_client.Servers.SelectMany(x => x.Users.Select(y => y.Id)).Count()} (non-unique)" + //$"\nUsers: {_client.Servers.SelectMany(x => x.Users.Select(y => y.Id)).Count()} (non-unique)" +
$"\nHeap: {Math.Round(GC.GetTotalMemory(true) / (1024.0 * 1024.0), 2).ToString()}MB" + //$"\nHeap: {Math.Round(GC.GetTotalMemory(true) / (1024.0 * 1024.0), 2).ToString()}MB" +
$"\nCommands Ran this session: {_commandsRan}"; $"\n`Commands Ran this session: {_commandsRan}`";
} }
public string GetStats() { public string GetStats() {

View File

@ -272,7 +272,7 @@ namespace NadekoBot.Modules {
.Description("Shows some basic stats for nadeko") .Description("Shows some basic stats for nadeko")
.Do(async e => { .Do(async e => {
var t = Task.Run(() => { var t = Task.Run(() => {
return "```" + NadekoStats.Instance.GetStats() + "\n" + Music.GetMusicStats() + "```"; return NadekoStats.Instance.GetStats() + "\n`" + Music.GetMusicStats() + "`";
}); });
await e.Send(await t); await e.Send(await t);

View File

@ -84,6 +84,8 @@ namespace NadekoBot.Modules {
await e.Send("Failed to create a music player for this server"); await e.Send("Failed to create a music player for this server");
return; return;
} }
if (e.GetArg("query") == null || e.GetArg("query").Length < 5)
return;
var player = musicPlayers[e.Server]; var player = musicPlayers[e.Server];
@ -97,8 +99,14 @@ namespace NadekoBot.Modules {
throw new NullReferenceException("StreamRequest is null."); throw new NullReferenceException("StreamRequest is null.");
Message msg = null; Message msg = null;
Message qmsg = null; Message qmsg = null;
sr.OnResolving += async () => {
qmsg = await e.Send($":musical_note: **Resolving**... \"{e.GetArg("query")}\"");
};
sr.OnResolvingFailed += async (err) => {
qmsg = await e.Send($":anger: :musical_note: **Resolving failed** for `{e.GetArg("query")}`");
};
sr.OnQueued += async () => { sr.OnQueued += async () => {
qmsg = await e.Send($":musical_note:**Queued** {sr.Title.TrimTo(55)}"); await qmsg.Edit($":musical_note:**Queued** {sr.Title.TrimTo(55)}");
}; };
sr.OnCompleted += async () => { sr.OnCompleted += async () => {
await e.Send($":musical_note:**Finished playing** {sr.Title.TrimTo(55)}"); await e.Send($":musical_note:**Finished playing** {sr.Title.TrimTo(55)}");