diff --git a/NadekoBot/Classes/Extensions.cs b/NadekoBot/Classes/Extensions.cs index 3dabae36..0d9edbbe 100644 --- a/NadekoBot/Classes/Extensions.cs +++ b/NadekoBot/Classes/Extensions.cs @@ -44,6 +44,20 @@ namespace NadekoBot.Extensions { return str; return string.Join("", str.Take(num - 3)) + "..."; } + /// + /// Removes trailing S or ES (if specified) on the given string if the num is 1 + /// + /// + /// + /// + /// String with the correct singular/plural form + 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; + } /// /// Sends a message to the channel from which this command is called. diff --git a/NadekoBot/Classes/Music/MusicControls.cs b/NadekoBot/Classes/Music/MusicControls.cs index 0bb46677..c9265cea 100644 --- a/NadekoBot/Classes/Music/MusicControls.cs +++ b/NadekoBot/Classes/Music/MusicControls.cs @@ -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(); diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index 843fe68f..ce60ec6c 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -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(); } } } diff --git a/NadekoBot/Modules/Conversations.cs b/NadekoBot/Modules/Conversations.cs index 54aa3628..40d0a92a 100644 --- a/NadekoBot/Modules/Conversations.cs +++ b/NadekoBot/Modules/Conversations.cs @@ -222,17 +222,14 @@ namespace NadekoBot.Modules { }); cgb.CreateCommand("rip") - .Description("Shows a grave image.Optional parameter [@X] instructs her to put X's name on the grave.\n**Usage**: @NadekoBot rip [@X]") - .Parameter("user", ParameterType.Unparsed) + .Description("Shows a grave image of someone with a start year\n**Usage**: @NadekoBot rip @Someone 2000") + .Parameter("user", ParameterType.Optional) + .Parameter("year", ParameterType.Optional) .Do(async e => { var usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault(); string text = ""; - if (usr == null) { - text = e.GetArg("user"); - } else { - text = usr.Name; - } - await e.Channel.SendFile("ripzor_m8.png", RipName(text)); + text = usr?.Name; + await e.Channel.SendFile("ripzor_m8.png", RipName(text, e.GetArg("year") == "" ? null : e.GetArg("year"))); }); cgb.CreateCommand("j") @@ -324,7 +321,7 @@ namespace NadekoBot.Modules { .Do(async e => { string str = "Bye"; foreach (var u in e.Message.MentionedUsers) { - if(u.Id != NadekoBot.client.CurrentUser.Id) + if (u.Id != NadekoBot.client.CurrentUser.Id) str += " " + u.Mention; } await e.Send(str); @@ -406,7 +403,7 @@ namespace NadekoBot.Modules { }); } - public Stream RipName(string name) { + public Stream RipName(string name, string year = null) { Bitmap bm = Resources.rip; int offset = name.Length * 5; @@ -420,7 +417,7 @@ namespace NadekoBot.Modules { //TODO use measure string Graphics g = Graphics.FromImage(bm); g.DrawString(name, new Font("Comic Sans MS", fontSize, FontStyle.Bold), Brushes.Black, 100 - offset, 200); - g.DrawString("? - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 235); + g.DrawString((year == null ? "?" : year) + " - " + DateTime.Now.Year, new Font("Consolas", 12, FontStyle.Bold), Brushes.Black, 80, 235); g.Flush(); g.Dispose(); diff --git a/NadekoBot/Modules/Music.cs b/NadekoBot/Modules/Music.cs index aa2e5f4f..78b80dbc 100644 --- a/NadekoBot/Modules/Music.cs +++ b/NadekoBot/Modules/Music.cs @@ -14,11 +14,9 @@ namespace NadekoBot.Modules { public static ConcurrentDictionary musicPlayers = new ConcurrentDictionary(); internal static string GetMusicStats() { - var servers = 0; - var queued = 0; var stats = musicPlayers.Where(kvp => kvp.Value?.SongQueue.Count > 0 || kvp.Value?.CurrentSong != null); - - return $"Playing {stats.Count()} songs, {stats.Sum(kvp => kvp.Value?.SongQueue?.Count ?? 0)} queued."; + int cnt; + return $"Playing {cnt = stats.Count()} songs".SnPl(cnt)+$", {stats.Sum(kvp => kvp.Value?.SongQueue?.Count ?? 0)} queued."; } public Music() : base() { @@ -164,6 +162,25 @@ namespace NadekoBot.Modules { player.SongQueue.Shuffle(); await e.Send(":musical_note: Songs shuffled!"); }); + bool setgameEnabled = false; + Timer setgameTimer = new Timer(); + setgameTimer.Interval = 20000; + setgameTimer.Elapsed += (s, e) => { + int num = musicPlayers.Count; + NadekoBot.client.SetGame($"{num} songs".SnPl(num) + $", {musicPlayers.Sum(kvp => kvp.Value.SongQueue.Count())} queued"); + }; + setgameTimer.Start(); + cgb.CreateCommand("setgame") + .Description("Sets the game of the bot to the number of songs playing.**Owner only**") + .Do(e => { + if (NadekoBot.OwnerID != e.User.Id) + return; + setgameEnabled = !setgameEnabled; + if (setgameEnabled) + setgameTimer.Start(); + else + setgameTimer.Stop(); + }); }); } } diff --git a/NadekoBot/Modules/Searches.cs b/NadekoBot/Modules/Searches.cs index 7849e3f3..391abd49 100644 --- a/NadekoBot/Modules/Searches.cs +++ b/NadekoBot/Modules/Searches.cs @@ -225,13 +225,17 @@ namespace NadekoBot.Modules Console.WriteLine("ERROR: No google api key found. Playing `Never gonna give you up`."); return @"https://www.youtube.com/watch?v=dQw4w9WgXcQ"; } - WebRequest wr = WebRequest.Create("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=" + Uri.EscapeDataString(v) + "&key=" + NadekoBot.GoogleAPIKey); + try { + WebRequest wr = WebRequest.Create("https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&q=" + Uri.EscapeDataString(v) + "&key=" + NadekoBot.GoogleAPIKey); - var sr = new StreamReader(wr.GetResponse().GetResponseStream()); + var sr = new StreamReader(wr.GetResponse().GetResponseStream()); - dynamic obj = JObject.Parse(sr.ReadToEnd()); - string toReturn = "http://www.youtube.com/watch?v=" + obj.items[0].id.videoId.ToString(); - return toReturn; + dynamic obj = JObject.Parse(sr.ReadToEnd()); + string toReturn = "http://www.youtube.com/watch?v=" + obj.items[0].id.videoId.ToString(); + return toReturn; + } catch (Exception) { + return string.Empty; + } } public string GetDanbooruImageLink(string tag) { diff --git a/NadekoBot/bin/Debug/Discord.Net.Audio.dll b/NadekoBot/bin/Debug/Discord.Net.Audio.dll index 70d90c60..b7a91876 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 21052e89..5ba96c97 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 320bdbbe..560dd90d 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 74b454aa..0cf035ad 100644 Binary files a/NadekoBot/bin/Debug/Discord.Net.dll and b/NadekoBot/bin/Debug/Discord.Net.dll differ