.aar cleaned up, localized

This commit is contained in:
Kwoth 2017-02-14 16:55:59 +01:00
parent 8c27082c14
commit 45fb8b925d
3 changed files with 35 additions and 16 deletions

View File

@ -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<ulong, ulong> AutoAssignedRoles { get; }
private static ConcurrentDictionary<ulong, ulong> autoAssignedRoles { get; }
static AutoAssignRoleCommands()
{
_log = LogManager.GetCurrentClassLogger();
var log = LogManager.GetCurrentClassLogger();
AutoAssignedRoles = new ConcurrentDictionary<ulong, ulong>(NadekoBot.AllGuildConfigs.Where(x => x.AutoAssignRoleId != 0)
autoAssignedRoles = new ConcurrentDictionary<ulong, ulong>(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);
}
}
}

View File

@ -59,6 +59,24 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to **Auto assign role** on user join is now **disabled**..
/// </summary>
public static string administration_aar_disabled {
get {
return ResourceManager.GetString("administration_aar_disabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to **Auto assign role** on user join is now **enabled**..
/// </summary>
public static string administration_aar_enabled {
get {
return ResourceManager.GetString("administration_aar_enabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to I don&apos;t have the permission necessary for that most likely..
/// </summary>

View File

@ -298,6 +298,12 @@
<data name="pokemon_you_fainted" xml:space="preserve">
<value>You fainted, so you are not able to move!</value>
</data>
<data name="administration_aar_disabled" xml:space="preserve">
<value>**Auto assign role** on user join is now **disabled**.</value>
</data>
<data name="administration_aar_enabled" xml:space="preserve">
<value>**Auto assign role** on user join is now **enabled**.</value>
</data>
<data name="administration_mute_error" xml:space="preserve">
<value>I don't have the permission necessary for that most likely.</value>
</data>