From 902ddc70f609c17349276ccbd10deb2df46ab7d7 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 25 Jun 2017 04:58:48 +0200 Subject: [PATCH] triggered permissions are now translatable --- src/NadekoBot/NadekoBot.cs | 6 +++--- .../Services/CustomReactions/CustomReactionsService.cs | 6 ++++-- src/NadekoBot/Services/Games/ChatterbotService.cs | 7 +++++-- src/NadekoBot/Services/Permissions/PermissionsService.cs | 9 ++++----- src/NadekoBot/_strings/ResponseStrings.en-US.json | 7 ++++--- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index a180f3b5..4142aa2f 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -165,7 +165,7 @@ namespace NadekoBot #endregion #region permissions - var permissionsService = new PermissionService(Client, Db, BotConfig, CommandHandler); + var permissionsService = new PermissionService(Client, Db, BotConfig, CommandHandler, Strings); var blacklistService = new BlacklistService(BotConfig); var cmdcdsService = new CmdCdService(AllGuildConfigs); var filterService = new FilterService(Client, AllGuildConfigs); @@ -180,11 +180,11 @@ namespace NadekoBot var clashService = new ClashOfClansService(Client, Db, Localization, Strings, uow, startingGuildIdList); var musicService = new MusicService(GoogleApi, Strings, Localization, Db, soundcloudApiService, Credentials, AllGuildConfigs); - var crService = new CustomReactionsService(permissionsService, Db, Client, CommandHandler, BotConfig, uow); + var crService = new CustomReactionsService(permissionsService, Db, Strings, Client, CommandHandler, BotConfig, uow); #region Games var gamesService = new GamesService(Client, BotConfig, AllGuildConfigs, Strings, Images, CommandHandler); - var chatterBotService = new ChatterBotService(Client, permissionsService, AllGuildConfigs, CommandHandler); + var chatterBotService = new ChatterBotService(Client, permissionsService, AllGuildConfigs, CommandHandler, Strings); var pollService = new PollService(Client, Strings); #endregion diff --git a/src/NadekoBot/Services/CustomReactions/CustomReactionsService.cs b/src/NadekoBot/Services/CustomReactions/CustomReactionsService.cs index ecf0dede..c64f5c81 100644 --- a/src/NadekoBot/Services/CustomReactions/CustomReactionsService.cs +++ b/src/NadekoBot/Services/CustomReactions/CustomReactionsService.cs @@ -27,8 +27,9 @@ namespace NadekoBot.Services.CustomReactions private readonly PermissionService _perms; private readonly CommandHandler _cmd; private readonly BotConfig _bc; + private readonly NadekoStrings _strings; - public CustomReactionsService(PermissionService perms, DbService db, + public CustomReactionsService(PermissionService perms, DbService db, NadekoStrings strings, DiscordSocketClient client, CommandHandler cmd, BotConfig bc, IUnitOfWork uow) { _log = LogManager.GetCurrentClassLogger(); @@ -37,6 +38,7 @@ namespace NadekoBot.Services.CustomReactions _perms = perms; _cmd = cmd; _bc = bc; + _strings = strings; var items = uow.CustomReactions.GetAll(); GuildReactions = new ConcurrentDictionary(items.Where(g => g.GuildId != null && g.GuildId != 0).GroupBy(k => k.GuildId.Value).ToDictionary(g => g.Key, g => g.ToArray())); @@ -109,7 +111,7 @@ namespace NadekoBot.Services.CustomReactions { if (pc.Verbose) { - var returnMsg = $"Permission number #{index + 1} **{pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), sg)}** is preventing this action."; + var returnMsg = _strings.GetText("trigger", guild.Id, "Permissions".ToLowerInvariant(), index + 1, Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), (SocketGuild)guild))); try { await msg.Channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { } _log.Info(returnMsg); } diff --git a/src/NadekoBot/Services/Games/ChatterbotService.cs b/src/NadekoBot/Services/Games/ChatterbotService.cs index ad295dec..833eef0b 100644 --- a/src/NadekoBot/Services/Games/ChatterbotService.cs +++ b/src/NadekoBot/Services/Games/ChatterbotService.cs @@ -19,15 +19,18 @@ namespace NadekoBot.Services.Games private readonly Logger _log; private readonly PermissionService _perms; private readonly CommandHandler _cmd; + private readonly NadekoStrings _strings; public ConcurrentDictionary> ChatterBotGuilds { get; } - public ChatterBotService(DiscordSocketClient client, PermissionService perms, IEnumerable gcs, CommandHandler cmd) + public ChatterBotService(DiscordSocketClient client, PermissionService perms, IEnumerable gcs, + CommandHandler cmd, NadekoStrings strings) { _client = client; _log = LogManager.GetCurrentClassLogger(); _perms = perms; _cmd = cmd; + _strings = strings; ChatterBotGuilds = new ConcurrentDictionary>( gcs.Where(gc => gc.CleverbotEnabled) @@ -102,7 +105,7 @@ namespace NadekoBot.Services.Games if (pc.Verbose) { //todo move this to permissions - var returnMsg = $"Permission number #{index + 1} **{pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), sg)}** is preventing this action."; + var returnMsg = _strings.GetText("trigger", guild.Id, "Permissions".ToLowerInvariant(), index + 1, Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), (SocketGuild)guild))); try { await usrMsg.Channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { } _log.Info(returnMsg); } diff --git a/src/NadekoBot/Services/Permissions/PermissionsService.cs b/src/NadekoBot/Services/Permissions/PermissionsService.cs index 00794d2d..c4c586a9 100644 --- a/src/NadekoBot/Services/Permissions/PermissionsService.cs +++ b/src/NadekoBot/Services/Permissions/PermissionsService.cs @@ -20,16 +20,18 @@ namespace NadekoBot.Services.Permissions private readonly DbService _db; private readonly Logger _log; private readonly CommandHandler _cmd; + private readonly NadekoStrings _strings; //guildid, root permission public ConcurrentDictionary Cache { get; } = new ConcurrentDictionary(); - public PermissionService(DiscordSocketClient client, DbService db, BotConfig bc, CommandHandler cmd) + public PermissionService(DiscordSocketClient client, DbService db, BotConfig bc, CommandHandler cmd, NadekoStrings strings) { _log = LogManager.GetCurrentClassLogger(); _db = db; _cmd = cmd; + _strings = strings; var sw = Stopwatch.StartNew(); if (client.ShardId == 0) @@ -205,11 +207,9 @@ WHERE secondaryTargetName LIKE '.%' OR PermissionCache pc = GetCache(guild.Id); if (!resetCommand && !pc.Permissions.CheckPermissions(msg, commandName, moduleName, out int index)) { - var returnMsg = $"Permission number #{index + 1} **{pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), (SocketGuild)guild)}** is preventing this action."; if (pc.Verbose) - try { await channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { } + try { await channel.SendErrorAsync(_strings.GetText("trigger", guild.Id, "Permissions".ToLowerInvariant(), index + 1, Format.Bold(pc.Permissions[index].GetCommand(_cmd.GetPrefix(guild), (SocketGuild)guild)))).ConfigureAwait(false); } catch { } return true; - //return new ExecuteCommandResult(cmd, pc, SearchResult.FromError(CommandError.Exception, returnMsg)); } @@ -222,7 +222,6 @@ WHERE secondaryTargetName LIKE '.%' OR if (pc.Verbose) try { await channel.SendErrorAsync(returnMsg).ConfigureAwait(false); } catch { } return true; - //return new ExecuteCommandResult(cmd, pc, SearchResult.FromError(CommandError.Exception, $"You need the **{pc.PermRole}** role in order to use permission commands.")); } } } diff --git a/src/NadekoBot/_strings/ResponseStrings.en-US.json b/src/NadekoBot/_strings/ResponseStrings.en-US.json index d1863403..f405c63e 100644 --- a/src/NadekoBot/_strings/ResponseStrings.en-US.json +++ b/src/NadekoBot/_strings/ResponseStrings.en-US.json @@ -154,6 +154,7 @@ "administration_old_topic": "Old topic", "administration_perms": "Error. Most likely I don't have sufficient permissions.", "permissions_perms_reset": "Permissions for this server are reset.", + "permissions_trigger": "Permission number #{0} {1} is preventing this action.", "administration_prot_active": "Active protections", "administration_prot_disable": "{0} has been **disabled** on this server.", "administration_prot_enable": "{0} Enabled", @@ -446,7 +447,7 @@ "music_skipped_to": "Skipped to `{0}:{1}`", "music_songs_shuffled": "Songs shuffled", "music_song_moved": "Song moved", - "music_song_not_found": "No song found.", + "music_song_not_found": "No song found.", "music_time_format": "{0}h {1}m {2}s", "music_to_position": "To position", "music_unlimited": "unlimited", @@ -523,7 +524,7 @@ "searches_cost": "Cost", "searches_date": "Date", "searches_define": "Define:", - "searches_define_unknown": "Can't find the definition for that term.", + "searches_define_unknown": "Can't find the definition for that term.", "searches_dropped": "Dropped", "searches_episodes": "Episodes", "searches_error_occured": "Error occurred.", @@ -534,7 +535,7 @@ "searches_hashtag_error": "Failed finding a definition for that tag.", "searches_height_weight": "Height/Weight", "searches_height_weight_val": "{0}m/{1}kg", - "searches_hex_invalid": "Invalid color specified.", + "searches_hex_invalid": "Invalid color specified.", "searches_humidity": "Humidity", "searches_image_search_for": "Image search for:", "searches_imdb_fail": "Failed to find that movie.",