From 5d37d4529dfc9de4fd39ef4047e643f80f9a321a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 00:31:00 +0200 Subject: [PATCH 01/10] Fixed prune by removing cache? Fixed error on ~yt by removing contracts? --- .../Modules/Administration/AdministrationModule.cs | 7 +++++++ src/NadekoBot/NadekoBot.cs | 1 - src/NadekoBot/Services/Impl/YoutubeService.cs | 10 ++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/AdministrationModule.cs b/src/NadekoBot/Modules/Administration/AdministrationModule.cs index 05011cba..29e2132d 100644 --- a/src/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/src/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -23,7 +23,13 @@ namespace NadekoBot.Modules.Administration { } + [LocalizedCommand, LocalizedDescription, LocalizedSummary] + [RequireContext(ContextType.Guild)] + public async Task cmd(IMessage imsg, [Remainder] string arg) + { + var channel = imsg.Channel as ITextChannel; + } ////todo owner only //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] @@ -445,6 +451,7 @@ namespace NadekoBot.Modules.Administration public async Task Prune(IMessage msg, int count) { var channel = msg.Channel as ITextChannel; + await msg.DeleteAsync(); while (count > 0) { int limit = (count < 100) ? count : 100; diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index c9ea9c23..9131238e 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -36,7 +36,6 @@ namespace NadekoBot AudioMode = Discord.Audio.AudioMode.Incoming, LargeThreshold = 200, LogLevel = LogSeverity.Warning, - MessageCacheSize = 10, }); //initialize Services diff --git a/src/NadekoBot/Services/Impl/YoutubeService.cs b/src/NadekoBot/Services/Impl/YoutubeService.cs index 31655950..bcc44fa2 100644 --- a/src/NadekoBot/Services/Impl/YoutubeService.cs +++ b/src/NadekoBot/Services/Impl/YoutubeService.cs @@ -22,8 +22,14 @@ namespace NadekoBot.Services.Impl } public async Task> FindPlaylistIdsByKeywordsAsync(string keywords, int count = 1) { - Contract.Requires(!string.IsNullOrWhiteSpace(keywords)); - Contract.Requires(count > 0); + //Contract.Requires(!string.IsNullOrWhiteSpace(keywords)); + //Contract.Requires(count > 0); + + if (string.IsNullOrWhiteSpace(keywords)) + throw new ArgumentNullException(nameof(keywords)); + + if (count <= 0) + throw new ArgumentOutOfRangeException(nameof(count)); var match = new Regex("(?:youtu\\.be\\/|list=)(?[\\da-zA-Z\\-_]*)").Match(keywords); if (match.Length > 1) From 3e4ce6ad236568eb061c2b45b82e8a339721dd01 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 00:35:42 +0200 Subject: [PATCH 02/10] Fixed ~chucknorris --- src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs b/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs index 03e5363b..c9c89d33 100644 --- a/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs @@ -73,8 +73,8 @@ namespace NadekoBot.Modules.Searches var channel = imsg.Channel as ITextChannel; using (var http = new HttpClient()) { - var response = await http.GetStringAsync("http://tambal.azurewebsites.net/joke/random").ConfigureAwait(false); - await channel.SendMessageAsync("`" + JObject.Parse(response)["joke"].ToString() + "` 😆").ConfigureAwait(false); + var response = await http.GetStringAsync("http://api.icndb.com/jokes/random/").ConfigureAwait(false); + await channel.SendMessageAsync("`" + JObject.Parse(response)["value"]["joke"].ToString() + "` 😆").ConfigureAwait(false); } } From 30fde5fa83e6109d2c03686c55c107faf41719f7 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 00:41:15 +0200 Subject: [PATCH 03/10] Fixed ~yt definitely? --- src/NadekoBot/Services/Impl/YoutubeService.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/NadekoBot/Services/Impl/YoutubeService.cs b/src/NadekoBot/Services/Impl/YoutubeService.cs index bcc44fa2..94290894 100644 --- a/src/NadekoBot/Services/Impl/YoutubeService.cs +++ b/src/NadekoBot/Services/Impl/YoutubeService.cs @@ -45,8 +45,11 @@ namespace NadekoBot.Services.Impl public async Task> FindRelatedVideosAsync(string id, int count = 1) { - Contract.Requires(!string.IsNullOrWhiteSpace(id)); - Contract.Requires(count > 0); + if (string.IsNullOrWhiteSpace(id)) + throw new ArgumentNullException(nameof(id)); + + if (count <= 0) + throw new ArgumentOutOfRangeException(nameof(count)); var match = new Regex("(?:youtu\\.be\\/|v=)(?[\\da-zA-Z\\-_]*)").Match(id); if (match.Length > 1) @@ -62,8 +65,11 @@ namespace NadekoBot.Services.Impl public async Task> FindVideosByKeywordsAsync(string keywords, int count = 1) { - Contract.Requires(!string.IsNullOrWhiteSpace(keywords)); - Contract.Requires(count > 0); + if (string.IsNullOrWhiteSpace(keywords)) + throw new ArgumentNullException(nameof(keywords)); + + if (count <= 0) + throw new ArgumentOutOfRangeException(nameof(count)); var query = yt.Search.List("snippet"); query.MaxResults = count; From 9e158b53b0de7cdbae9b12459e87601cfb7769ac Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 00:47:39 +0200 Subject: [PATCH 04/10] Now properly loading youtubeapikey from credentials --- src/NadekoBot/Modules/Searches/Searches.cs | 3 +-- src/NadekoBot/NadekoBot.cs | 2 +- src/NadekoBot/Services/Impl/BotCredentials.cs | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index ed3d1015..76d4bdb8 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -60,8 +60,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】 await channel.SendMessageAsync("No results found for that query."); return; } - var shortUrl = await result.ShortenUrl().ConfigureAwait(false); - await channel.SendMessageAsync(shortUrl).ConfigureAwait(false); + await channel.SendMessageAsync(result).ConfigureAwait(false); } [LocalizedCommand, LocalizedDescription, LocalizedSummary] diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index 9131238e..f5719829 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -101,7 +101,7 @@ namespace NadekoBot } else if (!t.IsSuccess && t.Error != CommandError.UnknownCommand) { - _log.Warn("Command errored!\n\tFull Message: {0}\n\tError:{1}", imsg.Content, t.Error); + _log.Warn("Command errored!\n\tFull Message: {0}\n\tError:{1}", imsg.Content, t.ErrorReason); } }); diff --git a/src/NadekoBot/Services/Impl/BotCredentials.cs b/src/NadekoBot/Services/Impl/BotCredentials.cs index 2f4b5f6a..081c0555 100644 --- a/src/NadekoBot/Services/Impl/BotCredentials.cs +++ b/src/NadekoBot/Services/Impl/BotCredentials.cs @@ -34,6 +34,7 @@ namespace NadekoBot.Services.Impl Token = cm.Token; OwnerIds = cm.OwnerIds; LoLApiKey = cm.LoLApiKey; + GoogleApiKey = cm.GoogleApiKey; } else _log.Fatal("credentials.json is missing. Failed to start."); @@ -43,6 +44,7 @@ namespace NadekoBot.Services.Impl public string Token { get; set; } public ulong[] OwnerIds { get; set; } public string LoLApiKey { get; set; } + public string GoogleApiKey { get; set; } } public bool IsOwner(IUser u) => OwnerIds.Contains(u.Id); From 5600afe96adc5eb4613491935f475f552e6e0eed Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 00:53:41 +0200 Subject: [PATCH 05/10] Mashape key now loading, ~# and ~ud sould work --- src/NadekoBot/Services/Impl/BotCredentials.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/NadekoBot/Services/Impl/BotCredentials.cs b/src/NadekoBot/Services/Impl/BotCredentials.cs index 081c0555..405f4f2e 100644 --- a/src/NadekoBot/Services/Impl/BotCredentials.cs +++ b/src/NadekoBot/Services/Impl/BotCredentials.cs @@ -35,6 +35,7 @@ namespace NadekoBot.Services.Impl OwnerIds = cm.OwnerIds; LoLApiKey = cm.LoLApiKey; GoogleApiKey = cm.GoogleApiKey; + MashapeKey = cm.MashapeKey; } else _log.Fatal("credentials.json is missing. Failed to start."); @@ -45,6 +46,7 @@ namespace NadekoBot.Services.Impl public ulong[] OwnerIds { get; set; } public string LoLApiKey { get; set; } public string GoogleApiKey { get; set; } + public IEnumerable MashapeKey { get; set; } } public bool IsOwner(IUser u) => OwnerIds.Contains(u.Id); From 7cfb04cdfab713ad9ab1d36c7dd5e7335943dd6a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 01:01:50 +0200 Subject: [PATCH 06/10] Fixed mashape api key loading --- src/NadekoBot/Services/IBotCredentials.cs | 2 +- src/NadekoBot/Services/Impl/BotCredentials.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Services/IBotCredentials.cs b/src/NadekoBot/Services/IBotCredentials.cs index e298c5b1..d5a27306 100644 --- a/src/NadekoBot/Services/IBotCredentials.cs +++ b/src/NadekoBot/Services/IBotCredentials.cs @@ -10,7 +10,7 @@ namespace NadekoBot.Services string Token { get; } string GoogleApiKey { get; } ulong[] OwnerIds { get; } - IEnumerable MashapeKey { get; } + string MashapeKey { get; } string LoLApiKey { get; } bool IsOwner(IUser u); diff --git a/src/NadekoBot/Services/Impl/BotCredentials.cs b/src/NadekoBot/Services/Impl/BotCredentials.cs index 405f4f2e..d06a0cbb 100644 --- a/src/NadekoBot/Services/Impl/BotCredentials.cs +++ b/src/NadekoBot/Services/Impl/BotCredentials.cs @@ -17,7 +17,7 @@ namespace NadekoBot.Services.Impl public string GoogleApiKey { get; } - public IEnumerable MashapeKey { get; } + public string MashapeKey { get; } public string Token { get; } @@ -46,7 +46,7 @@ namespace NadekoBot.Services.Impl public ulong[] OwnerIds { get; set; } public string LoLApiKey { get; set; } public string GoogleApiKey { get; set; } - public IEnumerable MashapeKey { get; set; } + public string MashapeKey { get; set; } } public bool IsOwner(IUser u) => OwnerIds.Contains(u.Id); From e7b6f110a39068b3f521baa4fa4660f418a7424a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 03:06:40 +0200 Subject: [PATCH 07/10] Updated discord.net, fixes to parser --- discord.net | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord.net b/discord.net index 06184c1a..fa06826f 160000 --- a/discord.net +++ b/discord.net @@ -1 +1 @@ -Subproject commit 06184c1a655232beedd608a8b0190ca2c70b9b23 +Subproject commit fa06826f92fd020f2af5f48aa25784d10239f668 From 57a2caef842e51cfa70b4d984b1c224d44ac1163 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 03:35:28 +0200 Subject: [PATCH 08/10] Fixed raffle --- .../Modules/Administration/Commands/RatelimitCommand.cs | 2 +- src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs | 2 +- src/NadekoBot/Modules/Gambling/Gambling.cs | 2 +- src/NadekoBot/_Extensions/Extensions.cs | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs index 18f67780..c7864d46 100644 --- a/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs @@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Administration { var channel = imsg.Channel as ITextChannel; - if (channel == null || await imsg.IsAuthor(_client)) + if (channel == null || await imsg.IsAuthor()) return; ConcurrentDictionary userTimePair; if (!RatelimitingChannels.TryGetValue(channel.Id, out userTimePair)) return; diff --git a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs index 72538677..b5e36bb7 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs @@ -196,7 +196,7 @@ namespace NadekoBot.Modules.Gambling private async Task Client_MessageReceived(IMessage imsg) { - if (await imsg.IsAuthor(NadekoBot.Client) || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel) + if (await imsg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel) return; messagesSinceGameStarted++; } diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index c7d2677c..59e8833f 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Gambling role = role ?? channel.Guild.EveryoneRole; - var members = (await role.Members()).Where(u => u.Status == UserStatus.Online); + var members = role.Members().Where(u => u.Status == UserStatus.Online); var membersArray = members as IUser[] ?? members.ToArray(); var usr = membersArray[new Random().Next(0, membersArray.Length)]; await channel.SendMessageAsync($"**Raffled user:** {usr.Username} (id: {usr.Id})").ConfigureAwait(false); diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 63c44a7d..aef5da9b 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -26,11 +26,11 @@ namespace NadekoBot.Extensions public static async Task Reply(this IMessage msg, string content) => await msg.Channel.SendMessageAsync(content).ConfigureAwait(false); - public static Task IsAuthor(this IMessage msg, DiscordSocketClient client) => - Task.FromResult(client.GetCurrentUser().Id == msg.Author.Id); + public static Task IsAuthor(this IMessage msg) => + Task.FromResult(NadekoBot.Client.GetCurrentUser().Id == msg.Author.Id); - public static async Task> Members(this IRole role) => - await role.Members(); + public static IEnumerable Members(this IRole role) => + NadekoBot.Client.GetGuilds().Where(g => g.Id == role.GuildId).FirstOrDefault()?.GetUsers().Where(u => u.Roles.Contains(role)) ?? Enumerable.Empty(); public static async Task ReplyLong(this IMessage msg, string content, string breakOn = "\n", string addToEnd = "", string addToStart = "") { From 8271bf41d6ff1e678a6d1ba83660a67808fb30a7 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 03:44:09 +0200 Subject: [PATCH 09/10] Small fix/debug --- .../Administration/AdministrationModule.cs | 7 ------- src/NadekoBot/Services/Impl/Localization.cs | 21 +++---------------- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/AdministrationModule.cs b/src/NadekoBot/Modules/Administration/AdministrationModule.cs index 29e2132d..b03d287e 100644 --- a/src/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/src/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -22,13 +22,6 @@ namespace NadekoBot.Modules.Administration public Administration(ILocalization loc, CommandService cmds, IBotConfiguration config, DiscordSocketClient client) : base(loc, cmds, config, client) { - } - [LocalizedCommand, LocalizedDescription, LocalizedSummary] - [RequireContext(ContextType.Guild)] - public async Task cmd(IMessage imsg, [Remainder] string arg) - { - var channel = imsg.Channel as ITextChannel; - } ////todo owner only //[LocalizedCommand, LocalizedDescription, LocalizedSummary] diff --git a/src/NadekoBot/Services/Impl/Localization.cs b/src/NadekoBot/Services/Impl/Localization.cs index 719274b6..7be58e16 100644 --- a/src/NadekoBot/Services/Impl/Localization.cs +++ b/src/NadekoBot/Services/Impl/Localization.cs @@ -4,27 +4,12 @@ namespace NadekoBot.Services { public class Localization : ILocalization { - public string this[string key] { - get { - try - { - return Resources.ResponseStrings.ResourceManager.GetString(key); - } - catch (Exception) { - return key; - } - } - } + public string this[string key] => LoadCommandString(key); public static string LoadCommandString(string key) { - try - { - return Resources.CommandStrings.ResourceManager.GetString(key); - } - catch (Exception) { - return key; - } + string toReturn = Resources.CommandStrings.ResourceManager.GetString(key); + return string.IsNullOrWhiteSpace(toReturn) ? key : toReturn; } //private static string GetCommandString(string key) From 09ff6aefb7988b45f74e673dbe84c1ecf2373887 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 21 Aug 2016 04:34:26 +0200 Subject: [PATCH 10/10] Mentionrole is now mentioning once again --- src/NadekoBot/Modules/Administration/AdministrationModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Administration/AdministrationModule.cs b/src/NadekoBot/Modules/Administration/AdministrationModule.cs index b03d287e..b6f14069 100644 --- a/src/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/src/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -646,7 +646,7 @@ namespace NadekoBot.Modules.Administration foreach (var role in roles) { send += $"\n`{role.Name}`\n"; - send += string.Join(", ", (await channel.Guild.GetUsersAsync()).Where(u => u.Roles.Contains(role)).Distinct()); + send += string.Join(", ", (await channel.Guild.GetUsersAsync()).Where(u => u.Roles.Contains(role)).Distinct().Select(u=>u.Mention)); } while (send.Length > 2000)