optimizations, tried to fix queue of longs songs.
This commit is contained in:
parent
09adb9854c
commit
6e23aa2d67
@ -124,7 +124,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
$"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}`";
|
$"**【 {SongInfo.Title.TrimTo(55)} 】**`{(SongInfo.Provider ?? "-")}`";
|
||||||
public SongInfo SongInfo { get; }
|
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;
|
private bool prebufferingComplete { get; set; } = false;
|
||||||
public MusicPlayer MusicPlayer { get; set; }
|
public MusicPlayer MusicPlayer { get; set; }
|
||||||
@ -148,24 +148,24 @@ namespace NadekoBot.Classes.Music {
|
|||||||
while (!cancelToken.IsCancellationRequested) {
|
while (!cancelToken.IsCancellationRequested) {
|
||||||
int read = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, blockSize);
|
int read = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, blockSize);
|
||||||
if (read == 0)
|
if (read == 0)
|
||||||
if (attempt++ == 10)
|
if (attempt++ == 20)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
await Task.Delay(50);
|
await Task.Delay(50);
|
||||||
else
|
else
|
||||||
attempt = 0;
|
attempt = 0;
|
||||||
await songBuffer.WriteAsync(buffer, read, cancelToken);
|
await songBuffer.WriteAsync(buffer, read, cancelToken);
|
||||||
if (songBuffer.ContentLength > 1.MB())
|
if (songBuffer.ContentLength > 2.MB())
|
||||||
prebufferingComplete = true;
|
prebufferingComplete = true;
|
||||||
}
|
}
|
||||||
Console.WriteLine("Buffering done.");
|
Console.WriteLine($"Buffering done. [{songBuffer.ContentLength}]");
|
||||||
});
|
});
|
||||||
|
|
||||||
internal async Task Play(IAudioClient voiceClient, CancellationToken cancelToken) {
|
internal async Task Play(IAudioClient voiceClient, CancellationToken cancelToken) {
|
||||||
var t = BufferSong(cancelToken).ConfigureAwait(false);
|
var t = BufferSong(cancelToken).ConfigureAwait(false);
|
||||||
int bufferAttempts = 0;
|
int bufferAttempts = 0;
|
||||||
int waitPerAttempt = 500;
|
int waitPerAttempt = 500;
|
||||||
int toAttemptTimes = SongInfo.ProviderType != MusicType.Normal ? 4 : 8;
|
int toAttemptTimes = SongInfo.ProviderType != MusicType.Normal ? 5 : 9;
|
||||||
while (!prebufferingComplete && bufferAttempts++ < toAttemptTimes) {
|
while (!prebufferingComplete && bufferAttempts++ < toAttemptTimes) {
|
||||||
await Task.Delay(waitPerAttempt);
|
await Task.Delay(waitPerAttempt);
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,8 @@ using System.Linq;
|
|||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot
|
namespace NadekoBot {
|
||||||
{
|
public class NadekoStats {
|
||||||
public class NadekoStats
|
|
||||||
{
|
|
||||||
public string BotVersion = "NadekoBot 0.8-beta14";
|
public string BotVersion = "NadekoBot 0.8-beta14";
|
||||||
|
|
||||||
private static readonly NadekoStats _instance = new NadekoStats();
|
private static readonly NadekoStats _instance = new NadekoStats();
|
||||||
@ -23,6 +21,10 @@ namespace NadekoBot
|
|||||||
private string _statsCache = "";
|
private string _statsCache = "";
|
||||||
private Stopwatch _statsSW = new Stopwatch();
|
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<string> messages = new List<string>();
|
List<string> messages = new List<string>();
|
||||||
|
|
||||||
static NadekoStats() { }
|
static NadekoStats() { }
|
||||||
@ -37,6 +39,50 @@ namespace NadekoBot
|
|||||||
|
|
||||||
Task.Run(() => StartCollecting());
|
Task.Run(() => StartCollecting());
|
||||||
Console.WriteLine("Logging enabled.");
|
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() =>
|
public TimeSpan GetUptime() =>
|
||||||
@ -47,7 +93,8 @@ namespace NadekoBot
|
|||||||
return time.Days + " days, " + time.Hours + " hours, and " + time.Minutes + " minutes.";
|
return time.Days + " days, " + time.Hours + " hours, and " + time.Minutes + " minutes.";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadStats() {
|
public Task LoadStats() =>
|
||||||
|
Task.Run(() => {
|
||||||
var sb = new System.Text.StringBuilder();
|
var sb = new System.Text.StringBuilder();
|
||||||
sb.AppendLine("`Author: Kwoth` `Library: Discord.Net`");
|
sb.AppendLine("`Author: Kwoth` `Library: Discord.Net`");
|
||||||
//$"\nDiscord.Net version: {DiscordConfig.LibVersion}" +
|
//$"\nDiscord.Net version: {DiscordConfig.LibVersion}" +
|
||||||
@ -57,19 +104,20 @@ namespace NadekoBot
|
|||||||
sb.AppendLine($"`Bot id: {_client.CurrentUser.Id}`");
|
sb.AppendLine($"`Bot id: {_client.CurrentUser.Id}`");
|
||||||
sb.AppendLine($"`Owner id: {NadekoBot.OwnerID}`");
|
sb.AppendLine($"`Owner id: {NadekoBot.OwnerID}`");
|
||||||
sb.AppendLine($"`Uptime: {GetUptimeString()}`");
|
sb.AppendLine($"`Uptime: {GetUptimeString()}`");
|
||||||
sb.Append($"`Servers: {_client.Servers.Count()}");
|
sb.Append($"`Servers: {ServerCount}");
|
||||||
sb.AppendLine($" | Channels: {_client.Servers.Sum(s => s.AllChannels.Count())}`");
|
sb.Append($" | TextChannels: {TextChannelsCount}");
|
||||||
|
sb.AppendLine($" | VoiceChannels: {VoiceChannelsCount}`");
|
||||||
//$"\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)" +
|
||||||
sb.AppendLine($"`Heap: {Math.Round((double)GC.GetTotalMemory(true) / 1.MiB(), 2).ToString()} MB`");
|
sb.AppendLine($"`Heap: {Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString()} MB`");
|
||||||
sb.AppendLine($"`Commands Ran this session: {_commandsRan}`");
|
sb.AppendLine($"`Commands Ran this session: {_commandsRan}`");
|
||||||
sb.AppendLine($"`Message queue size:{_client.MessageQueue.Count}`");
|
sb.AppendLine($"`Message queue size:{_client.MessageQueue.Count}`");
|
||||||
sb.AppendLine($"`Greeted {Commands.ServerGreetCommand.Greeted} times.`");
|
sb.AppendLine($"`Greeted {Commands.ServerGreetCommand.Greeted} times.`");
|
||||||
_statsCache = sb.ToString();
|
_statsCache = sb.ToString();
|
||||||
}
|
});
|
||||||
|
|
||||||
public string GetStats() {
|
public async Task<string> GetStats() {
|
||||||
if (_statsSW.ElapsedTicks > 5) {
|
if (_statsSW.Elapsed.Seconds > 5) {
|
||||||
LoadStats();
|
await LoadStats();
|
||||||
_statsSW.Restart();
|
_statsSW.Restart();
|
||||||
}
|
}
|
||||||
return _statsCache;
|
return _statsCache;
|
||||||
@ -91,28 +139,29 @@ namespace NadekoBot
|
|||||||
ConnectedServers = connectedServers,
|
ConnectedServers = connectedServers,
|
||||||
DateAdded = DateTime.Now
|
DateAdded = DateTime.Now
|
||||||
});
|
});
|
||||||
} catch {
|
}
|
||||||
|
catch {
|
||||||
Console.WriteLine("DB Exception in stats collecting.");
|
Console.WriteLine("DB Exception in stats collecting.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//todo - batch save this
|
//todo - batch save this
|
||||||
private void StatsCollector_RanCommand(object sender, CommandEventArgs e)
|
private void StatsCollector_RanCommand(object sender, CommandEventArgs e) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
_commandsRan++;
|
_commandsRan++;
|
||||||
Classes.DBHandler.Instance.InsertData(new Classes._DataModels.Command {
|
Classes.DBHandler.Instance.InsertData(new Classes._DataModels.Command {
|
||||||
ServerId = (long)e.Server.Id,
|
ServerId = (long)e.Server.Id,
|
||||||
ServerName = e.Server.Name,
|
ServerName = e.Server.Name,
|
||||||
ChannelId = (long)e.Channel.Id,
|
ChannelId = (long)e.Channel.Id,
|
||||||
ChannelName =e.Channel.Name,
|
ChannelName = e.Channel.Name,
|
||||||
UserId = (long)e.User.Id,
|
UserId = (long)e.User.Id,
|
||||||
UserName = e.User.Name,
|
UserName = e.User.Name,
|
||||||
CommandName = e.Command.Text,
|
CommandName = e.Command.Text,
|
||||||
DateAdded = DateTime.Now
|
DateAdded = DateTime.Now
|
||||||
});
|
});
|
||||||
} catch {
|
}
|
||||||
|
catch {
|
||||||
Console.WriteLine("Parse error in ran command.");
|
Console.WriteLine("Parse error in ran command.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,21 +368,16 @@ namespace NadekoBot.Modules {
|
|||||||
cgb.CreateCommand(".stats")
|
cgb.CreateCommand(".stats")
|
||||||
.Description("Shows some basic stats for Nadeko.")
|
.Description("Shows some basic stats for Nadeko.")
|
||||||
.Do(async e => {
|
.Do(async e => {
|
||||||
var t = Task.Run(() => {
|
await e.Channel.SendMessage(await NadekoStats.Instance.GetStats());
|
||||||
return NadekoStats.Instance.GetStats(); //+ "`" + Music.GetMusicStats() + "`";
|
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
await e.Channel.SendMessage(await t);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
cgb.CreateCommand(".leaveall")
|
cgb.CreateCommand(".leaveall")
|
||||||
.Description("Nadeko leaves all servers **OWNER ONLY**")
|
.Description("Nadeko leaves all servers **OWNER ONLY**")
|
||||||
.Do(e => {
|
.Do(e => {
|
||||||
if (e.User.Id == NadekoBot.OwnerID)
|
if (e.User.Id == NadekoBot.OwnerID)
|
||||||
NadekoBot.client.Servers.ForEach(async s => { if (s.Name == e.Server.Name) return; await s.Leave(); });
|
NadekoBot.client.Servers.ForEach(async s => { if (s.Name == e.Server.Name) return; await s.Leave(); });
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
cgb.CreateCommand(".prune")
|
cgb.CreateCommand(".prune")
|
||||||
.Parameter("num", ParameterType.Required)
|
.Parameter("num", ParameterType.Required)
|
||||||
.Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 5")
|
.Description("Prunes a number of messages from the current channel.\n**Usage**: .prune 5")
|
||||||
|
@ -69,7 +69,7 @@ namespace NadekoBot {
|
|||||||
LogLevel = LogSeverity.Warning,
|
LogLevel = LogSeverity.Warning,
|
||||||
LogHandler = (s, e) => {
|
LogHandler = (s, e) => {
|
||||||
try {
|
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 { }
|
catch { }
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ namespace NadekoBot {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Console.WriteLine("-----------------");
|
Console.WriteLine("-----------------");
|
||||||
Console.WriteLine(NadekoStats.Instance.GetStats());
|
Console.WriteLine(await NadekoStats.Instance.GetStats());
|
||||||
Console.WriteLine("-----------------");
|
Console.WriteLine("-----------------");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user