NadekoBot/src/NadekoBot/Modules/Administration/Commands/LogCommand.cs

1061 lines
49 KiB
C#
Raw Normal View History

using Discord;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
2016-12-12 23:44:52 +00:00
using NadekoBot.Modules.Permissions;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using NLog;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
2016-12-29 13:56:15 +00:00
using System.Diagnostics;
using System.Linq;
2016-09-06 01:59:00 +00:00
using System.Threading;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Administration
{
public partial class Administration
{
[Group]
public class LogCommands : NadekoSubmodule
{
2017-04-15 00:54:19 +00:00
private static DiscordShardedClient Client { get; }
2017-02-14 18:06:02 +00:00
private new static Logger _log { get; }
2017-04-15 00:54:19 +00:00
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; }
2017-04-15 00:54:19 +00:00
private static ConcurrentDictionary<ITextChannel, List<string>> PresenceUpdates { get; } = new ConcurrentDictionary<ITextChannel, List<string>>();
2017-02-14 18:06:02 +00:00
private static readonly Timer _timerReference;
2016-09-06 01:59:00 +00:00
static LogCommands()
{
2017-04-15 00:54:19 +00:00
Client = NadekoBot.Client;
_log = LogManager.GetCurrentClassLogger();
2016-12-29 13:56:15 +00:00
var sw = Stopwatch.StartNew();
2017-04-15 00:54:19 +00:00
2017-02-14 13:30:21 +00:00
GuildLogSettings = new ConcurrentDictionary<ulong, LogSetting>(NadekoBot.AllGuildConfigs
.ToDictionary(g => g.GuildId, g => g.LogSetting));
2017-02-14 18:06:02 +00:00
_timerReference = new Timer(async (state) =>
2016-09-06 01:59:00 +00:00
{
2016-10-24 21:36:03 +00:00
try
{
2017-04-15 00:54:19 +00:00
var keys = PresenceUpdates.Keys.ToList();
2016-10-24 21:36:03 +00:00
await Task.WhenAll(keys.Select(async key =>
{
2017-04-15 00:54:19 +00:00
if (PresenceUpdates.TryRemove(key, out List<string> messages))
2017-02-14 18:06:02 +00:00
try { await key.SendConfirmAsync(key.Guild.GetLogText("presence_updates"), string.Join(Environment.NewLine, messages)); }
2017-02-14 13:30:21 +00:00
catch
{
// ignored
}
2016-10-24 21:36:03 +00:00
}));
}
catch (Exception ex)
2016-09-06 01:59:00 +00:00
{
2016-10-24 21:36:03 +00:00
_log.Warn(ex);
}
2017-01-08 23:33:42 +00:00
}, null, TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(15));
2016-12-29 13:56:15 +00:00
sw.Stop();
_log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s");
2016-09-06 01:59:00 +00:00
//_client.MessageReceived += _client_MessageReceived;
2017-04-15 00:54:19 +00:00
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
2017-04-15 00:54:19 +00:00
Client.UserUpdated += _client_UserUpdated;
#endif
2017-04-15 00:54:19 +00:00
Client.ChannelCreated += _client_ChannelCreated;
Client.ChannelDestroyed += _client_ChannelDestroyed;
Client.ChannelUpdated += _client_ChannelUpdated;
MuteCommands.UserMuted += MuteCommands_UserMuted;
MuteCommands.UserUnmuted += MuteCommands_UserUnmuted;
}
2017-01-15 01:28:33 +00:00
private static async Task _client_UserUpdated(SocketUser before, SocketUser uAfter)
{
try
{
2017-01-08 23:33:42 +00:00
var after = uAfter as SocketGuildUser;
2017-01-08 23:33:42 +00:00
if (after == null)
return;
2017-01-08 23:33:42 +00:00
var g = after.Guild;
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(g.Id, out LogSetting logSetting)
2017-01-08 23:33:42 +00:00
|| (logSetting.UserUpdatedId == null))
return;
2017-01-08 23:33:42 +00:00
ITextChannel logChannel;
if ((logChannel = await TryGetLogChannel(g, logSetting, LogType.UserUpdated)) == null)
return;
var embed = new EmbedBuilder();
2017-01-08 23:33:42 +00:00
if (before.Username != after.Username)
{
2017-02-14 18:06:02 +00:00
embed.WithTitle("👥 " + g.GetLogText("username_changed"))
.WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}")
2017-01-08 23:33:42 +00:00
.AddField(fb => fb.WithName("Old Name").WithValue($"{before.Username}").WithIsInline(true))
.AddField(fb => fb.WithName("New Name").WithValue($"{after.Username}").WithIsInline(true))
2017-04-15 00:54:19 +00:00
.WithFooter(fb => fb.WithText(CurrentTime))
2017-01-08 23:33:42 +00:00
.WithOkColor();
}
2017-04-15 00:54:19 +00:00
else if (before.AvatarId != after.AvatarId)
2017-01-08 23:33:42 +00:00
{
2017-02-14 18:06:02 +00:00
embed.WithTitle("👥" + g.GetLogText("avatar_changed"))
.WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}")
2017-04-15 00:54:19 +00:00
.WithThumbnailUrl(before.GetAvatarUrl())
.WithImageUrl(after.GetAvatarUrl())
.WithFooter(fb => fb.WithText(CurrentTime))
2017-01-08 23:33:42 +00:00
.WithOkColor();
}
2017-01-08 23:33:42 +00:00
else
{
return;
}
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
//var guildsMemberOf = NadekoBot.Client.GetGuilds().Where(g => g.Users.Select(u => u.Id).Contains(before.Id)).ToList();
//foreach (var g in guildsMemberOf)
//{
// LogSetting logSetting;
// if (!GuildLogSettings.TryGetValue(g.Id, out logSetting)
// || (logSetting.UserUpdatedId == null))
// return;
// ITextChannel logChannel;
// if ((logChannel = await TryGetLogChannel(g, logSetting, LogType.UserUpdated)) == null)
// return;
// try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch { }
//}
}
catch
2017-02-14 13:30:21 +00:00
{
// ignored
}
}
2017-01-15 01:28:33 +00:00
private static async Task _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
{
try
{
var usr = iusr as IGuildUser;
if (usr == null)
return;
var beforeVch = before.VoiceChannel;
var afterVch = after.VoiceChannel;
if (beforeVch == afterVch)
return;
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|| (logSetting.LogVoicePresenceTTSId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null)
return;
2017-01-08 23:33:42 +00:00
var str = "";
if (beforeVch?.Guild == afterVch?.Guild)
{
2017-02-14 18:06:02 +00:00
str = logChannel.Guild.GetLogText("moved", usr.Username, beforeVch?.Name, afterVch?.Name);
}
else if (beforeVch == null)
{
2017-02-14 18:06:02 +00:00
str = logChannel.Guild.GetLogText("joined", usr.Username, afterVch.Name);
}
else if (afterVch == null)
{
2017-02-14 18:06:02 +00:00
str = logChannel.Guild.GetLogText("left", usr.Username, beforeVch.Name);
}
var toDelete = await logChannel.SendMessageAsync(str, true).ConfigureAwait(false);
toDelete.DeleteAfter(5);
}
2017-02-14 13:30:21 +00:00
catch
{
// ignored
}
}
2017-01-01 12:57:38 +00:00
private static async void MuteCommands_UserMuted(IGuildUser usr, MuteCommands.MuteType muteType)
{
try
{
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|| (logSetting.UserMutedId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
return;
2017-02-14 13:30:21 +00:00
var mutes = "";
2017-02-14 18:06:02 +00:00
var mutedLocalized = logChannel.Guild.GetLogText("muted_sn");
switch (muteType)
{
case MuteCommands.MuteType.Voice:
2017-02-14 18:06:02 +00:00
mutes = "🔇 " + logChannel.Guild.GetLogText("xmuted_voice", mutedLocalized);
break;
case MuteCommands.MuteType.Chat:
2017-02-14 18:06:02 +00:00
mutes = "🔇 " + logChannel.Guild.GetLogText("xmuted_text", mutedLocalized);
break;
case MuteCommands.MuteType.All:
2017-02-14 18:06:02 +00:00
mutes = "🔇 " + logChannel.Guild.GetLogText("xmuted_text_and_voice", mutedLocalized);
break;
}
2017-01-08 23:33:42 +00:00
2017-02-14 18:06:02 +00:00
var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName(mutes))
2017-01-08 23:33:42 +00:00
.WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}")
2017-04-15 00:54:19 +00:00
.WithFooter(fb => fb.WithText(CurrentTime))
2017-01-08 23:33:42 +00:00
.WithOkColor();
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
}
2017-02-14 18:06:02 +00:00
catch
{
// ignored
}
}
2017-01-01 12:57:38 +00:00
private static async void MuteCommands_UserUnmuted(IGuildUser usr, MuteCommands.MuteType muteType)
{
try
{
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|| (logSetting.UserMutedId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
return;
2017-02-14 18:06:02 +00:00
var mutes = "";
var unmutedLocalized = logChannel.Guild.GetLogText("unmuted_sn");
switch (muteType)
{
case MuteCommands.MuteType.Voice:
2017-02-14 18:06:02 +00:00
mutes = "🔊 " + logChannel.Guild.GetLogText("xmuted_voice", unmutedLocalized);
break;
case MuteCommands.MuteType.Chat:
2017-02-14 18:06:02 +00:00
mutes = "🔊 " + logChannel.Guild.GetLogText("xmuted_text", unmutedLocalized);
break;
case MuteCommands.MuteType.All:
2017-02-14 18:06:02 +00:00
mutes = "🔊 " + logChannel.Guild.GetLogText("xmuted_text_and_voice", unmutedLocalized);
break;
}
2017-01-08 23:33:42 +00:00
2017-02-14 18:06:02 +00:00
var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName(mutes))
2017-01-08 23:33:42 +00:00
.WithTitle($"{usr.Username}#{usr.Discriminator} | {usr.Id}")
2017-04-15 00:54:19 +00:00
.WithFooter(fb => fb.WithText($"{CurrentTime}"))
2017-01-08 23:33:42 +00:00
.WithOkColor();
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
}
2017-02-14 18:06:02 +00:00
catch
{
// ignored
}
2016-09-06 01:59:00 +00:00
}
public static async Task TriggeredAntiProtection(IGuildUser[] users, PunishmentAction action, ProtectionType protection)
{
try
{
if (users.Length == 0)
return;
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out LogSetting logSetting)
|| (logSetting.LogOtherId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(users.First().Guild, logSetting, LogType.Other)) == null)
return;
var punishment = "";
2017-02-14 18:06:02 +00:00
switch (action)
{
2017-02-14 18:06:02 +00:00
case PunishmentAction.Mute:
punishment = "🔇 " + logChannel.Guild.GetLogText("muted_pl").ToUpperInvariant();
break;
case PunishmentAction.Kick:
punishment = "👢 " + logChannel.Guild.GetLogText("kicked_pl").ToUpperInvariant();
break;
case PunishmentAction.Softban:
2017-02-14 18:06:02 +00:00
punishment = "☣ " + logChannel.Guild.GetLogText("soft_banned_pl").ToUpperInvariant();
break;
case PunishmentAction.Ban:
punishment = "⛔️ " + logChannel.Guild.GetLogText("banned_pl").ToUpperInvariant();
break;
}
2017-01-08 23:33:42 +00:00
var embed = new EmbedBuilder().WithAuthor(eab => eab.WithName($"🛡 Anti-{protection}"))
2017-02-14 18:06:02 +00:00
.WithTitle(logChannel.Guild.GetLogText("users") + " " + punishment)
.WithDescription(string.Join("\n", users.Select(u => u.ToString())))
2017-04-15 00:54:19 +00:00
.WithFooter(fb => fb.WithText($"{CurrentTime}"))
2017-01-08 23:33:42 +00:00
.WithOkColor();
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
}
2017-02-14 18:06:02 +00:00
catch
{
// ignored
}
}
2017-01-15 01:28:33 +00:00
private static async Task _client_GuildUserUpdated(SocketGuildUser before, SocketGuildUser after)
2016-09-06 21:34:00 +00:00
{
try
2016-09-06 21:34:00 +00:00
{
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out LogSetting logSetting)
|| (logSetting.UserUpdatedId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null)
return;
2017-04-15 00:54:19 +00:00
var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText(CurrentTime))
2017-01-08 23:33:42 +00:00
.WithTitle($"{before.Username}#{before.Discriminator} | {before.Id}");
if (before.Nickname != after.Nickname)
2017-01-08 23:33:42 +00:00
{
2017-02-14 18:06:02 +00:00
embed.WithAuthor(eab => eab.WithName("👥 " + logChannel.Guild.GetLogText("nick_change")))
2017-01-08 23:33:42 +00:00
2017-02-14 18:06:02 +00:00
.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}"));
2017-01-08 23:33:42 +00:00
}
2017-04-15 00:54:19 +00:00
else if (!before.Roles.SequenceEqual(after.Roles))
2016-09-06 21:34:00 +00:00
{
2017-04-15 00:54:19 +00:00
if (before.Roles.Count < after.Roles.Count)
{
2017-04-15 00:54:19 +00:00
var diffRoles = after.Roles.Where(r => !before.Roles.Contains(r)).Select(r => r.Name);
2017-02-14 18:06:02 +00:00
embed.WithAuthor(eab => eab.WithName("⚔ " + logChannel.Guild.GetLogText("user_role_add")))
2017-01-08 23:33:42 +00:00
.WithDescription(string.Join(", ", diffRoles).SanitizeMentions());
}
2017-04-15 00:54:19 +00:00
else if (before.Roles.Count > after.Roles.Count)
2016-09-06 21:34:00 +00:00
{
2017-04-15 00:54:19 +00:00
var diffRoles = before.Roles.Where(r => !after.Roles.Contains(r)).Select(r => r.Name);
2017-02-14 18:06:02 +00:00
embed.WithAuthor(eab => eab.WithName("⚔ " + logChannel.Guild.GetLogText("user_role_rem")))
2017-01-08 23:33:42 +00:00
.WithDescription(string.Join(", ", diffRoles).SanitizeMentions());
2016-09-06 21:34:00 +00:00
}
}
else
return;
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
}
2017-02-14 18:06:02 +00:00
catch
{
// ignored
}
2016-09-06 21:34:00 +00:00
}
2017-01-15 01:28:33 +00:00
private static async Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
2016-09-06 01:59:00 +00:00
{
try
2016-09-06 01:59:00 +00:00
{
var before = cbefore as IGuildChannel;
if (before == null)
return;
var after = (IGuildChannel)cafter;
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out LogSetting logSetting)
|| (logSetting.ChannelUpdatedId == null)
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == after.Id))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated)) == null)
return;
2017-01-08 23:33:42 +00:00
2017-04-15 00:54:19 +00:00
var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText(CurrentTime));
2017-01-08 23:33:42 +00:00
var beforeTextChannel = cbefore as ITextChannel;
var afterTextChannel = cafter as ITextChannel;
if (before.Name != after.Name)
2017-01-08 23:33:42 +00:00
{
2017-02-14 18:06:02 +00:00
embed.WithTitle(" " + logChannel.Guild.GetLogText("ch_name_change"))
.WithDescription($"{after} | {after.Id}")
2017-02-14 18:06:02 +00:00
.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("ch_old_name")).WithValue(before.Name));
2017-01-08 23:33:42 +00:00
}
else if (beforeTextChannel?.Topic != afterTextChannel?.Topic)
{
2017-02-14 18:06:02 +00:00
embed.WithTitle(" " + logChannel.Guild.GetLogText("ch_topic_change"))
.WithDescription($"{after} | {after.Id}")
2017-02-14 18:06:02 +00:00
.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("old_topic")).WithValue(beforeTextChannel?.Topic ?? "-"))
.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("new_topic")).WithValue(afterTextChannel?.Topic ?? "-"));
2017-01-08 23:33:42 +00:00
}
2017-01-16 13:15:24 +00:00
else
return;
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
}
2017-02-14 18:06:02 +00:00
catch
{
// ignored
}
2016-09-06 01:59:00 +00:00
}
2017-01-15 01:28:33 +00:00
private static async Task _client_ChannelDestroyed(IChannel ich)
2016-09-06 01:59:00 +00:00
{
try
{
var ch = ich as IGuildChannel;
if (ch == null)
return;
2016-09-06 01:59:00 +00:00
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out LogSetting logSetting)
|| (logSetting.ChannelDestroyedId == null)
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == ch.Id))
return;
2016-09-06 01:59:00 +00:00
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null)
return;
2017-02-14 18:06:02 +00:00
string title;
if (ch is IVoiceChannel)
{
title = logChannel.Guild.GetLogText("voice_chan_destroyed");
}
else
title = logChannel.Guild.GetLogText("text_chan_destroyed");
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(new EmbedBuilder()
.WithOkColor()
2017-02-14 18:06:02 +00:00
.WithTitle("🆕 " + title)
2017-01-08 23:33:42 +00:00
.WithDescription($"{ch.Name} | {ch.Id}")
2017-04-15 00:54:19 +00:00
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false);
}
2017-02-14 18:06:02 +00:00
catch
{
// ignored
}
2016-09-06 01:59:00 +00:00
}
2017-01-15 01:28:33 +00:00
private static async Task _client_ChannelCreated(IChannel ich)
2016-09-06 01:59:00 +00:00
{
try
{
var ch = ich as IGuildChannel;
if (ch == null)
return;
2016-09-06 01:59:00 +00:00
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out LogSetting logSetting)
|| (logSetting.ChannelCreatedId == null))
return;
2016-09-06 01:59:00 +00:00
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null)
return;
2017-02-14 18:06:02 +00:00
string title;
if (ch is IVoiceChannel)
{
title = logChannel.Guild.GetLogText("voice_chan_created");
}
else
title = logChannel.Guild.GetLogText("text_chan_created");
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(new EmbedBuilder()
.WithOkColor()
2017-02-14 18:06:02 +00:00
.WithTitle("🆕 " + title)
2017-01-08 23:33:42 +00:00
.WithDescription($"{ch.Name} | {ch.Id}")
2017-04-15 00:54:19 +00:00
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false);
}
catch (Exception ex) { _log.Warn(ex); }
}
2017-01-15 01:28:33 +00:00
private static async Task _client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
{
try
{
var usr = iusr as IGuildUser;
if (usr == null)
return;
var beforeVch = before.VoiceChannel;
var afterVch = after.VoiceChannel;
if (beforeVch == afterVch)
return;
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|| (logSetting.LogVoicePresenceId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null)
return;
string str = null;
if (beforeVch?.Guild == afterVch?.Guild)
{
2017-04-15 00:54:19 +00:00
str = "🎙" + Format.Code(PrettyCurrentTime) + logChannel.Guild.GetLogText("user_vmoved",
2017-02-14 18:06:02 +00:00
"👤" + Format.Bold(usr.Username + "#" + usr.Discriminator),
Format.Bold(beforeVch?.Name ?? ""), Format.Bold(afterVch?.Name ?? ""));
}
else if (beforeVch == null)
{
2017-04-15 00:54:19 +00:00
str = "🎙" + Format.Code(PrettyCurrentTime) + logChannel.Guild.GetLogText("user_vjoined",
2017-02-14 18:06:02 +00:00
"👤" + Format.Bold(usr.Username + "#" + usr.Discriminator),
Format.Bold(afterVch.Name ?? ""));
}
else if (afterVch == null)
{
2017-04-15 00:54:19 +00:00
str = "🎙" + Format.Code(PrettyCurrentTime) + logChannel.Guild.GetLogText("user_vleft",
2017-02-28 09:35:36 +00:00
"👤" + Format.Bold(usr.Username + "#" + usr.Discriminator),
2017-02-14 18:06:02 +00:00
Format.Bold(beforeVch.Name ?? ""));
}
if (str != null)
2017-04-15 00:54:19 +00:00
PresenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; });
2017-02-14 18:06:02 +00:00
}
catch
{
// ignored
}
2016-12-31 16:34:21 +00:00
}
2017-01-15 01:28:33 +00:00
private static async Task _client_UserPresenceUpdated(Optional<SocketGuild> optGuild, SocketUser usr, SocketPresence before, SocketPresence after)
{
try
{
var guild = optGuild.GetValueOrDefault() ?? (usr as SocketGuildUser)?.Guild;
2016-12-31 16:34:21 +00:00
if (guild == null)
return;
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting)
|| (logSetting.LogUserPresenceId == null)
|| before.Status == after.Status)
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserPresence)) == null)
return;
string str = "";
if (before.Status != after.Status)
2017-04-15 00:54:19 +00:00
str = "🎭" + Format.Code(PrettyCurrentTime) +
2017-02-14 18:06:02 +00:00
logChannel.Guild.GetLogText("user_status_change",
"👤" + Format.Bold(usr.Username),
Format.Bold(after.Status.ToString()));
//if (before.Game?.Name != after.Game?.Name)
//{
// if (str != "")
// str += "\n";
// str += $"👾`{prettyCurrentTime}`👤__**{usr.Username}**__ is now playing **{after.Game?.Name}**.";
//}
2017-04-15 00:54:19 +00:00
PresenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; });
2017-02-14 18:06:02 +00:00
}
catch
{
// ignored
}
2016-12-31 16:34:21 +00:00
}
2016-09-06 01:59:00 +00:00
2017-01-15 01:28:33 +00:00
private static async Task _client_UserLeft(IGuildUser usr)
{
try
{
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|| (logSetting.UserLeftId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)) == null)
return;
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(new EmbedBuilder()
.WithOkColor()
2017-02-14 18:06:02 +00:00
.WithTitle("❌ " + logChannel.Guild.GetLogText("user_left"))
2017-04-15 00:54:19 +00:00
.WithThumbnailUrl(usr.GetAvatarUrl())
.WithDescription(usr.ToString())
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
2017-04-15 00:54:19 +00:00
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false);
}
2017-02-14 18:06:02 +00:00
catch
{
// ignored
}
}
2017-01-15 01:28:33 +00:00
private static async Task _client_UserJoined(IGuildUser usr)
{
try
{
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting)
|| (logSetting.UserJoinedId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null)
return;
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(new EmbedBuilder()
.WithOkColor()
2017-02-14 18:06:02 +00:00
.WithTitle("✅ " + logChannel.Guild.GetLogText("user_joined"))
2017-04-15 00:54:19 +00:00
.WithThumbnailUrl(usr.GetAvatarUrl())
.WithDescription($"{usr}")
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
2017-04-15 00:54:19 +00:00
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false);
}
catch (Exception ex) { _log.Warn(ex); }
}
2017-01-15 01:28:33 +00:00
private static async Task _client_UserUnbanned(IUser usr, IGuild guild)
{
try
{
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting)
|| (logSetting.UserUnbannedId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null)
return;
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(new EmbedBuilder()
.WithOkColor()
2017-02-14 18:06:02 +00:00
.WithTitle("♻️ " + logChannel.Guild.GetLogText("user_unbanned"))
2017-04-15 00:54:19 +00:00
.WithThumbnailUrl(usr.GetAvatarUrl())
.WithDescription(usr.ToString())
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
2017-04-15 00:54:19 +00:00
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false);
}
catch (Exception ex) { _log.Warn(ex); }
}
2017-01-15 01:28:33 +00:00
private static async Task _client_UserBanned(IUser usr, IGuild guild)
{
try
{
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting)
|| (logSetting.UserBannedId == null))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null)
return;
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(new EmbedBuilder()
.WithOkColor()
2017-02-14 18:06:02 +00:00
.WithTitle("🚫 " + logChannel.Guild.GetLogText("user_banned"))
2017-04-15 00:54:19 +00:00
.WithThumbnailUrl(usr.GetAvatarUrl())
.WithDescription(usr.ToString())
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
2017-04-15 00:54:19 +00:00
.WithFooter(efb => efb.WithText(CurrentTime))).ConfigureAwait(false);
}
catch (Exception ex) { _log.Warn(ex); }
}
2017-04-15 00:54:19 +00:00
private static async Task _client_MessageDeleted(Cacheable<IMessage, ulong> optMsg, ISocketMessageChannel ch)
{
2016-09-06 01:59:00 +00:00
try
{
2017-04-15 00:54:19 +00:00
var msg = (optMsg.HasValue ? optMsg.Value : null) as IUserMessage;
if (msg == null || msg.IsAuthor())
return;
2017-04-15 00:54:19 +00:00
var channel = ch as ITextChannel;
if (channel == null)
return;
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting)
|| (logSetting.MessageDeletedId == null)
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(channel.Guild, logSetting, LogType.MessageDeleted)) == null || logChannel.Id == msg.Id)
return;
2017-01-08 23:33:42 +00:00
var embed = new EmbedBuilder()
.WithOkColor()
2017-02-14 18:06:02 +00:00
.WithTitle("🗑 " + logChannel.Guild.GetLogText("msg_del", ((ITextChannel)msg.Channel).Name))
.WithDescription(msg.Author.ToString())
.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("content")).WithValue(string.IsNullOrWhiteSpace(msg.Content) ? "-" : msg.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false))
.AddField(efb => efb.WithName("Id").WithValue(msg.Id.ToString()).WithIsInline(false))
2017-04-15 00:54:19 +00:00
.WithFooter(efb => efb.WithText(CurrentTime));
if (msg.Attachments.Any())
2017-02-21 02:50:24 +00:00
embed.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("attachments")).WithValue(string.Join(", ", msg.Attachments.Select(a => a.Url))).WithIsInline(false));
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
}
catch (Exception ex)
2017-02-14 18:06:02 +00:00
{
_log.Warn(ex);
2017-02-14 18:06:02 +00:00
// ignored
}
}
2017-04-15 00:54:19 +00:00
private static async Task _client_MessageUpdated(Cacheable<IMessage, ulong> optmsg, SocketMessage imsg2, ISocketMessageChannel ch)
{
try
{
var after = imsg2 as IUserMessage;
if (after == null || after.IsAuthor())
return;
2017-04-15 00:54:19 +00:00
var before = (optmsg.HasValue ? optmsg.Value : null) as IUserMessage;
if (before == null)
return;
2017-04-15 00:54:19 +00:00
var channel = ch as ITextChannel;
if (channel == null)
return;
if (before.Content == after.Content)
return;
2017-04-15 00:54:19 +00:00
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting)
|| (logSetting.MessageUpdatedId == null)
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id))
return;
ITextChannel logChannel;
2016-12-31 16:34:21 +00:00
if ((logChannel = await TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated)) == null || logChannel.Id == after.Channel.Id)
return;
2017-01-08 23:33:42 +00:00
var embed = new EmbedBuilder()
.WithOkColor()
2017-02-14 18:06:02 +00:00
.WithTitle("📝 " + logChannel.Guild.GetLogText("msg_update", ((ITextChannel)after.Channel).Name))
.WithDescription(after.Author.ToString())
.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("old_msg")).WithValue(string.IsNullOrWhiteSpace(before.Content) ? "-" : before.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false))
.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("new_msg")).WithValue(string.IsNullOrWhiteSpace(after.Content) ? "-" : after.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false))
.AddField(efb => efb.WithName("Id").WithValue(after.Id.ToString()).WithIsInline(false))
2017-04-15 00:54:19 +00:00
.WithFooter(efb => efb.WithText(CurrentTime));
2017-01-08 23:33:42 +00:00
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
}
2017-02-14 18:06:02 +00:00
catch
{
// ignored
}
}
public enum LogType
{
2016-12-12 23:44:52 +00:00
Other,
MessageUpdated,
MessageDeleted,
UserJoined,
UserLeft,
UserBanned,
UserUnbanned,
UserUpdated,
ChannelCreated,
ChannelDestroyed,
ChannelUpdated,
UserPresence,
VoicePresence,
VoicePresenceTTS,
UserMuted
2016-12-12 23:44:52 +00:00
};
2016-12-31 16:34:21 +00:00
private static async Task<ITextChannel> TryGetLogChannel(IGuild guild, LogSetting logSetting, LogType logChannelType)
{
2016-12-12 23:44:52 +00:00
ulong? id = null;
switch (logChannelType)
{
2016-12-12 23:44:52 +00:00
case LogType.Other:
id = logSetting.LogOtherId;
break;
2016-12-12 23:44:52 +00:00
case LogType.MessageUpdated:
id = logSetting.MessageUpdatedId;
break;
2016-12-12 23:44:52 +00:00
case LogType.MessageDeleted:
id = logSetting.MessageDeletedId;
break;
case LogType.UserJoined:
id = logSetting.UserJoinedId;
break;
case LogType.UserLeft:
id = logSetting.UserLeftId;
break;
case LogType.UserBanned:
id = logSetting.UserBannedId;
break;
case LogType.UserUnbanned:
id = logSetting.UserUnbannedId;
break;
case LogType.UserUpdated:
id = logSetting.UserUpdatedId;
break;
case LogType.ChannelCreated:
id = logSetting.ChannelCreatedId;
break;
case LogType.ChannelDestroyed:
id = logSetting.ChannelDestroyedId;
break;
case LogType.ChannelUpdated:
id = logSetting.ChannelUpdatedId;
break;
2016-12-12 23:44:52 +00:00
case LogType.UserPresence:
id = logSetting.LogUserPresenceId;
break;
2016-12-12 23:44:52 +00:00
case LogType.VoicePresence:
id = logSetting.LogVoicePresenceId;
break;
2016-12-12 23:44:52 +00:00
case LogType.VoicePresenceTTS:
id = logSetting.LogVoicePresenceTTSId;
break;
case LogType.UserMuted:
id = logSetting.UserMutedId;
break;
}
2016-12-12 23:44:52 +00:00
if (!id.HasValue)
{
UnsetLogSetting(guild.Id, logChannelType);
return null;
}
2016-12-31 16:34:21 +00:00
var channel = await guild.GetTextChannelAsync(id.Value).ConfigureAwait(false);
if (channel == null)
2016-12-12 23:44:52 +00:00
{
UnsetLogSetting(guild.Id, logChannelType);
return null;
}
else
return channel;
}
2016-12-12 23:44:52 +00:00
private static void UnsetLogSetting(ulong guildId, LogType logChannelType)
{
using (var uow = DbHandler.UnitOfWork())
{
var newLogSetting = uow.GuildConfigs.LogSettingsFor(guildId).LogSetting;
2016-12-12 23:44:52 +00:00
switch (logChannelType)
{
case LogType.Other:
2016-12-25 07:10:27 +00:00
newLogSetting.LogOtherId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.MessageUpdated:
2016-12-25 07:10:27 +00:00
newLogSetting.MessageUpdatedId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.MessageDeleted:
2016-12-25 07:10:27 +00:00
newLogSetting.MessageDeletedId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.UserJoined:
2016-12-25 07:10:27 +00:00
newLogSetting.UserJoinedId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.UserLeft:
2016-12-25 07:10:27 +00:00
newLogSetting.UserLeftId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.UserBanned:
2016-12-25 07:10:27 +00:00
newLogSetting.UserBannedId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.UserUnbanned:
2016-12-25 07:10:27 +00:00
newLogSetting.UserUnbannedId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.UserUpdated:
2016-12-25 07:10:27 +00:00
newLogSetting.UserUpdatedId = null;
break;
case LogType.UserMuted:
newLogSetting.UserMutedId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.ChannelCreated:
2016-12-25 07:10:27 +00:00
newLogSetting.ChannelCreatedId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.ChannelDestroyed:
2016-12-25 07:10:27 +00:00
newLogSetting.ChannelDestroyedId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.ChannelUpdated:
2016-12-25 07:10:27 +00:00
newLogSetting.ChannelUpdatedId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.UserPresence:
2016-12-25 07:10:27 +00:00
newLogSetting.LogUserPresenceId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.VoicePresence:
2016-12-25 07:10:27 +00:00
newLogSetting.LogVoicePresenceId = null;
2016-12-12 23:44:52 +00:00
break;
case LogType.VoicePresenceTTS:
2016-12-25 07:10:27 +00:00
newLogSetting.LogVoicePresenceTTSId = null;
2016-12-12 23:44:52 +00:00
break;
}
GuildLogSettings.AddOrUpdate(guildId, newLogSetting, (gid, old) => newLogSetting);
uow.Complete();
}
}
public enum EnableDisable
{
2016-12-12 23:44:52 +00:00
Enable,
Disable
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
[OwnerOnly]
2017-01-01 11:54:02 +00:00
public async Task LogServer(PermissionAction action)
{
2017-01-01 11:54:44 +00:00
var channel = (ITextChannel)Context.Channel;
2016-09-06 01:59:00 +00:00
LogSetting logSetting;
using (var uow = DbHandler.UnitOfWork())
{
logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting;
2016-09-06 01:59:00 +00:00
GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting);
2016-12-12 23:44:52 +00:00
logSetting.LogOtherId =
logSetting.MessageUpdatedId =
logSetting.MessageDeletedId =
logSetting.UserJoinedId =
logSetting.UserLeftId =
logSetting.UserBannedId =
logSetting.UserUnbannedId =
logSetting.UserUpdatedId =
logSetting.ChannelCreatedId =
logSetting.ChannelDestroyedId =
logSetting.ChannelUpdatedId =
logSetting.LogUserPresenceId =
logSetting.LogVoicePresenceId =
2017-01-08 23:33:42 +00:00
logSetting.UserMutedId =
2016-12-12 23:44:52 +00:00
logSetting.LogVoicePresenceTTSId = (action.Value ? channel.Id : (ulong?)null);
await uow.CompleteAsync().ConfigureAwait(false);
}
2016-12-12 23:44:52 +00:00
if (action.Value)
2017-02-14 18:06:02 +00:00
await ReplyConfirmLocalized("log_all").ConfigureAwait(false);
else
2017-02-14 18:06:02 +00:00
await ReplyConfirmLocalized("log_disabled").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
[OwnerOnly]
2017-01-01 11:54:02 +00:00
public async Task LogIgnore()
{
2017-01-01 11:54:44 +00:00
var channel = (ITextChannel)Context.Channel;
int removed;
using (var uow = DbHandler.UnitOfWork())
{
var config = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id);
LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
2016-10-18 01:26:41 +00:00
config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
if (removed == 0)
2016-10-18 01:26:41 +00:00
{
var toAdd = new IgnoredLogChannel { ChannelId = channel.Id };
logSetting.IgnoredChannels.Add(toAdd);
config.LogSetting.IgnoredChannels.Add(toAdd);
}
await uow.CompleteAsync().ConfigureAwait(false);
}
if (removed == 0)
2017-02-14 18:06:02 +00:00
await ReplyConfirmLocalized("log_ignore", Format.Bold(channel.Mention + "(" + channel.Id + ")")).ConfigureAwait(false);
else
2017-02-14 18:06:02 +00:00
await ReplyConfirmLocalized("log_not_ignore", Format.Bold(channel.Mention + "(" + channel.Id + ")")).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
2016-09-06 01:59:00 +00:00
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
2016-12-24 13:13:48 +00:00
[OwnerOnly]
2017-01-01 11:54:02 +00:00
public async Task LogEvents()
2016-09-06 01:59:00 +00:00
{
2017-02-17 22:57:28 +00:00
await Context.Channel.SendConfirmAsync(GetText("log_events") + "\n" +
string.Join(", ", Enum.GetNames(typeof(LogType)).Cast<string>()))
.ConfigureAwait(false);
2016-09-06 01:59:00 +00:00
}
[NadekoCommand, Usage, Description, Aliases]
2016-09-06 21:34:00 +00:00
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
2016-12-24 13:13:48 +00:00
[OwnerOnly]
2017-01-01 11:54:02 +00:00
public async Task Log(LogType type)
2016-09-06 21:34:00 +00:00
{
2017-01-01 11:54:44 +00:00
var channel = (ITextChannel)Context.Channel;
2016-12-12 23:44:52 +00:00
ulong? channelId = null;
2016-09-06 21:34:00 +00:00
using (var uow = DbHandler.UnitOfWork())
{
var logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting;
2016-09-06 21:34:00 +00:00
GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting);
2016-12-12 23:44:52 +00:00
switch (type)
{
case LogType.Other:
channelId = logSetting.LogOtherId = (logSetting.LogOtherId == null ? channel.Id : default(ulong?));
break;
case LogType.MessageUpdated:
channelId = logSetting.MessageUpdatedId = (logSetting.MessageUpdatedId == null ? channel.Id : default(ulong?));
break;
case LogType.MessageDeleted:
channelId = logSetting.MessageDeletedId = (logSetting.MessageDeletedId == null ? channel.Id : default(ulong?));
break;
case LogType.UserJoined:
channelId = logSetting.UserJoinedId = (logSetting.UserJoinedId == null ? channel.Id : default(ulong?));
break;
case LogType.UserLeft:
channelId = logSetting.UserLeftId = (logSetting.UserLeftId == null ? channel.Id : default(ulong?));
break;
case LogType.UserBanned:
channelId = logSetting.UserBannedId = (logSetting.UserBannedId == null ? channel.Id : default(ulong?));
break;
case LogType.UserUnbanned:
channelId = logSetting.UserUnbannedId = (logSetting.UserUnbannedId == null ? channel.Id : default(ulong?));
break;
case LogType.UserUpdated:
channelId = logSetting.UserUpdatedId = (logSetting.UserUpdatedId == null ? channel.Id : default(ulong?));
break;
case LogType.UserMuted:
channelId = logSetting.UserMutedId = (logSetting.UserMutedId == null ? channel.Id : default(ulong?));
break;
2016-12-12 23:44:52 +00:00
case LogType.ChannelCreated:
channelId = logSetting.ChannelCreatedId = (logSetting.ChannelCreatedId == null ? channel.Id : default(ulong?));
break;
case LogType.ChannelDestroyed:
channelId = logSetting.ChannelDestroyedId = (logSetting.ChannelDestroyedId == null ? channel.Id : default(ulong?));
break;
case LogType.ChannelUpdated:
channelId = logSetting.ChannelUpdatedId = (logSetting.ChannelUpdatedId == null ? channel.Id : default(ulong?));
break;
case LogType.UserPresence:
channelId = logSetting.LogUserPresenceId = (logSetting.LogUserPresenceId == null ? channel.Id : default(ulong?));
break;
case LogType.VoicePresence:
channelId = logSetting.LogVoicePresenceId = (logSetting.LogVoicePresenceId == null ? channel.Id : default(ulong?));
break;
case LogType.VoicePresenceTTS:
channelId = logSetting.LogVoicePresenceTTSId = (logSetting.LogVoicePresenceTTSId == null ? channel.Id : default(ulong?));
break;
}
2016-09-06 21:34:00 +00:00
await uow.CompleteAsync().ConfigureAwait(false);
}
2016-12-12 23:44:52 +00:00
if (channelId != null)
2017-02-14 18:06:02 +00:00
await ReplyConfirmLocalized("log", Format.Bold(type.ToString())).ConfigureAwait(false);
2016-09-06 21:34:00 +00:00
else
2017-02-14 18:06:02 +00:00
await ReplyConfirmLocalized("log_stop", Format.Bold(type.ToString())).ConfigureAwait(false);
2016-09-06 21:34:00 +00:00
}
}
}
2017-02-14 18:06:02 +00:00
public static class GuildExtensions
{
public static string GetLogText(this IGuild guild, string key, params object[] replacements)
=> NadekoTopLevelModule.GetTextStatic(key,
2017-02-14 18:06:02 +00:00
NadekoBot.Localization.GetCultureInfo(guild),
typeof(Administration).Name.ToLowerInvariant(),
replacements);
}
}