diff --git a/src/Bot/Bot.csproj b/src/Bot/Bot.csproj index 601766a..2d3cd2f 100644 --- a/src/Bot/Bot.csproj +++ b/src/Bot/Bot.csproj @@ -77,6 +77,10 @@ ResXFileCodeGenerator Quote.Designer.cs + + ResXFileCodeGenerator + Role.Designer.cs + @@ -127,5 +131,10 @@ True Quote.resx + + True + True + Role.resx + diff --git a/src/Bot/Commands/Admin/Role.cs b/src/Bot/Commands/Admin/Role.cs index e997fa8..c8459dd 100644 --- a/src/Bot/Commands/Admin/Role.cs +++ b/src/Bot/Commands/Admin/Role.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; using Discord.Net; +using Geekbot.Core; using Geekbot.Core.CommandPreconditions; using Geekbot.Core.Database; using Geekbot.Core.Database.Models; @@ -17,19 +18,15 @@ namespace Geekbot.Bot.Commands.Admin { [Group("role")] [DisableInDirectMessage] - public class Role : ModuleBase + public class Role : GeekbotCommandBase { private readonly DatabaseContext _database; - private readonly IErrorHandler _errorHandler; private readonly IReactionListener _reactionListener; - private readonly ITranslationHandler _translationHandler; - public Role(DatabaseContext database, IErrorHandler errorHandler, IReactionListener reactionListener, ITranslationHandler translationHandler) + public Role(DatabaseContext database, IErrorHandler errorHandler, IReactionListener reactionListener, ITranslationHandler translationHandler) : base(errorHandler, translationHandler) { _database = database; - _errorHandler = errorHandler; _reactionListener = reactionListener; - _translationHandler = translationHandler; } [Command(RunMode = RunMode.Async)] @@ -38,23 +35,22 @@ namespace Geekbot.Bot.Commands.Admin { try { - var transContext = await _translationHandler.GetGuildContext(Context); var roles = _database.RoleSelfService.Where(g => g.GuildId.Equals(Context.Guild.Id.AsLong())).ToList(); if (roles.Count == 0) { - await ReplyAsync(transContext.GetString("NoRolesConfigured")); + await ReplyAsync(Localization.Role.NoRolesConfigured); return; } var sb = new StringBuilder(); - sb.AppendLine(transContext.GetString("ListHeader", Context.Guild.Name)); - sb.AppendLine(transContext.GetString("ListInstruction")); + sb.AppendLine(string.Format(Localization.Role.ListHeader, Context.Guild.Name)); + sb.AppendLine(Localization.Role.ListInstruction); foreach (var role in roles) sb.AppendLine($"- {role.WhiteListName}"); await ReplyAsync(sb.ToString()); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -64,7 +60,6 @@ namespace Geekbot.Bot.Commands.Admin { try { - var transContext = await _translationHandler.GetGuildContext(Context); var roleName = roleNameRaw.ToLower(); var roleFromDb = _database.RoleSelfService.FirstOrDefault(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName)); @@ -74,31 +69,31 @@ namespace Geekbot.Bot.Commands.Admin var role = Context.Guild.Roles.First(r => r.Id == roleFromDb.RoleId.AsUlong()); if (role == null) { - await ReplyAsync(transContext.GetString("RoleNotFound")); + await ReplyAsync(Localization.Role.RoleNotFound); return; } if (guildUser.RoleIds.Contains(role.Id)) { await guildUser.RemoveRoleAsync(role); - await ReplyAsync(transContext.GetString("RemovedUserFromRole", role.Name)); + await ReplyAsync(string.Format(Localization.Role.RemovedUserFromRole, role.Name)); return; } await guildUser.AddRoleAsync(role); - await ReplyAsync(transContext.GetString("AddedUserFromRole", role.Name)); + await ReplyAsync(string.Format(Localization.Role.AddedUserFromRole, role.Name)); return; } - await ReplyAsync(transContext.GetString("RoleNotFound")); + await ReplyAsync(Localization.Role.RoleNotFound); } catch (HttpException e) { - await _errorHandler.HandleHttpException(e, Context); + await ErrorHandler.HandleHttpException(e, Context); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -109,10 +104,9 @@ namespace Geekbot.Bot.Commands.Admin { try { - var transContext = await _translationHandler.GetGuildContext(Context); if (role.IsManaged) { - await ReplyAsync(transContext.GetString("CannotAddManagedRole")); + await ReplyAsync(Localization.Role.CannotAddManagedRole); return; } @@ -122,7 +116,7 @@ namespace Geekbot.Bot.Commands.Admin || role.Permissions.BanMembers || role.Permissions.KickMembers) { - await ReplyAsync(transContext.GetString("CannotAddDangerousRole")); + await ReplyAsync(Localization.Role.CannotAddDangerousRole); return; } @@ -133,11 +127,11 @@ namespace Geekbot.Bot.Commands.Admin WhiteListName = roleName }); await _database.SaveChangesAsync(); - await ReplyAsync(transContext.GetString("AddedRoleToWhitelist", role.Name)); + await ReplyAsync(string.Format(Localization.Role.AddedRoleToWhitelist, role.Name)); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -148,22 +142,21 @@ namespace Geekbot.Bot.Commands.Admin { try { - var transContext = await _translationHandler.GetGuildContext(Context); var roleFromDb = _database.RoleSelfService.FirstOrDefault(e => e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName)); if (roleFromDb != null) { _database.RoleSelfService.Remove(roleFromDb); await _database.SaveChangesAsync(); - await ReplyAsync(transContext.GetString("RemovedRoleFromWhitelist", roleName)); + await ReplyAsync(string.Format(Localization.Role.RemovedRoleFromWhitelist, roleName)); return; } - await ReplyAsync(transContext.GetString("RoleNotFound")); + await ReplyAsync(Localization.Role.RoleNotFound); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } @@ -182,14 +175,13 @@ namespace Geekbot.Bot.Commands.Admin await _reactionListener.AddRoleToListener(messageId, Context.Guild.Id, emoji, role); await Context.Message.DeleteAsync(); } - catch (HttpException e) + catch (HttpException) { await Context.Channel.SendMessageAsync("Custom emojis from other servers are not supported"); - Console.WriteLine(e); } catch (Exception e) { - await _errorHandler.HandleCommandException(e, Context); + await ErrorHandler.HandleCommandException(e, Context); } } } diff --git a/src/Bot/Localization/Role.Designer.cs b/src/Bot/Localization/Role.Designer.cs new file mode 100644 index 0000000..9128e3d --- /dev/null +++ b/src/Bot/Localization/Role.Designer.cs @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Geekbot.Bot.Localization { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Role { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Role() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Geekbot.Bot.Localization.Role", typeof(Role).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Added {0} to the whitelist. + /// + internal static string AddedRoleToWhitelist { + get { + return ResourceManager.GetString("AddedRoleToWhitelist", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Added you to {0}. + /// + internal static string AddedUserFromRole { + get { + return ResourceManager.GetString("AddedUserFromRole", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You cannot add that role to self service because it contains one or more dangerous permissions. + /// + internal static string CannotAddDangerousRole { + get { + return ResourceManager.GetString("CannotAddDangerousRole", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You can't add a role that is managed by discord. + /// + internal static string CannotAddManagedRole { + get { + return ResourceManager.GetString("CannotAddManagedRole", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to **Self Service Roles on {0}**. + /// + internal static string ListHeader { + get { + return ResourceManager.GetString("ListHeader", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to To get a role, use `!role [name]`. + /// + internal static string ListInstruction { + get { + return ResourceManager.GetString("ListInstruction", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to There are no roles configured for this server. + /// + internal static string NoRolesConfigured { + get { + return ResourceManager.GetString("NoRolesConfigured", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Removed {0} from the whitelist. + /// + internal static string RemovedRoleFromWhitelist { + get { + return ResourceManager.GetString("RemovedRoleFromWhitelist", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Removed you from {0}. + /// + internal static string RemovedUserFromRole { + get { + return ResourceManager.GetString("RemovedUserFromRole", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to That role doesn't exist or is not on the whitelist. + /// + internal static string RoleNotFound { + get { + return ResourceManager.GetString("RoleNotFound", resourceCulture); + } + } + } +} diff --git a/src/Bot/Localization/Role.de-ch.resx b/src/Bot/Localization/Role.de-ch.resx new file mode 100644 index 0000000..b0b3259 --- /dev/null +++ b/src/Bot/Localization/Role.de-ch.resx @@ -0,0 +1,44 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Es sind kei rolle für dä server konfiguriert + + + **Self Service Rollene uf {0}** + + + Zum ä rolle becho, schriib `!role [name]` + + + Die rolle gids nid or isch nid uf dr whitelist + + + Han di entfernt vo {0} + + + Han di hinzue gfüegt zu {0} + + + Du chasch kei rolle hinzuefüge wo verwalted wird vo discord + + + Du chasch die rolle nid hinzuefüge will er ein oder mehreri gföhrlichi berechtigunge het + + + {0} isch zur whitelist hinzuegfüegt + + + {0} isch vo dr whitelist glöscht + + \ No newline at end of file diff --git a/src/Bot/Localization/Role.resx b/src/Bot/Localization/Role.resx new file mode 100644 index 0000000..63b70d0 --- /dev/null +++ b/src/Bot/Localization/Role.resx @@ -0,0 +1,51 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + There are no roles configured for this server + + + **Self Service Roles on {0}** + + + To get a role, use `!role [name]` + + + That role doesn't exist or is not on the whitelist + + + Removed you from {0} + + + Added you to {0} + + + You can't add a role that is managed by discord + + + You cannot add that role to self service because it contains one or more dangerous permissions + + + Added {0} to the whitelist + + + Removed {0} from the whitelist + + \ No newline at end of file diff --git a/src/Core/Localization/Translations.yml b/src/Core/Localization/Translations.yml index 678755d..dc18c2b 100644 --- a/src/Core/Localization/Translations.yml +++ b/src/Core/Localization/Translations.yml @@ -22,35 +22,4 @@ errorHandler: httpErrors: 403: EN: "Seems like i don't have enough permission to that :confused:" - CHDE: "Gseht danach us das ich nid gnueg recht han zum das mache :confused:" -role: - NoRolesConfigured: - EN: "There are no roles configured for this server" - CHDE: "Es sind kei rolle für dä server konfiguriert" - ListHeader: - EN: "**Self Service Roles on {0}**" - CHDE: "**Self Service Rollene uf {0}**" - ListInstruction: - EN: "To get a role, use `!role [name]`" - CHDE: "Zum ä rolle becho, schriib `!role [name]`" - RoleNotFound: - EN: "That role doesn't exist or is not on the whitelist" - CHDE: "Die rolle gids nid or isch nid uf dr whitelist" - RemovedUserFromRole: - EN: "Removed you from {0}" - CHDE: "Han di entfernt vo {0}" - AddedUserFromRole: - EN: "Added you to {0}" - CHDE: "Han di hinzue gfüegt zu {0}" - CannotAddManagedRole: - EN: "You can't add a role that is managed by discord" - CHDE: "Du chasch kei rolle hinzuefüge wo verwalted wird vo discord" - CannotAddDangerousRole: - EN: "You cannot add that role to self service because it contains one or more dangerous permissions" - CHDE: "Du chasch die rolle nid hinzuefüge will er ein oder mehreri gföhrlichi berechtigunge het" - AddedRoleToWhitelist: - EN: "Added {0} to the whitelist" - CHDE: "{0} isch zur whitelist hinzuegfüegt" - RemovedRoleFromWhitelist: - EN: "Removed {0} from the whitelist" - CHDE: "{0} isch vo dr whitelist glöscht" \ No newline at end of file + CHDE: "Gseht danach us das ich nid gnueg recht han zum das mache :confused:" \ No newline at end of file