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() {
VideoInfo video = null;
try {
if (OnResolving != null)
OnResolving();
Console.WriteLine("Resolving video link");
video = DownloadUrlResolver.GetDownloadUrls(Searches.FindYoutubeUrlByKeywords(Query))
.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"
} catch (Exception ex) {
privateState = StreamState.Completed;
if (OnResolvingFailed != null)
OnResolvingFailed(ex.Message);
Console.WriteLine($"Failed resolving the link.{ex.Message}");
return;
}
@ -83,6 +87,8 @@ namespace NadekoBot.Classes.Music {
public Action OnBuffering = null;
public Action OnStarted = 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
@ -238,20 +244,18 @@ namespace NadekoBot.Classes.Music {
}
// 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) {
Console.WriteLine("Prebuffering complete.");
} else {
Console.WriteLine("Didn't buffer jack shit.");
}
//for now wait for 3 seconds before starting playback.
int blockSize = 1920 * NadekoBot.client.Audio().Config.Channels;
byte[] voiceBuffer = new byte[blockSize];
if (parent.OnStarted != null)
parent.OnStarted();
int attempt = 0;
while (!IsCanceled) {
int readCount = 0;

View File

@ -47,18 +47,18 @@ namespace NadekoBot
public void LoadStats() {
_statsCache =
"Author: Kwoth" +
$"\nDiscord.Net version: {DiscordConfig.LibVersion}" +
$"\nRuntime: {_client.GetRuntime()}" +
$"\nBot Version: {BotVersion}" +
$"\nLogged in as: {_client.CurrentUser.Name}" +
$"\nBot id: {_client.CurrentUser.Id}" +
$"\nUptime: {GetUptimeString()}" +
$"\nServers: {_client.Servers.Count()}" +
$"\nChannels: {_client.Servers.Sum(s => s.AllChannels.Count())}" +
$"\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" +
$"\nCommands Ran this session: {_commandsRan}";
"`Author: Kwoth`" +
//$"\nDiscord.Net version: {DiscordConfig.LibVersion}" +
//$"\nRuntime: {_client.GetRuntime()}" +
$"\n`Bot Version: {BotVersion}`" +
//$"\nLogged in as: {_client.CurrentUser.Name}" +
$"\n`Bot id: {_client.CurrentUser.Id}`" +
$"\n`Uptime: {GetUptimeString()}`" +
$"\n`Servers: {_client.Servers.Count()}`" +
$"\n`Channels: {_client.Servers.Sum(s => s.AllChannels.Count())}`" +
//$"\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" +
$"\n`Commands Ran this session: {_commandsRan}`";
}
public string GetStats() {

View File

@ -272,7 +272,7 @@ namespace NadekoBot.Modules {
.Description("Shows some basic stats for nadeko")
.Do(async e => {
var t = Task.Run(() => {
return "```" + NadekoStats.Instance.GetStats() + "\n" + Music.GetMusicStats() + "```";
return NadekoStats.Instance.GetStats() + "\n`" + Music.GetMusicStats() + "`";
});
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");
return;
}
if (e.GetArg("query") == null || e.GetArg("query").Length < 5)
return;
var player = musicPlayers[e.Server];
@ -97,8 +99,14 @@ namespace NadekoBot.Modules {
throw new NullReferenceException("StreamRequest is null.");
Message msg = 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 () => {
qmsg = await e.Send($":musical_note:**Queued** {sr.Title.TrimTo(55)}");
await qmsg.Edit($":musical_note:**Queued** {sr.Title.TrimTo(55)}");
};
sr.OnCompleted += async () => {
await e.Send($":musical_note:**Finished playing** {sr.Title.TrimTo(55)}");