From 0b09379bc5a7c28c99a40bea9e900ea7ab7a77e6 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 12 Oct 2016 23:41:31 +0200 Subject: [PATCH] A lot of bugfixes --- .../Modules/Administration/Administration.cs | 17 ++++++++++++ .../Commands/MessageRepeater.cs | 2 +- .../Games/Commands/PlantAndPickCommands.cs | 2 +- .../Games/Commands/Trivia/TriviaGame.cs | 16 ++++++++--- .../Commands/StreamNotificationCommands.cs | 2 +- .../Resources/CommandStrings.Designer.cs | 27 +++++++++++++++++++ src/NadekoBot/Resources/CommandStrings.resx | 9 +++++++ 7 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 0231f8d4..de1c466f 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -50,6 +50,23 @@ namespace NadekoBot.Modules.Administration } } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequirePermission(GuildPermission.Administrator)] + public async Task ResetPermissions(IUserMessage imsg) + { + var channel = (ITextChannel)imsg.Channel; + + using (var uow = DbHandler.UnitOfWork()) + { + var config = uow.GuildConfigs.PermissionsFor(channel.Guild.Id); + config.RootPermission = Permission.GetDefaultRoot(); + await uow.CompleteAsync(); + } + + await channel.SendMessageAsync($"{imsg.Author.Mention} :ok: `Permissions for this server are reset`"); + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [OwnerOnly] diff --git a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index 0a7ba01d..501de4f2 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Administration while (!token.IsCancellationRequested) { await Task.Delay(Repeater.Interval, token).ConfigureAwait(false); - try { await Channel.SendMessageAsync("🔄 " + Repeater.Message).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } + try { await Channel.SendMessageAsync("🔄 " + Repeater.Message).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); try { source.Cancel(); } catch { } } } } catch (OperationCanceledException) { } diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index 2b8d8072..c6ab6c12 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Games IUserMessage msg; var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(Gambling.Gambling.CurrencyName[0]); - var msgToSend = $"Oh how Nice! **{imsg.Author.Username}** planted {(vowelFirst ? "an" : "a")} {Gambling.Gambling.CurrencyName}. Pick it using {NadekoBot.ModulePrefixes[typeof(Gambling.Gambling).Name]}pick"; + var msgToSend = $"Oh how Nice! **{imsg.Author.Username}** planted {(vowelFirst ? "an" : "a")} {Gambling.Gambling.CurrencyName}. Pick it using {NadekoBot.ModulePrefixes[typeof(Games).Name]}pick"; if (file == null) { msg = await channel.SendMessageAsync(Gambling.Gambling.CurrencySign).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs index 2356a6a7..de1c3262 100644 --- a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs @@ -1,4 +1,5 @@ using Discord; +using Discord.Net; using NadekoBot.Extensions; using NLog; using System; @@ -61,7 +62,12 @@ namespace NadekoBot.Modules.Games.Trivia } oldQuestions.Add(CurrentQuestion); //add it to exclusion list so it doesn't show up again //sendquestion - try { await channel.SendMessageAsync($":question: **{CurrentQuestion.Question}**").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } + try { await channel.SendMessageAsync($":question: **{CurrentQuestion.Question}**").ConfigureAwait(false); } + catch (HttpException ex) when (ex.StatusCode == System.Net.HttpStatusCode.Forbidden) + { + break; + } + catch (Exception ex) { _log.Warn(ex); } //receive messages NadekoBot.Client.MessageReceived += PotentialGuess; @@ -88,13 +94,15 @@ namespace NadekoBot.Modules.Games.Trivia // load next question if game is still running await Task.Delay(2000).ConfigureAwait(false); } + try { NadekoBot.Client.MessageReceived -= PotentialGuess; } catch { } + GameActive = false; await End().ConfigureAwait(false); } private async Task End() { ShouldStopGame = true; - await channel.SendMessageAsync("**Trivia game ended**\n" + GetLeaderboard()).ConfigureAwait(false); + try { await channel.SendMessageAsync("**Trivia game ended**\n" + GetLeaderboard()).ConfigureAwait(false); } catch { } } public async Task StopGame() @@ -127,7 +135,7 @@ namespace NadekoBot.Modules.Games.Trivia { if (GameActive && CurrentQuestion.IsAnswerCorrect(umsg.Content) && !triviaCancelSource.IsCancellationRequested) { - Users.AddOrUpdate(guildUser, 0, (gu, old) => old++); + Users.AddOrUpdate(guildUser, 1, (gu, old) => ++old); guess = true; } } @@ -152,7 +160,7 @@ namespace NadekoBot.Modules.Games.Trivia var sb = new StringBuilder(); sb.Append("**Leaderboard:**\n-----------\n"); - foreach (var kvp in Users.OrderBy(kvp => kvp.Value)) + foreach (var kvp in Users.OrderByDescending(kvp => kvp.Value)) { sb.AppendLine($"**{kvp.Key.Username}** has {kvp.Value} points".ToString().SnPl(kvp.Value)); } diff --git a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs index 6abf08c4..eddc41d6 100644 --- a/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/StreamNotificationCommands.cs @@ -44,7 +44,7 @@ namespace NadekoBot.Modules.Searches checkTimer = new Timer(async (state) => { oldCachedStatuses = new ConcurrentDictionary(cachedStatuses); - cachedStatuses.Clear(); + cachedStatuses = new ConcurrentDictionary(); try { IEnumerable streams; diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index a2cfaeac..aa85279f 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -5270,6 +5270,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to resetperms. + /// + public static string resetpermissions_cmd { + get { + return ResourceManager.GetString("resetpermissions_cmd", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Resets BOT's permissions module on this server to the default value.. + /// + public static string resetpermissions_desc { + get { + return ResourceManager.GetString("resetpermissions_desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to `.resetperms`. + /// + public static string resetpermissions_usage { + get { + return ResourceManager.GetString("resetpermissions_usage", resourceCulture); + } + } + /// /// Looks up a localized string similar to restart. /// diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index d9de35da..3072d75f 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2637,4 +2637,13 @@ `.fwtoall` + + resetperms + + + Resets BOT's permissions module on this server to the default value. + + + `.resetperms` + \ No newline at end of file