new libs, crashfix, !m setgame, ripyear...

also better strings for music (plural and singular)
This commit is contained in:
Master Kwoth
2016-01-31 09:22:47 +01:00
parent 73309c723e
commit e71e390cca
10 changed files with 64 additions and 35 deletions

View File

@@ -44,6 +44,20 @@ namespace NadekoBot.Extensions {
return str;
return string.Join("", str.Take(num - 3)) + "...";
}
/// <summary>
/// Removes trailing S or ES (if specified) on the given string if the num is 1
/// </summary>
/// <param name="str"></param>
/// <param name="num"></param>
/// <param name="es"></param>
/// <returns>String with the correct singular/plural form</returns>
public static string SnPl(this string str, int? num,bool es = false) {
if (str == null)
throw new ArgumentNullException(nameof(str));
if (num == null)
throw new ArgumentNullException(nameof(num));
return num == 1 ? str.Remove(str.Length - 1, es ? 2 : 1) : str;
}
/// <summary>
/// Sends a message to the channel from which this command is called.

View File

@@ -24,21 +24,17 @@ namespace NadekoBot.Classes.Music {
public MusicControls() {
Task.Run(async () => {
while (!Stopped) {
try {
lock (_voiceLock) {
if (CurrentSong == null) {
if (SongQueue.Count > 0)
LoadNextSong();
} else if (CurrentSong.State == StreamState.Completed || NextSong) {
NextSong = false;
lock (_voiceLock) {
if (CurrentSong == null) {
if (SongQueue.Count > 0)
LoadNextSong();
}
} else if (CurrentSong.State == StreamState.Completed || NextSong) {
NextSong = false;
LoadNextSong();
}
} catch (Exception e) {
Console.WriteLine("Bug in music task run. " + e);
}
await Task.Delay(500);
await Task.Delay(1000);
}
});
}
@@ -74,7 +70,7 @@ namespace NadekoBot.Classes.Music {
Stopped = true;
foreach (var kvp in SongQueue) {
if(kvp != null)
kvp.Cancel();
kvp.Stop();
}
SongQueue.Clear();
CurrentSong?.Stop();

View File

@@ -239,7 +239,7 @@ namespace NadekoBot.Classes.Music {
// prebuffering wait stuff start
int bufferAttempts = 0;
int waitPerAttempt = 500;
while (!prebufferingComplete && bufferAttempts++ < 10) {
while (!prebufferingComplete && bufferAttempts++ < 15) {
await Task.Delay(waitPerAttempt);
}
if (prebufferingComplete) {
@@ -299,8 +299,9 @@ namespace NadekoBot.Classes.Music {
internal void Stop() {
Console.WriteLine("Stopping playback");
if (State != StreamState.Completed) {
if(State == StreamState.Playing)
parent.OnCompleted();
State = StreamState.Completed;
parent.OnCompleted();
}
}
}