diff --git a/NadekoBot/Classes/Music/Song.cs b/NadekoBot/Classes/Music/Song.cs index 18448373..bc595d44 100644 --- a/NadekoBot/Classes/Music/Song.cs +++ b/NadekoBot/Classes/Music/Song.cs @@ -124,7 +124,7 @@ namespace NadekoBot.Classes.Music { $"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}`"; public SongInfo SongInfo { get; } - private PoopyBuffer songBuffer { get; } = new PoopyBuffer(2.MB()); + private PoopyBuffer songBuffer { get; } = new PoopyBuffer(10.MB()); private bool prebufferingComplete { get; set; } = false; public MusicPlayer MusicPlayer { get; set; } @@ -148,24 +148,24 @@ namespace NadekoBot.Classes.Music { while (!cancelToken.IsCancellationRequested) { int read = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, blockSize); if (read == 0) - if (attempt++ == 10) + if (attempt++ == 20) break; else await Task.Delay(50); else attempt = 0; await songBuffer.WriteAsync(buffer, read, cancelToken); - if (songBuffer.ContentLength > 1.MB()) + if (songBuffer.ContentLength > 2.MB()) prebufferingComplete = true; } - Console.WriteLine("Buffering done."); + Console.WriteLine($"Buffering done. [{songBuffer.ContentLength}]"); }); internal async Task Play(IAudioClient voiceClient, CancellationToken cancelToken) { var t = BufferSong(cancelToken).ConfigureAwait(false); int bufferAttempts = 0; int waitPerAttempt = 500; - int toAttemptTimes = SongInfo.ProviderType != MusicType.Normal ? 4 : 8; + int toAttemptTimes = SongInfo.ProviderType != MusicType.Normal ? 5 : 9; while (!prebufferingComplete && bufferAttempts++ < toAttemptTimes) { await Task.Delay(waitPerAttempt); } diff --git a/NadekoBot/Classes/NadekoStats.cs b/NadekoBot/Classes/NadekoStats.cs index 346349a5..b980149e 100644 --- a/NadekoBot/Classes/NadekoStats.cs +++ b/NadekoBot/Classes/NadekoStats.cs @@ -7,10 +7,8 @@ using System.Linq; using NadekoBot.Extensions; using System.Threading.Tasks; -namespace NadekoBot -{ - public class NadekoStats - { +namespace NadekoBot { + public class NadekoStats { public string BotVersion = "NadekoBot 0.8-beta14"; private static readonly NadekoStats _instance = new NadekoStats(); @@ -23,6 +21,10 @@ namespace NadekoBot private string _statsCache = ""; private Stopwatch _statsSW = new Stopwatch(); + public int ServerCount { get; private set; } = 0; + public int TextChannelsCount { get; private set; } = 0; + public int VoiceChannelsCount { get; private set; } = 0; + List messages = new List(); static NadekoStats() { } @@ -37,6 +39,50 @@ namespace NadekoBot Task.Run(() => StartCollecting()); Console.WriteLine("Logging enabled."); + + ServerCount = _client.Servers.Count(); + var channels = _client.Servers.SelectMany(s => s.AllChannels); + TextChannelsCount = channels.Where(c => c.Type == ChannelType.Text).Count(); + VoiceChannelsCount = channels.Count() - TextChannelsCount; + + _client.JoinedServer += (s, e) => { + try { + ServerCount++; + TextChannelsCount += e.Server.TextChannels.Count(); + VoiceChannelsCount += e.Server.VoiceChannels.Count(); + } + catch { } + }; + _client.LeftServer += (s, e) => { + try { + ServerCount--; + TextChannelsCount -= e.Server.TextChannels.Count(); + VoiceChannelsCount -= e.Server.VoiceChannels.Count(); + } + catch { } + }; + _client.ChannelCreated += (s, e) => { + try { + if (e.Channel.IsPrivate) + return; + if (e.Channel.Type == ChannelType.Text) + TextChannelsCount++; + else if (e.Channel.Type == ChannelType.Voice) + VoiceChannelsCount++; + } + catch { } + }; + _client.ChannelDestroyed += (s, e) => { + try { + if (e.Channel.IsPrivate) + return; + if (e.Channel.Type == ChannelType.Text) + VoiceChannelsCount++; + else if (e.Channel.Type == ChannelType.Voice) + VoiceChannelsCount--; + } + catch { } + }; } public TimeSpan GetUptime() => @@ -47,29 +93,31 @@ namespace NadekoBot return time.Days + " days, " + time.Hours + " hours, and " + time.Minutes + " minutes."; } - public void LoadStats() { - var sb = new System.Text.StringBuilder(); - sb.AppendLine("`Author: Kwoth` `Library: Discord.Net`"); - //$"\nDiscord.Net version: {DiscordConfig.LibVersion}" + - //$"\nRuntime: {_client.GetRuntime()}" + - sb.AppendLine($"`Bot Version: {BotVersion}`"); - //$"\nLogged in as: {_client.CurrentUser.Name}" + - sb.AppendLine($"`Bot id: {_client.CurrentUser.Id}`"); - sb.AppendLine($"`Owner id: {NadekoBot.OwnerID}`"); - sb.AppendLine($"`Uptime: {GetUptimeString()}`"); - sb.Append($"`Servers: {_client.Servers.Count()}"); - sb.AppendLine($" | Channels: {_client.Servers.Sum(s => s.AllChannels.Count())}`"); - //$"\nUsers: {_client.Servers.SelectMany(x => x.Users.Select(y => y.Id)).Count()} (non-unique)" + - sb.AppendLine($"`Heap: {Math.Round((double)GC.GetTotalMemory(true) / 1.MiB(), 2).ToString()} MB`"); - sb.AppendLine($"`Commands Ran this session: {_commandsRan}`"); - sb.AppendLine($"`Message queue size:{_client.MessageQueue.Count}`"); - sb.AppendLine($"`Greeted {Commands.ServerGreetCommand.Greeted} times.`"); - _statsCache = sb.ToString(); - } + public Task LoadStats() => + Task.Run(() => { + var sb = new System.Text.StringBuilder(); + sb.AppendLine("`Author: Kwoth` `Library: Discord.Net`"); + //$"\nDiscord.Net version: {DiscordConfig.LibVersion}" + + //$"\nRuntime: {_client.GetRuntime()}" + + sb.AppendLine($"`Bot Version: {BotVersion}`"); + //$"\nLogged in as: {_client.CurrentUser.Name}" + + sb.AppendLine($"`Bot id: {_client.CurrentUser.Id}`"); + sb.AppendLine($"`Owner id: {NadekoBot.OwnerID}`"); + sb.AppendLine($"`Uptime: {GetUptimeString()}`"); + sb.Append($"`Servers: {ServerCount}"); + sb.Append($" | TextChannels: {TextChannelsCount}"); + sb.AppendLine($" | VoiceChannels: {VoiceChannelsCount}`"); + //$"\nUsers: {_client.Servers.SelectMany(x => x.Users.Select(y => y.Id)).Count()} (non-unique)" + + sb.AppendLine($"`Heap: {Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString()} MB`"); + sb.AppendLine($"`Commands Ran this session: {_commandsRan}`"); + sb.AppendLine($"`Message queue size:{_client.MessageQueue.Count}`"); + sb.AppendLine($"`Greeted {Commands.ServerGreetCommand.Greeted} times.`"); + _statsCache = sb.ToString(); + }); - public string GetStats() { - if (_statsSW.ElapsedTicks > 5) { - LoadStats(); + public async Task GetStats() { + if (_statsSW.Elapsed.Seconds > 5) { + await LoadStats(); _statsSW.Restart(); } return _statsCache; @@ -91,28 +139,29 @@ namespace NadekoBot ConnectedServers = connectedServers, DateAdded = DateTime.Now }); - } catch { + } + catch { Console.WriteLine("DB Exception in stats collecting."); break; } } } //todo - batch save this - private void StatsCollector_RanCommand(object sender, CommandEventArgs e) - { + private void StatsCollector_RanCommand(object sender, CommandEventArgs e) { try { _commandsRan++; Classes.DBHandler.Instance.InsertData(new Classes._DataModels.Command { ServerId = (long)e.Server.Id, ServerName = e.Server.Name, ChannelId = (long)e.Channel.Id, - ChannelName =e.Channel.Name, + ChannelName = e.Channel.Name, UserId = (long)e.User.Id, UserName = e.User.Name, CommandName = e.Command.Text, DateAdded = DateTime.Now }); - } catch { + } + catch { Console.WriteLine("Parse error in ran command."); } } diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index 78f984db..d1300e39 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -368,21 +368,16 @@ namespace NadekoBot.Modules { cgb.CreateCommand(".stats") .Description("Shows some basic stats for Nadeko.") .Do(async e => { - var t = Task.Run(() => { - return NadekoStats.Instance.GetStats(); //+ "`" + Music.GetMusicStats() + "`"; - }); - - await e.Channel.SendMessage(await t); - + await e.Channel.SendMessage(await NadekoStats.Instance.GetStats()); }); - + /* cgb.CreateCommand(".leaveall") .Description("Nadeko leaves all servers **OWNER ONLY**") .Do(e => { if (e.User.Id == NadekoBot.OwnerID) NadekoBot.client.Servers.ForEach(async s => { if (s.Name == e.Server.Name) return; await s.Leave(); }); }); - + */ cgb.CreateCommand(".prune") .Parameter("num", ParameterType.Required) .Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 5") diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 25411069..3955d61a 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -69,7 +69,7 @@ namespace NadekoBot { LogLevel = LogSeverity.Warning, LogHandler = (s, e) => { try { - Console.WriteLine($"Severity: {e.Severity}\nMessage: {e.Message}\nExceptionMessage: {e.Exception?.Message ?? "-"}\nException: {(e.Exception?.ToString() ?? "-")}"); + Console.WriteLine($"Severity: {e.Severity}\nMessage: {e.Message}\nExceptionMessage: {e.Exception?.Message ?? "-"}");//\nException: {(e.Exception?.ToString() ?? "-")}"); } catch { } } @@ -135,7 +135,7 @@ namespace NadekoBot { return; } Console.WriteLine("-----------------"); - Console.WriteLine(NadekoStats.Instance.GetStats()); + Console.WriteLine(await NadekoStats.Instance.GetStats()); Console.WriteLine("-----------------"); try { diff --git a/NadekoBot/bin/Debug/Discord.Net.Audio.dll b/NadekoBot/bin/Debug/Discord.Net.Audio.dll index d78758e6..3c1178d6 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Audio.dll and b/NadekoBot/bin/Debug/Discord.Net.Audio.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.Commands.dll b/NadekoBot/bin/Debug/Discord.Net.Commands.dll index 4096fa6c..51d3973b 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Commands.dll and b/NadekoBot/bin/Debug/Discord.Net.Commands.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.Modules.dll b/NadekoBot/bin/Debug/Discord.Net.Modules.dll index 9d8214f2..e0c10031 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.Modules.dll and b/NadekoBot/bin/Debug/Discord.Net.Modules.dll differ diff --git a/NadekoBot/bin/Debug/Discord.Net.dll b/NadekoBot/bin/Debug/Discord.Net.dll index bb4e2311..06891e26 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.dll and b/NadekoBot/bin/Debug/Discord.Net.dll differ