From 45fb8b925d6d9d695af1421d11e7330d4294bd41 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 14 Feb 2017 16:55:59 +0100 Subject: [PATCH] .aar cleaned up, localized --- .../Commands/AutoAssignRoleCommands.cs | 27 ++++++++----------- .../Resources/ResponseStrings.Designer.cs | 18 +++++++++++++ src/NadekoBot/Resources/ResponseStrings.resx | 6 +++++ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs index 3ebddf9d..98a8844f 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs @@ -1,13 +1,10 @@ using Discord; using Discord.Commands; using NadekoBot.Attributes; -using NadekoBot.Extensions; using NadekoBot.Services; -using NadekoBot.Services.Database.Models; using NLog; using System; using System.Collections.Concurrent; -using System.Diagnostics; using System.Linq; using System.Threading.Tasks; @@ -18,22 +15,21 @@ namespace NadekoBot.Modules.Administration [Group] public class AutoAssignRoleCommands : NadekoSubmodule { - private static Logger _log { get; } //guildid/roleid - private static ConcurrentDictionary AutoAssignedRoles { get; } + private static ConcurrentDictionary autoAssignedRoles { get; } static AutoAssignRoleCommands() { - _log = LogManager.GetCurrentClassLogger(); + var log = LogManager.GetCurrentClassLogger(); - AutoAssignedRoles = new ConcurrentDictionary(NadekoBot.AllGuildConfigs.Where(x => x.AutoAssignRoleId != 0) + autoAssignedRoles = new ConcurrentDictionary(NadekoBot.AllGuildConfigs.Where(x => x.AutoAssignRoleId != 0) .ToDictionary(k => k.GuildId, v => v.AutoAssignRoleId)); NadekoBot.Client.UserJoined += async (user) => { try { - ulong roleId = 0; - AutoAssignedRoles.TryGetValue(user.Guild.Id, out roleId); + ulong roleId; + autoAssignedRoles.TryGetValue(user.Guild.Id, out roleId); if (roleId == 0) return; @@ -43,7 +39,7 @@ namespace NadekoBot.Modules.Administration if (role != null) await user.AddRolesAsync(role).ConfigureAwait(false); } - catch (Exception ex) { _log.Warn(ex); } + catch (Exception ex) { log.Warn(ex); } }; } @@ -52,20 +48,19 @@ namespace NadekoBot.Modules.Administration [RequireUserPermission(GuildPermission.ManageRoles)] public async Task AutoAssignRole([Remainder] IRole role = null) { - GuildConfig conf; using (var uow = DbHandler.UnitOfWork()) { - conf = uow.GuildConfigs.For(Context.Guild.Id, set => set); + var conf = uow.GuildConfigs.For(Context.Guild.Id, set => set); if (role == null) { conf.AutoAssignRoleId = 0; ulong throwaway; - AutoAssignedRoles.TryRemove(Context.Guild.Id, out throwaway); + autoAssignedRoles.TryRemove(Context.Guild.Id, out throwaway); } else { conf.AutoAssignRoleId = role.Id; - AutoAssignedRoles.AddOrUpdate(Context.Guild.Id, role.Id, (key, val) => role.Id); + autoAssignedRoles.AddOrUpdate(Context.Guild.Id, role.Id, (key, val) => role.Id); } await uow.CompleteAsync().ConfigureAwait(false); @@ -73,11 +68,11 @@ namespace NadekoBot.Modules.Administration if (role == null) { - await Context.Channel.SendConfirmAsync("🆗 **Auto assign role** on user join is now **disabled**.").ConfigureAwait(false); + await ReplyConfirmLocalized("aar_disabled").ConfigureAwait(false); return; } - await Context.Channel.SendConfirmAsync("✅ **Auto assign role** on user join is now **enabled**.").ConfigureAwait(false); + await ReplyConfirmLocalized("aar_enabled").ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index 493016ee..7d27eaf2 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -59,6 +59,24 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to **Auto assign role** on user join is now **disabled**.. + /// + public static string administration_aar_disabled { + get { + return ResourceManager.GetString("administration_aar_disabled", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to **Auto assign role** on user join is now **enabled**.. + /// + public static string administration_aar_enabled { + get { + return ResourceManager.GetString("administration_aar_enabled", resourceCulture); + } + } + /// /// Looks up a localized string similar to I don't have the permission necessary for that most likely.. /// diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index 480a91f0..7eeb75f1 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -298,6 +298,12 @@ You fainted, so you are not able to move! + + **Auto assign role** on user join is now **disabled**. + + + **Auto assign role** on user join is now **enabled**. + I don't have the permission necessary for that most likely.