From be8ca3b45dff51d621eaabc8b5afde40087cfeb7 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 14 Feb 2017 19:06:02 +0100 Subject: [PATCH] logging localized >.< --- .../Administration/Commands/LogCommand.cs | 267 +++++++---- src/NadekoBot/Modules/NadekoModule.cs | 18 +- .../Resources/ResponseStrings.Designer.cs | 450 ++++++++++++++++++ src/NadekoBot/Resources/ResponseStrings.resx | 155 ++++++ 4 files changed, 776 insertions(+), 114 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs index 8c63191d..3ad8c084 100644 --- a/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs @@ -1,7 +1,6 @@ ο»Ώusing Discord; using Discord.Commands; using Discord.WebSocket; -using Microsoft.EntityFrameworkCore; using NadekoBot.Attributes; using NadekoBot.Extensions; using NadekoBot.Modules.Permissions; @@ -23,39 +22,37 @@ namespace NadekoBot.Modules.Administration [Group] public class LogCommands : NadekoSubmodule { - private const string clockEmojiUrl = "https://cdn.discordapp.com/attachments/155726317222887425/258309524966866945/clock.png"; - - private static DiscordShardedClient _client { get; } - private static Logger _log { get; } + private static DiscordShardedClient client { get; } + private new static Logger _log { get; } private static string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】"; private static string currentTime => $"{DateTime.Now:HH:mm:ss}"; public static ConcurrentDictionary GuildLogSettings { get; } - private static ConcurrentDictionary> PresenceUpdates { get; } = new ConcurrentDictionary>(); - private static Timer timerReference { get; } + private static ConcurrentDictionary> presenceUpdates { get; } = new ConcurrentDictionary>(); + private static readonly Timer _timerReference; static LogCommands() { - _client = NadekoBot.Client; + client = NadekoBot.Client; _log = LogManager.GetCurrentClassLogger(); var sw = Stopwatch.StartNew(); GuildLogSettings = new ConcurrentDictionary(NadekoBot.AllGuildConfigs .ToDictionary(g => g.GuildId, g => g.LogSetting)); - timerReference = new Timer(async (state) => + _timerReference = new Timer(async (state) => { try { - var keys = PresenceUpdates.Keys.ToList(); + var keys = presenceUpdates.Keys.ToList(); await Task.WhenAll(keys.Select(async key => { List messages; - if (PresenceUpdates.TryRemove(key, out messages)) - try { await key.SendConfirmAsync("Presence Updates", string.Join(Environment.NewLine, messages)); } + if (presenceUpdates.TryRemove(key, out messages)) + try { await key.SendConfirmAsync(key.Guild.GetLogText("presence_updates"), string.Join(Environment.NewLine, messages)); } catch { // ignored @@ -72,23 +69,22 @@ namespace NadekoBot.Modules.Administration _log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s"); //_client.MessageReceived += _client_MessageReceived; - _client.MessageUpdated += _client_MessageUpdated; - _client.MessageDeleted += _client_MessageDeleted; - _client.UserBanned += _client_UserBanned; - _client.UserUnbanned += _client_UserUnbanned; - _client.UserJoined += _client_UserJoined; - _client.UserLeft += _client_UserLeft; - _client.UserPresenceUpdated += _client_UserPresenceUpdated; - _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated; - _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated_TTS; - _client.GuildMemberUpdated += _client_GuildUserUpdated; + client.MessageUpdated += _client_MessageUpdated; + client.MessageDeleted += _client_MessageDeleted; + client.UserBanned += _client_UserBanned; + client.UserUnbanned += _client_UserUnbanned; + client.UserJoined += _client_UserJoined; + client.UserLeft += _client_UserLeft; + client.UserPresenceUpdated += _client_UserPresenceUpdated; + client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated; + client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated_TTS; + client.GuildMemberUpdated += _client_GuildUserUpdated; #if !GLOBAL_NADEKO - _client.UserUpdated += _client_UserUpdated; + client.UserUpdated += _client_UserUpdated; #endif - - _client.ChannelCreated += _client_ChannelCreated; - _client.ChannelDestroyed += _client_ChannelDestroyed; - _client.ChannelUpdated += _client_ChannelUpdated; + client.ChannelCreated += _client_ChannelCreated; + client.ChannelDestroyed += _client_ChannelDestroyed; + client.ChannelUpdated += _client_ChannelUpdated; MuteCommands.UserMuted += MuteCommands_UserMuted; MuteCommands.UserUnmuted += MuteCommands_UserUnmuted; @@ -119,7 +115,7 @@ namespace NadekoBot.Modules.Administration if (before.Username != after.Username) { - embed.WithTitle("πŸ‘₯ Username Changed") + embed.WithTitle("πŸ‘₯ " + g.GetLogText("username_changed")) .WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}") .AddField(fb => fb.WithName("Old Name").WithValue($"{before.Username}").WithIsInline(true)) .AddField(fb => fb.WithName("New Name").WithValue($"{after.Username}").WithIsInline(true)) @@ -128,7 +124,7 @@ namespace NadekoBot.Modules.Administration } else if (before.AvatarUrl != after.AvatarUrl) { - embed.WithTitle("πŸ‘₯ Avatar Changed") + embed.WithTitle("πŸ‘₯" + g.GetLogText("avatar_changed")) .WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}") .WithTitle($"{before.Username}#{before.Discriminator} | {before.Id}") .WithThumbnailUrl(before.AvatarUrl) @@ -190,15 +186,15 @@ namespace NadekoBot.Modules.Administration var str = ""; if (beforeVch?.Guild == afterVch?.Guild) { - str = $"{usr.Username} moved from {beforeVch?.Name} to {afterVch?.Name}"; + str = logChannel.Guild.GetLogText("moved", usr.Username, beforeVch?.Name, afterVch?.Name); } else if (beforeVch == null) { - str = $"{usr.Username} has joined {afterVch.Name}"; + str = logChannel.Guild.GetLogText("joined", usr.Username, afterVch.Name); } else if (afterVch == null) { - str = $"{usr.Username} has left {beforeVch.Name}"; + str = logChannel.Guild.GetLogText("left", usr.Username, beforeVch.Name); } var toDelete = await logChannel.SendMessageAsync(str, true).ConfigureAwait(false); toDelete.DeleteAfter(5); @@ -222,27 +218,31 @@ namespace NadekoBot.Modules.Administration if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) return; var mutes = ""; + var mutedLocalized = logChannel.Guild.GetLogText("muted_sn"); switch (muteType) { case MuteCommands.MuteType.Voice: - mutes = "voice chat"; + mutes = "πŸ”‡ " + logChannel.Guild.GetLogText("xmuted_voice", mutedLocalized); break; case MuteCommands.MuteType.Chat: - mutes = "text chat"; + mutes = "πŸ”‡ " + logChannel.Guild.GetLogText("xmuted_text", mutedLocalized); break; case MuteCommands.MuteType.All: - mutes = "text and voice chat"; + mutes = "πŸ”‡ " + logChannel.Guild.GetLogText("xmuted_text_and_voice", mutedLocalized); break; } - var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName("πŸ”‡ User Muted from " + mutes)) + var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName(mutes)) .WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}") .WithFooter(fb => fb.WithText(currentTime)) .WithOkColor(); await logChannel.EmbedAsync(embed).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } private static async void MuteCommands_UserUnmuted(IGuildUser usr, MuteCommands.MuteType muteType) @@ -258,28 +258,32 @@ namespace NadekoBot.Modules.Administration if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null) return; - string mutes = ""; + var mutes = ""; + var unmutedLocalized = logChannel.Guild.GetLogText("unmuted_sn"); switch (muteType) { case MuteCommands.MuteType.Voice: - mutes = "voice chat"; + mutes = "πŸ”Š " + logChannel.Guild.GetLogText("xmuted_voice", unmutedLocalized); break; case MuteCommands.MuteType.Chat: - mutes = "text chat"; + mutes = "πŸ”Š " + logChannel.Guild.GetLogText("xmuted_text", unmutedLocalized); break; case MuteCommands.MuteType.All: - mutes = "text and voice chat"; + mutes = "πŸ”Š " + logChannel.Guild.GetLogText("xmuted_text_and_voice", unmutedLocalized); break; } - var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName("πŸ”Š User Unmuted from " + mutes)) + var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName(mutes)) .WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}") .WithFooter(fb => fb.WithText($"{currentTime}")) .WithOkColor(); await logChannel.EmbedAsync(embed).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } public static async Task TriggeredAntiProtection(IGuildUser[] users, PunishmentAction action, ProtectionType protection) @@ -298,28 +302,31 @@ namespace NadekoBot.Modules.Administration return; var punishment = ""; - if (action == PunishmentAction.Mute) + switch (action) { - punishment = "πŸ”‡ MUTED"; - } - else if (action == PunishmentAction.Kick) - { - punishment = "☣ SOFT-BANNED (KICKED)"; - } - else if (action == PunishmentAction.Ban) - { - punishment = "⛔️ BANNED"; + case PunishmentAction.Mute: + punishment = "πŸ”‡ " + logChannel.Guild.GetLogText("muted_pl").ToUpperInvariant(); + break; + case PunishmentAction.Kick: + punishment = "☣ " + logChannel.Guild.GetLogText("soft_banned_pl").ToUpperInvariant(); + break; + case PunishmentAction.Ban: + punishment = "⛔️ " + logChannel.Guild.GetLogText("banned_pl").ToUpperInvariant(); + break; } var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName($"πŸ›‘ Anti-{protection}")) - .WithTitle($"Users " + punishment) - .WithDescription(String.Join("\n", users.Select(u => u.ToString()))) + .WithTitle(logChannel.Guild.GetLogText("users") + " " + punishment) + .WithDescription(string.Join("\n", users.Select(u => u.ToString()))) .WithFooter(fb => fb.WithText($"{currentTime}")) .WithOkColor(); await logChannel.EmbedAsync(embed).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } private static async Task _client_GuildUserUpdated(SocketGuildUser before, SocketGuildUser after) @@ -338,23 +345,23 @@ namespace NadekoBot.Modules.Administration .WithTitle($"{before.Username}#{before.Discriminator} | {before.Id}"); if (before.Nickname != after.Nickname) { - embed.WithAuthor(eab => eab.WithName("πŸ‘₯ Nickname Changed")) + embed.WithAuthor(eab => eab.WithName("πŸ‘₯ " + logChannel.Guild.GetLogText("nick_change"))) - .AddField(efb => efb.WithName("Old Nickname").WithValue($"{before.Nickname}#{before.Discriminator}")) - .AddField(efb => efb.WithName("New Nickname").WithValue($"{after.Nickname}#{after.Discriminator}")); + .AddField(efb => efb.WithName(logChannel.Guild.GetLogText("old_nick")).WithValue($"{before.Nickname}#{before.Discriminator}")) + .AddField(efb => efb.WithName(logChannel.Guild.GetLogText("new_nick")).WithValue($"{after.Nickname}#{after.Discriminator}")); } else if (!before.RoleIds.SequenceEqual(after.RoleIds)) { if (before.RoleIds.Count < after.RoleIds.Count) { var diffRoles = after.RoleIds.Where(r => !before.RoleIds.Contains(r)).Select(r => before.Guild.GetRole(r).Name); - embed.WithAuthor(eab => eab.WithName("βš” User's Role Added")) + embed.WithAuthor(eab => eab.WithName("βš” " + logChannel.Guild.GetLogText("user_role_add"))) .WithDescription(string.Join(", ", diffRoles).SanitizeMentions()); } else if (before.RoleIds.Count > after.RoleIds.Count) { var diffRoles = before.RoleIds.Where(r => !after.RoleIds.Contains(r)).Select(r => before.Guild.GetRole(r).Name); - embed.WithAuthor(eab => eab.WithName("βš” User's Role Removed")) + embed.WithAuthor(eab => eab.WithName("βš” " + logChannel.Guild.GetLogText("user_role_rem"))) .WithDescription(string.Join(", ", diffRoles).SanitizeMentions()); } } @@ -362,7 +369,10 @@ namespace NadekoBot.Modules.Administration return; await logChannel.EmbedAsync(embed).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } private static async Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter) @@ -391,23 +401,26 @@ namespace NadekoBot.Modules.Administration if (before.Name != after.Name) { - embed.WithTitle("ℹ️ Channel Name Changed") + embed.WithTitle("ℹ️ " + logChannel.Guild.GetLogText("ch_name_change")) .WithDescription($"{after} | {after.Id}") - .AddField(efb => efb.WithName("Old Name").WithValue(before.Name)); + .AddField(efb => efb.WithName(logChannel.Guild.GetLogText("ch_old_name")).WithValue(before.Name)); } else if (beforeTextChannel?.Topic != afterTextChannel?.Topic) { - embed.WithTitle("ℹ️ Channel Topic Changed") + embed.WithTitle("ℹ️ " + logChannel.Guild.GetLogText("ch_topic_change")) .WithDescription($"{after} | {after.Id}") - .AddField(efb => efb.WithName("Old Topic").WithValue(beforeTextChannel.Topic)) - .AddField(efb => efb.WithName("New Topic").WithValue(afterTextChannel.Topic)); + .AddField(efb => efb.WithName(logChannel.Guild.GetLogText("old_topic")).WithValue(beforeTextChannel?.Topic ?? "-")) + .AddField(efb => efb.WithName(logChannel.Guild.GetLogText("new_topic")).WithValue(afterTextChannel?.Topic ?? "-")); } else return; await logChannel.EmbedAsync(embed).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } private static async Task _client_ChannelDestroyed(IChannel ich) @@ -427,14 +440,23 @@ namespace NadekoBot.Modules.Administration ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null) return; - + string title; + if (ch is IVoiceChannel) + { + title = logChannel.Guild.GetLogText("voice_chan_destroyed"); + } + else + title = logChannel.Guild.GetLogText("text_chan_destroyed"); await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() - .WithTitle("πŸ†• " + (ch is IVoiceChannel ? "Voice" : "Text") + " Channel Destroyed") + .WithTitle("πŸ†• " + title) .WithDescription($"{ch.Name} | {ch.Id}") .WithFooter(efb => efb.WithText(currentTime))).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } private static async Task _client_ChannelCreated(IChannel ich) @@ -453,10 +475,16 @@ namespace NadekoBot.Modules.Administration ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null) return; - + string title; + if (ch is IVoiceChannel) + { + title = logChannel.Guild.GetLogText("voice_chan_created"); + } + else + title = logChannel.Guild.GetLogText("text_chan_created"); await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() - .WithTitle("πŸ†• " + (ch is IVoiceChannel ? "Voice" : "Text") + " Channel Created") + .WithTitle("πŸ†• " + title) .WithDescription($"{ch.Name} | {ch.Id}") .WithFooter(efb => efb.WithText(currentTime))).ConfigureAwait(false); } @@ -489,20 +517,29 @@ namespace NadekoBot.Modules.Administration string str = null; if (beforeVch?.Guild == afterVch?.Guild) { - str = $"πŸŽ™`{prettyCurrentTime}`πŸ‘€__**{usr.Username}#{usr.Discriminator}**__ moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel."; + str = "πŸŽ™" + Format.Code(prettyCurrentTime) + logChannel.Guild.GetLogText("user_vmoved", + "πŸ‘€" + Format.Bold(usr.Username + "#" + usr.Discriminator), + Format.Bold(beforeVch?.Name ?? ""), Format.Bold(afterVch?.Name ?? "")); } else if (beforeVch == null) { - str = $"πŸŽ™`{prettyCurrentTime}`πŸ‘€__**{usr.Username}#{usr.Discriminator}**__ has joined **{afterVch.Name}** voice channel."; + str = "πŸŽ™" + Format.Code(prettyCurrentTime) + logChannel.Guild.GetLogText("user_vjoined", + "πŸ‘€" + Format.Bold(usr.Username + "#" + usr.Discriminator), + Format.Bold(afterVch.Name ?? "")); } else if (afterVch == null) { - str = $"πŸŽ™`{prettyCurrentTime}`πŸ‘€__**{usr.Username}#{usr.Discriminator}**__ has left **{beforeVch.Name}** voice channel."; + str = "πŸŽ™" + Format.Code(prettyCurrentTime) + logChannel.Guild.GetLogText("user_vleft", + "πŸ‘€" + Format.Code(prettyCurrentTime), "πŸ‘€" + Format.Bold(usr.Username + "#" + usr.Discriminator), + Format.Bold(beforeVch.Name ?? "")); } if (str != null) - PresenceUpdates.AddOrUpdate(logChannel, new List() { str }, (id, list) => { list.Add(str); return list; }); + presenceUpdates.AddOrUpdate(logChannel, new List() { str }, (id, list) => { list.Add(str); return list; }); + } + catch + { + // ignored } - catch { } } private static async Task _client_UserPresenceUpdated(Optional optGuild, SocketUser usr, SocketPresence before, SocketPresence after) @@ -525,7 +562,10 @@ namespace NadekoBot.Modules.Administration return; string str = ""; if (before.Status != after.Status) - str = $"🎭`{prettyCurrentTime}`πŸ‘€__**{usr.Username}**__ is now **{after.Status}**."; + str = "🎭" + Format.Code(prettyCurrentTime) + + logChannel.Guild.GetLogText("user_status_change", + "πŸ‘€" + Format.Bold(usr.Username), + Format.Bold(after.Status.ToString())); //if (before.Game?.Name != after.Game?.Name) //{ @@ -534,9 +574,12 @@ namespace NadekoBot.Modules.Administration // str += $"πŸ‘Ύ`{prettyCurrentTime}`πŸ‘€__**{usr.Username}**__ is now playing **{after.Game?.Name}**."; //} - PresenceUpdates.AddOrUpdate(logChannel, new List() { str }, (id, list) => { list.Add(str); return list; }); + presenceUpdates.AddOrUpdate(logChannel, new List() { str }, (id, list) => { list.Add(str); return list; }); + } + catch + { + // ignored } - catch { } } private static async Task _client_UserLeft(IGuildUser usr) @@ -554,13 +597,16 @@ namespace NadekoBot.Modules.Administration await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() - .WithTitle("❌ User Left") + .WithTitle("❌ " + logChannel.Guild.GetLogText("user_left")) .WithThumbnailUrl(usr.AvatarUrl) .WithDescription(usr.ToString()) .AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString())) .WithFooter(efb => efb.WithText(currentTime))).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } private static async Task _client_UserJoined(IGuildUser usr) @@ -578,7 +624,7 @@ namespace NadekoBot.Modules.Administration await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() - .WithTitle("βœ… User Joined") + .WithTitle("βœ… " + logChannel.Guild.GetLogText("user_joined")) .WithThumbnailUrl(usr.AvatarUrl) .WithDescription($"{usr}") .AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString())) @@ -602,7 +648,7 @@ namespace NadekoBot.Modules.Administration await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() - .WithTitle("♻️ User Unbanned") + .WithTitle("♻️ " + logChannel.Guild.GetLogText("user_unbanned")) .WithThumbnailUrl(usr.AvatarUrl) .WithDescription(usr.ToString()) .AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString())) @@ -625,7 +671,7 @@ namespace NadekoBot.Modules.Administration return; await logChannel.EmbedAsync(new EmbedBuilder() .WithOkColor() - .WithTitle("🚫 User Banned") + .WithTitle("🚫 " + logChannel.Guild.GetLogText("user_banned")) .WithThumbnailUrl(usr.AvatarUrl) .WithDescription(usr.ToString()) .AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString())) @@ -658,17 +704,20 @@ namespace NadekoBot.Modules.Administration return; var embed = new EmbedBuilder() .WithOkColor() - .WithTitle($"πŸ—‘ Message Deleted in #{((ITextChannel)msg.Channel).Name}") + .WithTitle("πŸ—‘ " + logChannel.Guild.GetLogText("msg_del", ((ITextChannel)msg.Channel).Name)) .WithDescription($"{msg.Author}") - .AddField(efb => efb.WithName("Content").WithValue(msg.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false)) + .AddField(efb => efb.WithName(logChannel.Guild.GetLogText("content")).WithValue(msg.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false)) .AddField(efb => efb.WithName("Id").WithValue(msg.Id.ToString()).WithIsInline(false)) .WithFooter(efb => efb.WithText(currentTime)); if (msg.Attachments.Any()) - embed.AddField(efb => efb.WithName("Attachments").WithValue(string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))).WithIsInline(false)); + embed.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("attachments")).WithValue(string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))).WithIsInline(false)); await logChannel.EmbedAsync(embed).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } private static async Task _client_MessageUpdated(Optional optmsg, SocketMessage imsg2) @@ -702,16 +751,19 @@ namespace NadekoBot.Modules.Administration var embed = new EmbedBuilder() .WithOkColor() - .WithTitle($"πŸ“ Message Updated in #{((ITextChannel)after.Channel).Name}") + .WithTitle("πŸ“ " + logChannel.Guild.GetLogText("msg_update", ((ITextChannel)after.Channel).Name)) .WithDescription(after.Author.ToString()) - .AddField(efb => efb.WithName("Old Message").WithValue(before.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false)) - .AddField(efb => efb.WithName("New Message").WithValue(after.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false)) + .AddField(efb => efb.WithName(logChannel.Guild.GetLogText("old_msg")).WithValue(before.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false)) + .AddField(efb => efb.WithName(logChannel.Guild.GetLogText("new_msg")).WithValue(after.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false)) .AddField(efb => efb.WithName("Id").WithValue(after.Id.ToString()).WithIsInline(false)) .WithFooter(efb => efb.WithText(currentTime)); await logChannel.EmbedAsync(embed).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } } public enum LogType @@ -783,8 +835,6 @@ namespace NadekoBot.Modules.Administration case LogType.UserMuted: id = logSetting.UserMutedId; break; - default: - break; } if (!id.HasValue) @@ -855,8 +905,6 @@ namespace NadekoBot.Modules.Administration case LogType.VoicePresenceTTS: newLogSetting.LogVoicePresenceTTSId = null; break; - default: - break; } GuildLogSettings.AddOrUpdate(guildId, newLogSetting, (gid, old) => newLogSetting); uow.Complete(); @@ -900,9 +948,9 @@ namespace NadekoBot.Modules.Administration await uow.CompleteAsync().ConfigureAwait(false); } if (action.Value) - await channel.SendConfirmAsync("Logging all events in this channel.").ConfigureAwait(false); + await ReplyConfirmLocalized("log_all").ConfigureAwait(false); else - await channel.SendConfirmAsync("Logging disabled.").ConfigureAwait(false); + await ReplyConfirmLocalized("log_disabled").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -929,9 +977,9 @@ namespace NadekoBot.Modules.Administration } if (removed == 0) - await channel.SendConfirmAsync($"Logging will IGNORE **{channel.Mention} ({channel.Id})**").ConfigureAwait(false); + await ReplyConfirmLocalized("log_ignore", Format.Bold(channel.Mention + "(" + channel.Id + ")")).ConfigureAwait(false); else - await channel.SendConfirmAsync($"Logging will NOT IGNORE **{channel.Mention} ({channel.Id})**").ConfigureAwait(false); + await ReplyConfirmLocalized("log_not_ignore", Format.Bold(channel.Mention + "(" + channel.Id + ")")).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -940,7 +988,7 @@ namespace NadekoBot.Modules.Administration [OwnerOnly] public async Task LogEvents() { - await Context.Channel.SendConfirmAsync("Log events you can subscribe to:", String.Join(", ", Enum.GetNames(typeof(LogType)).Cast())); + await ReplyConfirmLocalized("log_events", string.Join(", ", Enum.GetNames(typeof(LogType)).Cast())).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -1008,10 +1056,19 @@ namespace NadekoBot.Modules.Administration } if (channelId != null) - await channel.SendConfirmAsync($"Logging **{type}** event in this channel.").ConfigureAwait(false); + await ReplyConfirmLocalized("log", Format.Bold(type.ToString())).ConfigureAwait(false); else - await channel.SendConfirmAsync($"Stopped logging **{type}** event.").ConfigureAwait(false); + await ReplyConfirmLocalized("log_stop", Format.Bold(type.ToString())).ConfigureAwait(false); } } } + + public static class GuildExtensions + { + public static string GetLogText(this IGuild guild, string key, params object[] replacements) + => NadekoModule.GetTextStatic(key, + NadekoBot.Localization.GetCultureInfo(guild), + typeof(Administration).Name.ToLowerInvariant(), + replacements); + } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/NadekoModule.cs b/src/NadekoBot/Modules/NadekoModule.cs index 7f75e891..9bb524ec 100644 --- a/src/NadekoBot/Modules/NadekoModule.cs +++ b/src/NadekoBot/Modules/NadekoModule.cs @@ -12,7 +12,7 @@ namespace NadekoBot.Modules public abstract class NadekoModule : ModuleBase { protected readonly Logger _log; - protected CultureInfo _cultureInfo { get; private set; } + protected CultureInfo _cultureInfo; public readonly string Prefix; public readonly string ModuleTypeName; public readonly string LowerModuleTypeName; @@ -58,23 +58,23 @@ namespace NadekoBot.Modules /// /// Used as failsafe in case response key doesn't exist in the selected or default language. /// - private static readonly CultureInfo usCultureInfo = new CultureInfo("en-US"); + private static readonly CultureInfo _usCultureInfo = new CultureInfo("en-US"); - public static string GetTextStatic(string key, CultureInfo _cultureInfo, string lowerModuleTypeName) + public static string GetTextStatic(string key, CultureInfo cultureInfo, string lowerModuleTypeName) { - var text = NadekoBot.ResponsesResourceManager.GetString(lowerModuleTypeName + "_" + key, _cultureInfo); + var text = NadekoBot.ResponsesResourceManager.GetString(lowerModuleTypeName + "_" + key, cultureInfo); if (string.IsNullOrWhiteSpace(text)) { - LogManager.GetCurrentClassLogger().Warn(lowerModuleTypeName + "_" + key + " key is missing from " + _cultureInfo + " response strings. PLEASE REPORT THIS."); - return NadekoBot.ResponsesResourceManager.GetString(lowerModuleTypeName + "_" + key, usCultureInfo) ?? $"Error: dkey {lowerModuleTypeName + "_" + key} found!"; + LogManager.GetCurrentClassLogger().Warn(lowerModuleTypeName + "_" + key + " key is missing from " + cultureInfo + " response strings. PLEASE REPORT THIS."); + return NadekoBot.ResponsesResourceManager.GetString(lowerModuleTypeName + "_" + key, _usCultureInfo) ?? $"Error: dkey {lowerModuleTypeName + "_" + key} found!"; } - return text ?? $"Error: key {lowerModuleTypeName + "_" + key} not found."; + return text; } - public static string GetTextStatic(string key, CultureInfo _cultureInfo, string lowerModuleTypeName, params object[] replacements) + public static string GetTextStatic(string key, CultureInfo cultureInfo, string lowerModuleTypeName, params object[] replacements) { - return string.Format(GetTextStatic(key, _cultureInfo, lowerModuleTypeName), replacements); + return string.Format(GetTextStatic(key, cultureInfo, lowerModuleTypeName), replacements); } protected string GetText(string key) => diff --git a/src/NadekoBot/Resources/ResponseStrings.Designer.cs b/src/NadekoBot/Resources/ResponseStrings.Designer.cs index 48733a24..66ebbe34 100644 --- a/src/NadekoBot/Resources/ResponseStrings.Designer.cs +++ b/src/NadekoBot/Resources/ResponseStrings.Designer.cs @@ -77,6 +77,69 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Attachments. + /// + public static string administration_attachments { + get { + return ResourceManager.GetString("administration_attachments", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Avatar Changed. + /// + public static string administration_avatar_changed { + get { + return ResourceManager.GetString("administration_avatar_changed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to banned. + /// + public static string administration_banned_pl { + get { + return ResourceManager.GetString("administration_banned_pl", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Channel Name Changed. + /// + public static string administration_ch_name_change { + get { + return ResourceManager.GetString("administration_ch_name_change", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Old Name. + /// + public static string administration_ch_old_name { + get { + return ResourceManager.GetString("administration_ch_old_name", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Channel Topic Changed. + /// + public static string administration_ch_topic_change { + get { + return ResourceManager.GetString("administration_ch_topic_change", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Content. + /// + public static string administration_content { + get { + return ResourceManager.GetString("administration_content", resourceCulture); + } + } + /// /// Looks up a localized string similar to DM from. /// @@ -122,6 +185,15 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to {0} has joined {1}. + /// + public static string administration_joined { + get { + return ResourceManager.GetString("administration_joined", resourceCulture); + } + } + /// /// Looks up a localized string similar to List Of Languages ///{0}. @@ -177,6 +249,105 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to {0} has left {1}. + /// + public static string administration_left { + get { + return ResourceManager.GetString("administration_left", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Logging {0} event in this channel.. + /// + public static string administration_log { + get { + return ResourceManager.GetString("administration_log", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Logging all events in this channel.. + /// + public static string administration_log_all { + get { + return ResourceManager.GetString("administration_log_all", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Logging disabled.. + /// + public static string administration_log_disabled { + get { + return ResourceManager.GetString("administration_log_disabled", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Log events you can subscribe to:. + /// + public static string administration_log_events { + get { + return ResourceManager.GetString("administration_log_events", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Logging will ignore {0}. + /// + public static string administration_log_ignore { + get { + return ResourceManager.GetString("administration_log_ignore", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Logging will not ignore {0}. + /// + public static string administration_log_not_ignore { + get { + return ResourceManager.GetString("administration_log_not_ignore", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Stopped logging {0} event.. + /// + public static string administration_log_stop { + get { + return ResourceManager.GetString("administration_log_stop", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} moved from {1} to {2}. + /// + public static string administration_moved { + get { + return ResourceManager.GetString("administration_moved", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Message Deleted in #{0}. + /// + public static string administration_msg_del { + get { + return ResourceManager.GetString("administration_msg_del", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Message Updated in #{0}. + /// + public static string administration_msg_update { + get { + return ResourceManager.GetString("administration_msg_update", resourceCulture); + } + } + /// /// Looks up a localized string similar to I don't have the permission necessary for that most likely.. /// @@ -195,6 +366,132 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Muted. + /// + public static string administration_muted_pl { + get { + return ResourceManager.GetString("administration_muted_pl", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Muted. + /// + public static string administration_muted_sn { + get { + return ResourceManager.GetString("administration_muted_sn", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to New Message. + /// + public static string administration_new_msg { + get { + return ResourceManager.GetString("administration_new_msg", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to New Nickname. + /// + public static string administration_new_nick { + get { + return ResourceManager.GetString("administration_new_nick", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to New Topic. + /// + public static string administration_new_topic { + get { + return ResourceManager.GetString("administration_new_topic", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Nickname Changed. + /// + public static string administration_nick_change { + get { + return ResourceManager.GetString("administration_nick_change", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Old Message. + /// + public static string administration_old_msg { + get { + return ResourceManager.GetString("administration_old_msg", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Old Nickname. + /// + public static string administration_old_nick { + get { + return ResourceManager.GetString("administration_old_nick", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Old Topic. + /// + public static string administration_old_topic { + get { + return ResourceManager.GetString("administration_old_topic", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to soft-banned (kicked). + /// + public static string administration_soft_banned_pl { + get { + return ResourceManager.GetString("administration_soft_banned_pl", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Text Channel Destroyed . + /// + public static string administration_text_chan_created { + get { + return ResourceManager.GetString("administration_text_chan_created", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Text Channel Destroyed . + /// + public static string administration_text_chan_destroyed { + get { + return ResourceManager.GetString("administration_text_chan_destroyed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unmuted. + /// + public static string administration_unmuted_sn { + get { + return ResourceManager.GetString("administration_unmuted_sn", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User Banned. + /// + public static string administration_user_banned { + get { + return ResourceManager.GetString("administration_user_banned", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} has been **muted** from chatting.. /// @@ -213,6 +510,24 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to User Joined. + /// + public static string administration_user_joined { + get { + return ResourceManager.GetString("administration_user_joined", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User Left. + /// + public static string administration_user_left { + get { + return ResourceManager.GetString("administration_user_left", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} has been **muted** from text and voice chat.. /// @@ -222,6 +537,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to User's Role Added. + /// + public static string administration_user_role_add { + get { + return ResourceManager.GetString("administration_user_role_add", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User's Role Removed. + /// + public static string administration_user_role_rem { + get { + return ResourceManager.GetString("administration_user_role_rem", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} is now {1}. + /// + public static string administration_user_status_change { + get { + return ResourceManager.GetString("administration_user_status_change", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} has been **unmuted** from text and voice chat.. /// @@ -231,6 +573,33 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to {0} has joined {1} voice channel.. + /// + public static string administration_user_vjoined { + get { + return ResourceManager.GetString("administration_user_vjoined", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} has left {1} voice channel.. + /// + public static string administration_user_vleft { + get { + return ResourceManager.GetString("administration_user_vleft", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} moved from {1} to {2} voice channel.. + /// + public static string administration_user_vmoved { + get { + return ResourceManager.GetString("administration_user_vmoved", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} has been **voice muted**.. /// @@ -249,6 +618,87 @@ namespace NadekoBot.Resources { } } + /// + /// Looks up a localized string similar to Username Changed. + /// + public static string administration_username_changed { + get { + return ResourceManager.GetString("administration_username_changed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Users. + /// + public static string administration_users { + get { + return ResourceManager.GetString("administration_users", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Voice Channel Destroyed. + /// + public static string administration_voice_chan_created { + get { + return ResourceManager.GetString("administration_voice_chan_created", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Voice Channel Destroyed. + /// + public static string administration_voice_chan_destroyed { + get { + return ResourceManager.GetString("administration_voice_chan_destroyed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User {0} from text chat. + /// + public static string administration_xmuted_text { + get { + return ResourceManager.GetString("administration_xmuted_text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User {0} from text and voice chat. + /// + public static string administration_xmuted_text_and_voice { + get { + return ResourceManager.GetString("administration_xmuted_text_and_voice", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User {0} from voice chat. + /// + public static string administration_xmuted_voice { + get { + return ResourceManager.GetString("administration_xmuted_voice", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to User Unbanned. + /// + public static string administraton_user_unbanned { + get { + return ResourceManager.GetString("administraton_user_unbanned", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Presence Updates. + /// + public static string adminsitration_presence_updates { + get { + return ResourceManager.GetString("adminsitration_presence_updates", resourceCulture); + } + } + /// /// Looks up a localized string similar to That base is already claimed or destroyed.. /// diff --git a/src/NadekoBot/Resources/ResponseStrings.resx b/src/NadekoBot/Resources/ResponseStrings.resx index ff566d6c..1fdaa035 100644 --- a/src/NadekoBot/Resources/ResponseStrings.resx +++ b/src/NadekoBot/Resources/ResponseStrings.resx @@ -304,6 +304,28 @@ **Auto assign role** on user join is now **enabled**. + + Attachments + + + Avatar Changed + + + banned + PLURAL + + + Channel Name Changed + + + Old Name + + + Channel Topic Changed + + + Content + DM from @@ -319,6 +341,9 @@ I will stop forwarding DMs from now on. + + {0} has joined {1} + List Of Languages {0} @@ -338,30 +363,160 @@ This server's language is set to {0} - {0} + + {0} has left {1} + + + Logging {0} event in this channel. + + + Logging all events in this channel. + + + Logging disabled. + + + Log events you can subscribe to: + + + Logging will ignore {0} + + + Logging will not ignore {0} + + + Stopped logging {0} event. + + + {0} moved from {1} to {2} + + + Message Deleted in #{0} + + + Message Updated in #{0} + + + Muted + PLURAL (users have been muted) + + + Muted + singular "User muted." + I don't have the permission necessary for that most likely. New mute role set. + + New Message + + + New Nickname + + + New Topic + + + Nickname Changed + + + Old Message + + + Old Nickname + + + Old Topic + + + soft-banned (kicked) + PLURAL + + + Text Channel Destroyed + + + Text Channel Destroyed + + + Unmuted + singular + + + Username Changed + + + Users + + + User Banned + {0} has been **muted** from chatting. {0} has been **unmuted** from chatting. + + User Joined + + + User Left + {0} has been **muted** from text and voice chat. + + User's Role Added + + + User's Role Removed + + + {0} is now {1} + {0} has been **unmuted** from text and voice chat. + + {0} has joined {1} voice channel. + + + {0} has left {1} voice channel. + + + {0} moved from {1} to {2} voice channel. + {0} has been **voice muted**. {0} has been **voice unmuted**. + + Voice Channel Destroyed + + + Voice Channel Destroyed + + + User {0} from text chat + + + User {0} from text and voice chat + + + User {0} from voice chat + + + User Unbanned + + + Presence Updates + Back to ToC