logging localized >.<

This commit is contained in:
Kwoth 2017-02-14 19:06:02 +01:00
parent 97d32a46b6
commit be8ca3b45d
4 changed files with 776 additions and 114 deletions

View File

@ -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<ulong, LogSetting> GuildLogSettings { get; }
private static ConcurrentDictionary<ITextChannel, List<string>> PresenceUpdates { get; } = new ConcurrentDictionary<ITextChannel, List<string>>();
private static Timer timerReference { get; }
private static ConcurrentDictionary<ITextChannel, List<string>> presenceUpdates { get; } = new ConcurrentDictionary<ITextChannel, List<string>>();
private static readonly Timer _timerReference;
static LogCommands()
{
_client = NadekoBot.Client;
client = NadekoBot.Client;
_log = LogManager.GetCurrentClassLogger();
var sw = Stopwatch.StartNew();
GuildLogSettings = new ConcurrentDictionary<ulong, LogSetting>(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<string> 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<string>() { str }, (id, list) => { list.Add(str); return list; });
presenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; });
}
catch
{
// ignored
}
catch { }
}
private static async Task _client_UserPresenceUpdated(Optional<SocketGuild> 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<string>() { str }, (id, list) => { list.Add(str); return list; });
presenceUpdates.AddOrUpdate(logChannel, new List<string>() { 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<SocketMessage> 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<string>()));
await ReplyConfirmLocalized("log_events", string.Join(", ", Enum.GetNames(typeof(LogType)).Cast<string>())).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);
}
}

View File

@ -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
/// <summary>
/// Used as failsafe in case response key doesn't exist in the selected or default language.
/// </summary>
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) =>

View File

@ -77,6 +77,69 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Attachments.
/// </summary>
public static string administration_attachments {
get {
return ResourceManager.GetString("administration_attachments", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Avatar Changed.
/// </summary>
public static string administration_avatar_changed {
get {
return ResourceManager.GetString("administration_avatar_changed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to banned.
/// </summary>
public static string administration_banned_pl {
get {
return ResourceManager.GetString("administration_banned_pl", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Channel Name Changed.
/// </summary>
public static string administration_ch_name_change {
get {
return ResourceManager.GetString("administration_ch_name_change", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Old Name.
/// </summary>
public static string administration_ch_old_name {
get {
return ResourceManager.GetString("administration_ch_old_name", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Channel Topic Changed.
/// </summary>
public static string administration_ch_topic_change {
get {
return ResourceManager.GetString("administration_ch_topic_change", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Content.
/// </summary>
public static string administration_content {
get {
return ResourceManager.GetString("administration_content", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to DM from.
/// </summary>
@ -122,6 +185,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to {0} has joined {1}.
/// </summary>
public static string administration_joined {
get {
return ResourceManager.GetString("administration_joined", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to List Of Languages
///{0}.
@ -177,6 +249,105 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to {0} has left {1}.
/// </summary>
public static string administration_left {
get {
return ResourceManager.GetString("administration_left", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Logging {0} event in this channel..
/// </summary>
public static string administration_log {
get {
return ResourceManager.GetString("administration_log", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Logging all events in this channel..
/// </summary>
public static string administration_log_all {
get {
return ResourceManager.GetString("administration_log_all", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Logging disabled..
/// </summary>
public static string administration_log_disabled {
get {
return ResourceManager.GetString("administration_log_disabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Log events you can subscribe to:.
/// </summary>
public static string administration_log_events {
get {
return ResourceManager.GetString("administration_log_events", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Logging will ignore {0}.
/// </summary>
public static string administration_log_ignore {
get {
return ResourceManager.GetString("administration_log_ignore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Logging will not ignore {0}.
/// </summary>
public static string administration_log_not_ignore {
get {
return ResourceManager.GetString("administration_log_not_ignore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Stopped logging {0} event..
/// </summary>
public static string administration_log_stop {
get {
return ResourceManager.GetString("administration_log_stop", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} moved from {1} to {2}.
/// </summary>
public static string administration_moved {
get {
return ResourceManager.GetString("administration_moved", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Message Deleted in #{0}.
/// </summary>
public static string administration_msg_del {
get {
return ResourceManager.GetString("administration_msg_del", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Message Updated in #{0}.
/// </summary>
public static string administration_msg_update {
get {
return ResourceManager.GetString("administration_msg_update", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to I don&apos;t have the permission necessary for that most likely..
/// </summary>
@ -195,6 +366,132 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Muted.
/// </summary>
public static string administration_muted_pl {
get {
return ResourceManager.GetString("administration_muted_pl", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Muted.
/// </summary>
public static string administration_muted_sn {
get {
return ResourceManager.GetString("administration_muted_sn", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to New Message.
/// </summary>
public static string administration_new_msg {
get {
return ResourceManager.GetString("administration_new_msg", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to New Nickname.
/// </summary>
public static string administration_new_nick {
get {
return ResourceManager.GetString("administration_new_nick", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to New Topic.
/// </summary>
public static string administration_new_topic {
get {
return ResourceManager.GetString("administration_new_topic", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Nickname Changed.
/// </summary>
public static string administration_nick_change {
get {
return ResourceManager.GetString("administration_nick_change", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Old Message.
/// </summary>
public static string administration_old_msg {
get {
return ResourceManager.GetString("administration_old_msg", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Old Nickname.
/// </summary>
public static string administration_old_nick {
get {
return ResourceManager.GetString("administration_old_nick", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Old Topic.
/// </summary>
public static string administration_old_topic {
get {
return ResourceManager.GetString("administration_old_topic", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to soft-banned (kicked).
/// </summary>
public static string administration_soft_banned_pl {
get {
return ResourceManager.GetString("administration_soft_banned_pl", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Text Channel Destroyed .
/// </summary>
public static string administration_text_chan_created {
get {
return ResourceManager.GetString("administration_text_chan_created", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Text Channel Destroyed .
/// </summary>
public static string administration_text_chan_destroyed {
get {
return ResourceManager.GetString("administration_text_chan_destroyed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unmuted.
/// </summary>
public static string administration_unmuted_sn {
get {
return ResourceManager.GetString("administration_unmuted_sn", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User Banned.
/// </summary>
public static string administration_user_banned {
get {
return ResourceManager.GetString("administration_user_banned", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} has been **muted** from chatting..
/// </summary>
@ -213,6 +510,24 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to User Joined.
/// </summary>
public static string administration_user_joined {
get {
return ResourceManager.GetString("administration_user_joined", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User Left.
/// </summary>
public static string administration_user_left {
get {
return ResourceManager.GetString("administration_user_left", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} has been **muted** from text and voice chat..
/// </summary>
@ -222,6 +537,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to User&apos;s Role Added.
/// </summary>
public static string administration_user_role_add {
get {
return ResourceManager.GetString("administration_user_role_add", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User&apos;s Role Removed.
/// </summary>
public static string administration_user_role_rem {
get {
return ResourceManager.GetString("administration_user_role_rem", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} is now {1}.
/// </summary>
public static string administration_user_status_change {
get {
return ResourceManager.GetString("administration_user_status_change", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} has been **unmuted** from text and voice chat..
/// </summary>
@ -231,6 +573,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to {0} has joined {1} voice channel..
/// </summary>
public static string administration_user_vjoined {
get {
return ResourceManager.GetString("administration_user_vjoined", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} has left {1} voice channel..
/// </summary>
public static string administration_user_vleft {
get {
return ResourceManager.GetString("administration_user_vleft", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} moved from {1} to {2} voice channel..
/// </summary>
public static string administration_user_vmoved {
get {
return ResourceManager.GetString("administration_user_vmoved", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} has been **voice muted**..
/// </summary>
@ -249,6 +618,87 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Username Changed.
/// </summary>
public static string administration_username_changed {
get {
return ResourceManager.GetString("administration_username_changed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Users.
/// </summary>
public static string administration_users {
get {
return ResourceManager.GetString("administration_users", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Voice Channel Destroyed.
/// </summary>
public static string administration_voice_chan_created {
get {
return ResourceManager.GetString("administration_voice_chan_created", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Voice Channel Destroyed.
/// </summary>
public static string administration_voice_chan_destroyed {
get {
return ResourceManager.GetString("administration_voice_chan_destroyed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User {0} from text chat.
/// </summary>
public static string administration_xmuted_text {
get {
return ResourceManager.GetString("administration_xmuted_text", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User {0} from text and voice chat.
/// </summary>
public static string administration_xmuted_text_and_voice {
get {
return ResourceManager.GetString("administration_xmuted_text_and_voice", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User {0} from voice chat.
/// </summary>
public static string administration_xmuted_voice {
get {
return ResourceManager.GetString("administration_xmuted_voice", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User Unbanned.
/// </summary>
public static string administraton_user_unbanned {
get {
return ResourceManager.GetString("administraton_user_unbanned", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Presence Updates.
/// </summary>
public static string adminsitration_presence_updates {
get {
return ResourceManager.GetString("adminsitration_presence_updates", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to That base is already claimed or destroyed..
/// </summary>

View File

@ -304,6 +304,28 @@
<data name="administration_aar_enabled" xml:space="preserve">
<value>**Auto assign role** on user join is now **enabled**.</value>
</data>
<data name="administration_attachments" xml:space="preserve">
<value>Attachments</value>
</data>
<data name="administration_avatar_changed" xml:space="preserve">
<value>Avatar Changed</value>
</data>
<data name="administration_banned_pl" xml:space="preserve">
<value>banned</value>
<comment>PLURAL</comment>
</data>
<data name="administration_ch_name_change" xml:space="preserve">
<value>Channel Name Changed</value>
</data>
<data name="administration_ch_old_name" xml:space="preserve">
<value>Old Name</value>
</data>
<data name="administration_ch_topic_change" xml:space="preserve">
<value>Channel Topic Changed</value>
</data>
<data name="administration_content" xml:space="preserve">
<value>Content</value>
</data>
<data name="administration_dm_from" xml:space="preserve">
<value>DM from</value>
</data>
@ -319,6 +341,9 @@
<data name="administration_fwdm_stop" xml:space="preserve">
<value>I will stop forwarding DMs from now on.</value>
</data>
<data name="administration_joined" xml:space="preserve">
<value>{0} has joined {1}</value>
</data>
<data name="administration_lang_list" xml:space="preserve">
<value>List Of Languages
{0}</value>
@ -338,30 +363,160 @@
<data name="administration_lang_set_show" xml:space="preserve">
<value>This server's language is set to {0} - {0}</value>
</data>
<data name="administration_left" xml:space="preserve">
<value>{0} has left {1}</value>
</data>
<data name="administration_log" xml:space="preserve">
<value>Logging {0} event in this channel.</value>
</data>
<data name="administration_log_all" xml:space="preserve">
<value>Logging all events in this channel.</value>
</data>
<data name="administration_log_disabled" xml:space="preserve">
<value>Logging disabled.</value>
</data>
<data name="administration_log_events" xml:space="preserve">
<value>Log events you can subscribe to:</value>
</data>
<data name="administration_log_ignore" xml:space="preserve">
<value>Logging will ignore {0}</value>
</data>
<data name="administration_log_not_ignore" xml:space="preserve">
<value>Logging will not ignore {0}</value>
</data>
<data name="administration_log_stop" xml:space="preserve">
<value>Stopped logging {0} event.</value>
</data>
<data name="administration_moved" xml:space="preserve">
<value>{0} moved from {1} to {2}</value>
</data>
<data name="administration_msg_del" xml:space="preserve">
<value>Message Deleted in #{0}</value>
</data>
<data name="administration_msg_update" xml:space="preserve">
<value>Message Updated in #{0}</value>
</data>
<data name="administration_muted_pl" xml:space="preserve">
<value>Muted</value>
<comment>PLURAL (users have been muted)</comment>
</data>
<data name="administration_muted_sn" xml:space="preserve">
<value>Muted</value>
<comment>singular "User muted."</comment>
</data>
<data name="administration_mute_error" xml:space="preserve">
<value>I don't have the permission necessary for that most likely.</value>
</data>
<data name="administration_mute_role_set" xml:space="preserve">
<value>New mute role set.</value>
</data>
<data name="administration_new_msg" xml:space="preserve">
<value>New Message</value>
</data>
<data name="administration_new_nick" xml:space="preserve">
<value>New Nickname</value>
</data>
<data name="administration_new_topic" xml:space="preserve">
<value>New Topic</value>
</data>
<data name="administration_nick_change" xml:space="preserve">
<value>Nickname Changed</value>
</data>
<data name="administration_old_msg" xml:space="preserve">
<value>Old Message</value>
</data>
<data name="administration_old_nick" xml:space="preserve">
<value>Old Nickname</value>
</data>
<data name="administration_old_topic" xml:space="preserve">
<value>Old Topic</value>
</data>
<data name="administration_soft_banned_pl" xml:space="preserve">
<value>soft-banned (kicked)</value>
<comment>PLURAL</comment>
</data>
<data name="administration_text_chan_created" xml:space="preserve">
<value>Text Channel Destroyed </value>
</data>
<data name="administration_text_chan_destroyed" xml:space="preserve">
<value>Text Channel Destroyed </value>
</data>
<data name="administration_unmuted_sn" xml:space="preserve">
<value>Unmuted</value>
<comment>singular</comment>
</data>
<data name="administration_username_changed" xml:space="preserve">
<value>Username Changed</value>
</data>
<data name="administration_users" xml:space="preserve">
<value>Users</value>
</data>
<data name="administration_user_banned" xml:space="preserve">
<value>User Banned</value>
</data>
<data name="administration_user_chat_mute" xml:space="preserve">
<value>{0} has been **muted** from chatting.</value>
</data>
<data name="administration_user_chat_unmute" xml:space="preserve">
<value>{0} has been **unmuted** from chatting.</value>
</data>
<data name="administration_user_joined" xml:space="preserve">
<value>User Joined</value>
</data>
<data name="administration_user_left" xml:space="preserve">
<value>User Left</value>
</data>
<data name="administration_user_muted" xml:space="preserve">
<value>{0} has been **muted** from text and voice chat.</value>
</data>
<data name="administration_user_role_add" xml:space="preserve">
<value>User's Role Added</value>
</data>
<data name="administration_user_role_rem" xml:space="preserve">
<value>User's Role Removed</value>
</data>
<data name="administration_user_status_change" xml:space="preserve">
<value>{0} is now {1}</value>
</data>
<data name="administration_user_unmuted" xml:space="preserve">
<value>{0} has been **unmuted** from text and voice chat.</value>
</data>
<data name="administration_user_vjoined" xml:space="preserve">
<value>{0} has joined {1} voice channel.</value>
</data>
<data name="administration_user_vleft" xml:space="preserve">
<value>{0} has left {1} voice channel.</value>
</data>
<data name="administration_user_vmoved" xml:space="preserve">
<value>{0} moved from {1} to {2} voice channel.</value>
</data>
<data name="administration_user_voice_mute" xml:space="preserve">
<value>{0} has been **voice muted**.</value>
</data>
<data name="administration_user_voice_unmute" xml:space="preserve">
<value>{0} has been **voice unmuted**.</value>
</data>
<data name="administration_voice_chan_created" xml:space="preserve">
<value>Voice Channel Destroyed</value>
</data>
<data name="administration_voice_chan_destroyed" xml:space="preserve">
<value>Voice Channel Destroyed</value>
</data>
<data name="administration_xmuted_text" xml:space="preserve">
<value>User {0} from text chat</value>
</data>
<data name="administration_xmuted_text_and_voice" xml:space="preserve">
<value>User {0} from text and voice chat</value>
</data>
<data name="administration_xmuted_voice" xml:space="preserve">
<value>User {0} from voice chat</value>
</data>
<data name="administraton_user_unbanned" xml:space="preserve">
<value>User Unbanned</value>
</data>
<data name="adminsitration_presence_updates" xml:space="preserve">
<value>Presence Updates</value>
</data>
<data name="help_back_to_toc" xml:space="preserve">
<value>Back to ToC</value>
</data>