logging localized >.<
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
@@ -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) =>
|
||||
|
Reference in New Issue
Block a user