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 diff --git a/src/NadekoBot/Modules/Administration/AdministrationModule.cs b/src/NadekoBot/Modules/Administration/AdministrationModule.cs index 05011cba..b6f14069 100644 --- a/src/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/src/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -23,7 +23,6 @@ namespace NadekoBot.Modules.Administration { } - ////todo owner only //[LocalizedCommand, LocalizedDescription, LocalizedSummary] //[RequireContext(ContextType.Guild)] @@ -445,6 +444,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; @@ -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) 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/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); } } diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 4c5cadb9..baf8c8c1 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -59,8 +59,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 7d26f6bb..f3fad253 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 @@ -105,7 +104,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/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 0b825b55..a8c4f80f 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; } @@ -35,6 +35,8 @@ namespace NadekoBot.Services.Impl Token = cm.Token; OwnerIds = cm.OwnerIds; LoLApiKey = cm.LoLApiKey; + GoogleApiKey = cm.GoogleApiKey; + MashapeKey = cm.MashapeKey; } else _log.Fatal("credentials.json is missing. Failed to start."); @@ -44,6 +46,8 @@ 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 string MashapeKey { get; set; } } public bool IsOwner(IUser u) => OwnerIds.Contains(u.Id); 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) diff --git a/src/NadekoBot/Services/Impl/YoutubeService.cs b/src/NadekoBot/Services/Impl/YoutubeService.cs index 31655950..94290894 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) @@ -39,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) @@ -56,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; 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 = "") {