Convert Role command to new localization method
This commit is contained in:
parent
90af781c7b
commit
078c884df7
6 changed files with 280 additions and 62 deletions
|
@ -77,6 +77,10 @@
|
|||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Quote.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Update="Localization\Role.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Role.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Localization\Ship.Designer.cs">
|
||||
|
@ -127,5 +131,10 @@
|
|||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Quote.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Localization\Role.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Role.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
153
src/Bot/Localization/Role.Designer.cs
generated
Normal file
153
src/Bot/Localization/Role.Designer.cs
generated
Normal file
|
@ -0,0 +1,153 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Geekbot.Bot.Localization {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// 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() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Added {0} to the whitelist.
|
||||
/// </summary>
|
||||
internal static string AddedRoleToWhitelist {
|
||||
get {
|
||||
return ResourceManager.GetString("AddedRoleToWhitelist", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Added you to {0}.
|
||||
/// </summary>
|
||||
internal static string AddedUserFromRole {
|
||||
get {
|
||||
return ResourceManager.GetString("AddedUserFromRole", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You cannot add that role to self service because it contains one or more dangerous permissions.
|
||||
/// </summary>
|
||||
internal static string CannotAddDangerousRole {
|
||||
get {
|
||||
return ResourceManager.GetString("CannotAddDangerousRole", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You can't add a role that is managed by discord.
|
||||
/// </summary>
|
||||
internal static string CannotAddManagedRole {
|
||||
get {
|
||||
return ResourceManager.GetString("CannotAddManagedRole", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to **Self Service Roles on {0}**.
|
||||
/// </summary>
|
||||
internal static string ListHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("ListHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to To get a role, use `!role [name]`.
|
||||
/// </summary>
|
||||
internal static string ListInstruction {
|
||||
get {
|
||||
return ResourceManager.GetString("ListInstruction", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to There are no roles configured for this server.
|
||||
/// </summary>
|
||||
internal static string NoRolesConfigured {
|
||||
get {
|
||||
return ResourceManager.GetString("NoRolesConfigured", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Removed {0} from the whitelist.
|
||||
/// </summary>
|
||||
internal static string RemovedRoleFromWhitelist {
|
||||
get {
|
||||
return ResourceManager.GetString("RemovedRoleFromWhitelist", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Removed you from {0}.
|
||||
/// </summary>
|
||||
internal static string RemovedUserFromRole {
|
||||
get {
|
||||
return ResourceManager.GetString("RemovedUserFromRole", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to That role doesn't exist or is not on the whitelist.
|
||||
/// </summary>
|
||||
internal static string RoleNotFound {
|
||||
get {
|
||||
return ResourceManager.GetString("RoleNotFound", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
src/Bot/Localization/Role.de-ch.resx
Normal file
44
src/Bot/Localization/Role.de-ch.resx
Normal file
|
@ -0,0 +1,44 @@
|
|||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>1.3</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="NoRolesConfigured" xml:space="preserve">
|
||||
<value>Es sind kei rolle für dä server konfiguriert</value>
|
||||
</data>
|
||||
<data name="ListHeader" xml:space="preserve">
|
||||
<value>**Self Service Rollene uf {0}**</value>
|
||||
</data>
|
||||
<data name="ListInstruction" xml:space="preserve">
|
||||
<value>Zum ä rolle becho, schriib `!role [name]`</value>
|
||||
</data>
|
||||
<data name="RoleNotFound" xml:space="preserve">
|
||||
<value>Die rolle gids nid or isch nid uf dr whitelist</value>
|
||||
</data>
|
||||
<data name="RemovedUserFromRole" xml:space="preserve">
|
||||
<value>Han di entfernt vo {0}</value>
|
||||
</data>
|
||||
<data name="AddedUserFromRole" xml:space="preserve">
|
||||
<value>Han di hinzue gfüegt zu {0}</value>
|
||||
</data>
|
||||
<data name="CannotAddManagedRole" xml:space="preserve">
|
||||
<value>Du chasch kei rolle hinzuefüge wo verwalted wird vo discord</value>
|
||||
</data>
|
||||
<data name="CannotAddDangerousRole" xml:space="preserve">
|
||||
<value>Du chasch die rolle nid hinzuefüge will er ein oder mehreri gföhrlichi berechtigunge het</value>
|
||||
</data>
|
||||
<data name="AddedRoleToWhitelist" xml:space="preserve">
|
||||
<value>{0} isch zur whitelist hinzuegfüegt</value>
|
||||
</data>
|
||||
<data name="RemovedRoleFromWhitelist" xml:space="preserve">
|
||||
<value>{0} isch vo dr whitelist glöscht</value>
|
||||
</data>
|
||||
</root>
|
51
src/Bot/Localization/Role.resx
Normal file
51
src/Bot/Localization/Role.resx
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>1.3</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="NoRolesConfigured" xml:space="preserve">
|
||||
<value>There are no roles configured for this server</value>
|
||||
</data>
|
||||
<data name="ListHeader" xml:space="preserve">
|
||||
<value>**Self Service Roles on {0}**</value>
|
||||
</data>
|
||||
<data name="ListInstruction" xml:space="preserve">
|
||||
<value>To get a role, use `!role [name]`</value>
|
||||
</data>
|
||||
<data name="RoleNotFound" xml:space="preserve">
|
||||
<value>That role doesn't exist or is not on the whitelist</value>
|
||||
</data>
|
||||
<data name="RemovedUserFromRole" xml:space="preserve">
|
||||
<value>Removed you from {0}</value>
|
||||
</data>
|
||||
<data name="AddedUserFromRole" xml:space="preserve">
|
||||
<value>Added you to {0}</value>
|
||||
</data>
|
||||
<data name="CannotAddManagedRole" xml:space="preserve">
|
||||
<value>You can't add a role that is managed by discord</value>
|
||||
</data>
|
||||
<data name="CannotAddDangerousRole" xml:space="preserve">
|
||||
<value>You cannot add that role to self service because it contains one or more dangerous permissions</value>
|
||||
</data>
|
||||
<data name="AddedRoleToWhitelist" xml:space="preserve">
|
||||
<value>Added {0} to the whitelist</value>
|
||||
</data>
|
||||
<data name="RemovedRoleFromWhitelist" xml:space="preserve">
|
||||
<value>Removed {0} from the whitelist</value>
|
||||
</data>
|
||||
</root>
|
|
@ -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"
|
||||
CHDE: "Gseht danach us das ich nid gnueg recht han zum das mache :confused:"
|
Loading…
Reference in a new issue