self assigned role commands can now be localized :3

This commit is contained in:
Kwoth
2017-02-14 21:47:46 +01:00
parent 6ab8f26cd7
commit fd81b2de26
3 changed files with 199 additions and 32 deletions

View File

@@ -44,25 +44,30 @@ namespace NadekoBot.Modules.Administration
IEnumerable<SelfAssignedRole> roles;
string msg;
var error = false;
using (var uow = DbHandler.UnitOfWork())
{
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id);
if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.Guild.Id))
{
await Context.Channel.SendMessageAsync($"💢 Role **{role.Name}** is already in the list.").ConfigureAwait(false);
return;
msg = GetText("role_in_list", Format.Bold(role.Name));
error = true;
}
else
{
uow.SelfAssignedRoles.Add(new SelfAssignedRole {
uow.SelfAssignedRoles.Add(new SelfAssignedRole
{
RoleId = role.Id,
GuildId = role.Guild.Id
});
await uow.CompleteAsync();
msg = $"🆗 Role **{role.Name}** added to the list.";
msg = GetText("role_added", Format.Bold(role.Name));
}
}
await Context.Channel.SendConfirmAsync(msg.ToString()).ConfigureAwait(false);
if (error)
await Context.Channel.SendErrorAsync(msg).ConfigureAwait(false);
else
await Context.Channel.SendConfirmAsync(msg).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@@ -70,8 +75,6 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageRoles)]
public async Task Rsar([Remainder] IRole role)
{
//var channel = (ITextChannel)Context.Channel;
bool success;
using (var uow = DbHandler.UnitOfWork())
{
@@ -80,18 +83,16 @@ namespace NadekoBot.Modules.Administration
}
if (!success)
{
await Context.Channel.SendErrorAsync("❎ That role is not self-assignable.").ConfigureAwait(false);
await ReplyErrorLocalized("self_assign_not").ConfigureAwait(false);
return;
}
await Context.Channel.SendConfirmAsync($"🗑 **{role.Name}** has been removed from the list of self-assignable roles.").ConfigureAwait(false);
await ReplyConfirmLocalized("self_assign_rem", Format.Bold(role.Name)).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Lsar()
{
//var channel = (ITextChannel)Context.Channel;
var toRemove = new ConcurrentHashSet<SelfAssignedRole>();
var removeMsg = new StringBuilder();
var msg = new StringBuilder();
@@ -116,11 +117,11 @@ namespace NadekoBot.Modules.Administration
}
foreach (var role in toRemove)
{
removeMsg.AppendLine($"`{role.RoleId} not found. Cleaned up.`");
removeMsg.AppendLine(GetText("role_clean", role.RoleId));
}
await uow.CompleteAsync();
}
await Context.Channel.SendConfirmAsync($" There are `{roleCnt}` self assignable roles:", msg.ToString() + "\n\n" + removeMsg.ToString()).ConfigureAwait(false);
await Context.Channel.SendConfirmAsync(GetText("self_assign_list", roleCnt), msg + "\n\n" + removeMsg).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
@@ -128,8 +129,6 @@ namespace NadekoBot.Modules.Administration
[RequireUserPermission(GuildPermission.ManageRoles)]
public async Task Tesar()
{
//var channel = (ITextChannel)Context.Channel;
bool areExclusive;
using (var uow = DbHandler.UnitOfWork())
{
@@ -138,15 +137,16 @@ namespace NadekoBot.Modules.Administration
areExclusive = config.ExclusiveSelfAssignedRoles = !config.ExclusiveSelfAssignedRoles;
await uow.CompleteAsync();
}
string exl = areExclusive ? "**exclusive**." : "**not exclusive**.";
await Context.Channel.SendConfirmAsync(" Self assigned roles are now " + exl);
if(areExclusive)
await ReplyConfirmLocalized("self_assign_excl").ConfigureAwait(false);
else
await ReplyConfirmLocalized("self_assign_no_excl").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Iam([Remainder] IRole role)
{
//var channel = (ITextChannel)Context.Channel;
var guildUser = (IGuildUser)Context.User;
GuildConfig conf;
@@ -156,25 +156,24 @@ namespace NadekoBot.Modules.Administration
conf = uow.GuildConfigs.For(Context.Guild.Id, set => set);
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id);
}
SelfAssignedRole roleModel;
if ((roleModel = roles.FirstOrDefault(r=>r.RoleId == role.Id)) == null)
if (roles.FirstOrDefault(r=>r.RoleId == role.Id) == null)
{
await Context.Channel.SendErrorAsync("That role is not self-assignable.").ConfigureAwait(false);
await ReplyErrorLocalized("self_assign_not").ConfigureAwait(false);
return;
}
if (guildUser.RoleIds.Contains(role.Id))
{
await Context.Channel.SendErrorAsync($"You already have **{role.Name}** role.").ConfigureAwait(false);
await ReplyErrorLocalized("self_assign_already", Format.Bold(role.Name)).ConfigureAwait(false);
return;
}
if (conf.ExclusiveSelfAssignedRoles)
{
var sameRoleId = guildUser.RoleIds.Where(r => roles.Select(sar => sar.RoleId).Contains(r)).FirstOrDefault();
var sameRoleId = guildUser.RoleIds.FirstOrDefault(r => roles.Select(sar => sar.RoleId).Contains(r));
var sameRole = Context.Guild.GetRole(sameRoleId);
if (sameRoleId != default(ulong))
{
await Context.Channel.SendErrorAsync($"You already have **{sameRole?.Name}** `exclusive self-assigned` role.").ConfigureAwait(false);
await ReplyErrorLocalized("self_assign_already_excl", Format.Bold(sameRole?.Name)).ConfigureAwait(false);
return;
}
}
@@ -184,11 +183,11 @@ namespace NadekoBot.Modules.Administration
}
catch (Exception ex)
{
await Context.Channel.SendErrorAsync($"⚠️ I am unable to add that role to you. `I can't add roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false);
await ReplyErrorLocalized("self_assign_perms").ConfigureAwait(false);
Console.WriteLine(ex);
return;
}
var msg = await Context.Channel.SendConfirmAsync($"🆗 You now have **{role.Name}** role.").ConfigureAwait(false);
var msg = await ReplyConfirmLocalized("self_assign_success",Format.Bold(role.Name)).ConfigureAwait(false);
if (conf.AutoDeleteSelfAssignedRoleMessages)
{
@@ -210,15 +209,14 @@ namespace NadekoBot.Modules.Administration
autoDeleteSelfAssignedRoleMessages = uow.GuildConfigs.For(Context.Guild.Id, set => set).AutoDeleteSelfAssignedRoleMessages;
roles = uow.SelfAssignedRoles.GetFromGuild(Context.Guild.Id);
}
SelfAssignedRole roleModel;
if ((roleModel = roles.FirstOrDefault(r => r.RoleId == role.Id)) == null)
if (roles.FirstOrDefault(r => r.RoleId == role.Id) == null)
{
await Context.Channel.SendErrorAsync("💢 That role is not self-assignable.").ConfigureAwait(false);
await ReplyErrorLocalized("self_assign_not").ConfigureAwait(false);
return;
}
if (!guildUser.RoleIds.Contains(role.Id))
{
await Context.Channel.SendErrorAsync($"❎ You don't have **{role.Name}** role.").ConfigureAwait(false);
await ReplyErrorLocalized("self_assign_not_have",Format.Bold(role.Name)).ConfigureAwait(false);
return;
}
try
@@ -227,10 +225,10 @@ namespace NadekoBot.Modules.Administration
}
catch (Exception)
{
await Context.Channel.SendErrorAsync($"⚠️ I am unable to add that role to you. `I can't remove roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false);
await ReplyErrorLocalized("self_assign_perms").ConfigureAwait(false);
return;
}
var msg = await Context.Channel.SendConfirmAsync($"🆗 You no longer have **{role.Name}** role.").ConfigureAwait(false);
var msg = await ReplyConfirmLocalized("self_assign_remove", Format.Bold(role.Name)).ConfigureAwait(false);
if (autoDeleteSelfAssignedRoleMessages)
{