2016-09-05 10:27:58 +00:00
|
|
|
|
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;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
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;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
using System.Linq;
|
2016-09-06 01:59:00 +00:00
|
|
|
|
using System.Threading;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Administration
|
|
|
|
|
{
|
|
|
|
|
public partial class Administration
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-02-14 14:41:23 +00:00
|
|
|
|
public class LogCommands : NadekoSubmodule
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2017-02-14 18:06:02 +00:00
|
|
|
|
private static DiscordShardedClient client { get; }
|
|
|
|
|
private new static Logger _log { get; }
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-11-08 21:22:39 +00:00
|
|
|
|
private static string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
|
2017-01-12 17:18:16 +00:00
|
|
|
|
private static string currentTime => $"{DateTime.Now:HH:mm:ss}";
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-11-08 21:22:39 +00:00
|
|
|
|
public static ConcurrentDictionary<ulong, LogSetting> GuildLogSettings { get; }
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2017-02-14 18:06:02 +00:00
|
|
|
|
private static ConcurrentDictionary<ITextChannel, List<string>> presenceUpdates { get; } = new ConcurrentDictionary<ITextChannel, List<string>>();
|
|
|
|
|
private static readonly Timer _timerReference;
|
2016-09-06 01:59:00 +00:00
|
|
|
|
|
2016-11-08 21:22:39 +00:00
|
|
|
|
static LogCommands()
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2017-02-14 18:06:02 +00:00
|
|
|
|
client = NadekoBot.Client;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
_log = LogManager.GetCurrentClassLogger();
|
2016-12-29 13:56:15 +00:00
|
|
|
|
var sw = Stopwatch.StartNew();
|
2017-02-14 13:30:21 +00:00
|
|
|
|
|
|
|
|
|
GuildLogSettings = new ConcurrentDictionary<ulong, LogSetting>(NadekoBot.AllGuildConfigs
|
|
|
|
|
.ToDictionary(g => g.GuildId, g => g.LogSetting));
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
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-02-14 18:06:02 +00:00
|
|
|
|
var keys = presenceUpdates.Keys.ToList();
|
2016-09-10 19:40:25 +00:00
|
|
|
|
|
2016-10-24 21:36:03 +00:00
|
|
|
|
await Task.WhenAll(keys.Select(async key =>
|
|
|
|
|
{
|
|
|
|
|
List<string> messages;
|
2017-02-14 18:06:02 +00:00
|
|
|
|
if (presenceUpdates.TryRemove(key, out messages))
|
|
|
|
|
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
|
|
|
|
|
2016-09-26 17:23:01 +00:00
|
|
|
|
//_client.MessageReceived += _client_MessageReceived;
|
2017-02-14 18:06:02 +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;
|
2017-01-07 18:56:44 +00:00
|
|
|
|
#if !GLOBAL_NADEKO
|
2017-02-14 18:06:02 +00:00
|
|
|
|
client.UserUpdated += _client_UserUpdated;
|
2017-01-07 18:56:44 +00:00
|
|
|
|
#endif
|
2017-02-14 18:06:02 +00:00
|
|
|
|
client.ChannelCreated += _client_ChannelCreated;
|
|
|
|
|
client.ChannelDestroyed += _client_ChannelDestroyed;
|
|
|
|
|
client.ChannelUpdated += _client_ChannelUpdated;
|
2016-12-13 03:49:44 +00:00
|
|
|
|
|
|
|
|
|
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)
|
2017-01-07 18:56:44 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-01-08 23:33:42 +00:00
|
|
|
|
var after = uAfter as SocketGuildUser;
|
2017-01-07 18:56:44 +00:00
|
|
|
|
|
2017-01-08 23:33:42 +00:00
|
|
|
|
if (after == null)
|
2017-01-07 19:40:10 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2017-01-08 23:33:42 +00:00
|
|
|
|
var g = after.Guild;
|
|
|
|
|
|
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(g.Id, out logSetting)
|
|
|
|
|
|| (logSetting.UserUpdatedId == null))
|
|
|
|
|
return;
|
2017-01-07 18:56:44 +00:00
|
|
|
|
|
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-07 18:56:44 +00:00
|
|
|
|
|
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"))
|
2017-01-09 10:56:40 +00:00
|
|
|
|
.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))
|
|
|
|
|
.WithFooter(fb => fb.WithText(currentTime))
|
|
|
|
|
.WithOkColor();
|
|
|
|
|
}
|
|
|
|
|
else if (before.AvatarUrl != after.AvatarUrl)
|
|
|
|
|
{
|
2017-02-14 18:06:02 +00:00
|
|
|
|
embed.WithTitle("👥" + g.GetLogText("avatar_changed"))
|
2017-01-09 10:56:40 +00:00
|
|
|
|
.WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}")
|
2017-01-08 23:33:42 +00:00
|
|
|
|
.WithTitle($"{before.Username}#{before.Discriminator} | {before.Id}")
|
|
|
|
|
.WithThumbnailUrl(before.AvatarUrl)
|
|
|
|
|
.WithImageUrl(after.AvatarUrl)
|
|
|
|
|
.WithFooter(fb => fb.WithText(currentTime))
|
|
|
|
|
.WithOkColor();
|
2017-01-07 18:56:44 +00:00
|
|
|
|
}
|
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 { }
|
|
|
|
|
//}
|
2017-01-07 18:56:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
2017-02-14 13:30:21 +00:00
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2017-01-07 18:56:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:28:33 +00:00
|
|
|
|
private static async Task _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
|
2016-12-27 05:25:41 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var usr = iusr as IGuildUser;
|
|
|
|
|
if (usr == null)
|
|
|
|
|
return;
|
2016-12-27 05:25:41 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
var beforeVch = before.VoiceChannel;
|
|
|
|
|
var afterVch = after.VoiceChannel;
|
2016-12-27 05:25:41 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
if (beforeVch == afterVch)
|
|
|
|
|
return;
|
2016-12-27 05:25:41 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
|
|
|
|
|| (logSetting.LogVoicePresenceTTSId == null))
|
|
|
|
|
return;
|
2016-12-27 05:25:41 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
ITextChannel logChannel;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS)) == null)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
return;
|
2016-12-27 05:25:41 +00:00
|
|
|
|
|
2017-01-08 23:33:42 +00:00
|
|
|
|
var str = "";
|
2016-12-28 05:31:39 +00:00
|
|
|
|
if (beforeVch?.Guild == afterVch?.Guild)
|
2016-12-27 05:25:41 +00:00
|
|
|
|
{
|
2017-02-14 18:06:02 +00:00
|
|
|
|
str = logChannel.Guild.GetLogText("moved", usr.Username, beforeVch?.Name, afterVch?.Name);
|
2016-12-27 05:25:41 +00:00
|
|
|
|
}
|
2016-12-28 05:31:39 +00:00
|
|
|
|
else if (beforeVch == null)
|
|
|
|
|
{
|
2017-02-14 18:06:02 +00:00
|
|
|
|
str = logChannel.Guild.GetLogText("joined", usr.Username, afterVch.Name);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
else if (afterVch == null)
|
|
|
|
|
{
|
2017-02-14 18:06:02 +00:00
|
|
|
|
str = logChannel.Guild.GetLogText("left", usr.Username, beforeVch.Name);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
var toDelete = await logChannel.SendMessageAsync(str, true).ConfigureAwait(false);
|
|
|
|
|
toDelete.DeleteAfter(5);
|
|
|
|
|
}
|
2017-02-14 13:30:21 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-12-27 05:25:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-01 12:57:38 +00:00
|
|
|
|
private static async void MuteCommands_UserMuted(IGuildUser usr, MuteCommands.MuteType muteType)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out 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)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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");
|
2016-12-13 03:49:44 +00:00
|
|
|
|
switch (muteType)
|
|
|
|
|
{
|
|
|
|
|
case MuteCommands.MuteType.Voice:
|
2017-02-14 18:06:02 +00:00
|
|
|
|
mutes = "🔇 " + logChannel.Guild.GetLogText("xmuted_voice", mutedLocalized);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case MuteCommands.MuteType.Chat:
|
2017-02-14 18:06:02 +00:00
|
|
|
|
mutes = "🔇 " + logChannel.Guild.GetLogText("xmuted_text", mutedLocalized);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case MuteCommands.MuteType.All:
|
2017-02-14 18:06:02 +00:00
|
|
|
|
mutes = "🔇 " + logChannel.Guild.GetLogText("xmuted_text_and_voice", mutedLocalized);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
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}")
|
|
|
|
|
.WithFooter(fb => fb.WithText(currentTime))
|
|
|
|
|
.WithOkColor();
|
|
|
|
|
|
|
|
|
|
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
2017-02-14 18:06:02 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-12-13 03:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-01 12:57:38 +00:00
|
|
|
|
private static async void MuteCommands_UserUnmuted(IGuildUser usr, MuteCommands.MuteType muteType)
|
2016-12-13 03:49:44 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
|
|
|
|
|| (logSetting.UserMutedId == null))
|
|
|
|
|
return;
|
2016-12-13 03:49:44 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
ITextChannel logChannel;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted)) == null)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
return;
|
2016-12-13 03:49:44 +00:00
|
|
|
|
|
2017-02-14 18:06:02 +00:00
|
|
|
|
var mutes = "";
|
|
|
|
|
var unmutedLocalized = logChannel.Guild.GetLogText("unmuted_sn");
|
2016-12-13 03:49:44 +00:00
|
|
|
|
switch (muteType)
|
|
|
|
|
{
|
|
|
|
|
case MuteCommands.MuteType.Voice:
|
2017-02-14 18:06:02 +00:00
|
|
|
|
mutes = "🔊 " + logChannel.Guild.GetLogText("xmuted_voice", unmutedLocalized);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case MuteCommands.MuteType.Chat:
|
2017-02-14 18:06:02 +00:00
|
|
|
|
mutes = "🔊 " + logChannel.Guild.GetLogText("xmuted_text", unmutedLocalized);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case MuteCommands.MuteType.All:
|
2017-02-14 18:06:02 +00:00
|
|
|
|
mutes = "🔊 " + logChannel.Guild.GetLogText("xmuted_text_and_voice", unmutedLocalized);
|
2016-12-13 03:49:44 +00:00
|
|
|
|
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}")
|
|
|
|
|
.WithFooter(fb => fb.WithText($"{currentTime}"))
|
|
|
|
|
.WithOkColor();
|
|
|
|
|
|
|
|
|
|
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
2017-02-14 18:06:02 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-09-06 01:59:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 21:22:39 +00:00
|
|
|
|
public static async Task TriggeredAntiProtection(IGuildUser[] users, PunishmentAction action, ProtectionType protection)
|
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
2016-11-08 21:22:39 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
if (users.Length == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out 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)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var punishment = "";
|
2017-02-14 18:06:02 +00:00
|
|
|
|
switch (action)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
{
|
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("soft_banned_pl").ToUpperInvariant();
|
|
|
|
|
break;
|
|
|
|
|
case PunishmentAction.Ban:
|
|
|
|
|
punishment = "⛔️ " + logChannel.Guild.GetLogText("banned_pl").ToUpperInvariant();
|
|
|
|
|
break;
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
2017-01-08 23:33:42 +00:00
|
|
|
|
|
2017-01-09 10:56:40 +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-01-08 23:33:42 +00:00
|
|
|
|
.WithFooter(fb => fb.WithText($"{currentTime}"))
|
|
|
|
|
.WithOkColor();
|
|
|
|
|
|
|
|
|
|
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-11-08 21:22:39 +00:00
|
|
|
|
}
|
2017-02-14 18:06:02 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-11-08 21:22:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
2016-09-06 21:34:00 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out 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)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
return;
|
2017-01-08 23:33:42 +00:00
|
|
|
|
var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText(currentTime))
|
|
|
|
|
.WithTitle($"{before.Username}#{before.Discriminator} | {before.Id}");
|
2017-01-07 18:56:44 +00:00
|
|
|
|
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
|
|
|
|
}
|
2016-12-31 16:34:21 +00:00
|
|
|
|
else if (!before.RoleIds.SequenceEqual(after.RoleIds))
|
2016-09-06 21:34:00 +00:00
|
|
|
|
{
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if (before.RoleIds.Count < after.RoleIds.Count)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
{
|
2017-01-08 23:33:42 +00:00
|
|
|
|
var diffRoles = after.RoleIds.Where(r => !before.RoleIds.Contains(r)).Select(r => before.Guild.GetRole(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());
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
2016-12-31 16:34:21 +00:00
|
|
|
|
else if (before.RoleIds.Count > after.RoleIds.Count)
|
2016-09-06 21:34:00 +00:00
|
|
|
|
{
|
2017-01-08 23:33:42 +00:00
|
|
|
|
var diffRoles = before.RoleIds.Where(r => !after.RoleIds.Contains(r)).Select(r => before.Guild.GetRole(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
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-28 05:31:39 +00:00
|
|
|
|
else
|
|
|
|
|
return;
|
2017-01-08 23:33:42 +00:00
|
|
|
|
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
2016-09-06 01:59:00 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
var before = cbefore as IGuildChannel;
|
|
|
|
|
if (before == null)
|
|
|
|
|
return;
|
|
|
|
|
var after = (IGuildChannel)cafter;
|
|
|
|
|
|
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out 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)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
return;
|
2017-01-08 23:33:42 +00:00
|
|
|
|
|
|
|
|
|
var embed = new EmbedBuilder().WithOkColor().WithFooter(efb => efb.WithText(currentTime));
|
|
|
|
|
|
|
|
|
|
var beforeTextChannel = cbefore as ITextChannel;
|
|
|
|
|
var afterTextChannel = cafter as ITextChannel;
|
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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"))
|
2017-01-09 10:56:40 +00:00
|
|
|
|
.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"))
|
2017-01-09 10:56:40 +00:00
|
|
|
|
.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);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var ch = ich as IGuildChannel;
|
|
|
|
|
if (ch == null)
|
|
|
|
|
return;
|
2016-09-06 01:59:00 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting)
|
|
|
|
|
|| (logSetting.ChannelDestroyedId == null)
|
|
|
|
|
|| logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == ch.Id))
|
|
|
|
|
return;
|
2016-09-06 01:59:00 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
ITextChannel logChannel;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed)) == null)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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}")
|
|
|
|
|
.WithFooter(efb => efb.WithText(currentTime))).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var ch = ich as IGuildChannel;
|
|
|
|
|
if (ch == null)
|
|
|
|
|
return;
|
2016-09-06 01:59:00 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out logSetting)
|
|
|
|
|
|| (logSetting.ChannelCreatedId == null))
|
|
|
|
|
return;
|
2016-09-06 01:59:00 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
ITextChannel logChannel;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated)) == null)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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}")
|
|
|
|
|
.WithFooter(efb => efb.WithText(currentTime))).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { _log.Warn(ex); }
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:28:33 +00:00
|
|
|
|
private static async Task _client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var usr = iusr as IGuildUser;
|
|
|
|
|
if (usr == null)
|
|
|
|
|
return;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
var beforeVch = before.VoiceChannel;
|
|
|
|
|
var afterVch = after.VoiceChannel;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
if (beforeVch == afterVch)
|
|
|
|
|
return;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
|
|
|
|
|| (logSetting.LogVoicePresenceId == null))
|
|
|
|
|
return;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
ITextChannel logChannel;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence)) == null)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
return;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
string str = null;
|
|
|
|
|
if (beforeVch?.Guild == afterVch?.Guild)
|
|
|
|
|
{
|
2017-02-14 18:06:02 +00:00
|
|
|
|
str = "🎙" + Format.Code(prettyCurrentTime) + logChannel.Guild.GetLogText("user_vmoved",
|
|
|
|
|
"👤" + Format.Bold(usr.Username + "#" + usr.Discriminator),
|
|
|
|
|
Format.Bold(beforeVch?.Name ?? ""), Format.Bold(afterVch?.Name ?? ""));
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
else if (beforeVch == null)
|
|
|
|
|
{
|
2017-02-14 18:06:02 +00:00
|
|
|
|
str = "🎙" + Format.Code(prettyCurrentTime) + logChannel.Guild.GetLogText("user_vjoined",
|
|
|
|
|
"👤" + Format.Bold(usr.Username + "#" + usr.Discriminator),
|
|
|
|
|
Format.Bold(afterVch.Name ?? ""));
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
else if (afterVch == null)
|
|
|
|
|
{
|
2017-02-14 18:06:02 +00:00
|
|
|
|
str = "🎙" + Format.Code(prettyCurrentTime) + logChannel.Guild.GetLogText("user_vleft",
|
|
|
|
|
"👤" + Format.Code(prettyCurrentTime), "👤" + Format.Bold(usr.Username + "#" + usr.Discriminator),
|
|
|
|
|
Format.Bold(beforeVch.Name ?? ""));
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
if (str != null)
|
2017-02-14 18:06:02 +00:00
|
|
|
|
presenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; });
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
2016-12-24 05:21:51 +00:00
|
|
|
|
}
|
2016-12-31 16:34:21 +00:00
|
|
|
|
}
|
2016-09-05 10:27:58 +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)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-01-09 10:56:40 +00:00
|
|
|
|
var guild = optGuild.GetValueOrDefault() ?? (usr as SocketGuildUser)?.Guild;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
|
|
|
|
|
if (guild == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
|| (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)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
return;
|
2017-01-09 10:56:40 +00:00
|
|
|
|
string str = "";
|
2016-12-28 05:31:39 +00:00
|
|
|
|
if (before.Status != after.Status)
|
2017-02-14 18:06:02 +00:00
|
|
|
|
str = "🎭" + Format.Code(prettyCurrentTime) +
|
|
|
|
|
logChannel.Guild.GetLogText("user_status_change",
|
|
|
|
|
"👤" + Format.Bold(usr.Username),
|
|
|
|
|
Format.Bold(after.Status.ToString()));
|
2017-01-09 10:56:40 +00:00
|
|
|
|
|
|
|
|
|
//if (before.Game?.Name != after.Game?.Name)
|
|
|
|
|
//{
|
|
|
|
|
// if (str != "")
|
|
|
|
|
// str += "\n";
|
|
|
|
|
// str += $"👾`{prettyCurrentTime}`👤__**{usr.Username}**__ is now playing **{after.Game?.Name}**.";
|
|
|
|
|
//}
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2017-02-14 18:06:02 +00:00
|
|
|
|
presenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; });
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
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)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out 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)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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-01-08 23:33:42 +00:00
|
|
|
|
.WithThumbnailUrl(usr.AvatarUrl)
|
2017-01-09 10:56:40 +00:00
|
|
|
|
.WithDescription(usr.ToString())
|
|
|
|
|
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
|
2017-01-08 23:33:42 +00:00
|
|
|
|
.WithFooter(efb => efb.WithText(currentTime))).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
2017-02-14 18:06:02 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:28:33 +00:00
|
|
|
|
private static async Task _client_UserJoined(IGuildUser usr)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
|
|
|
|
|| (logSetting.UserJoinedId == null))
|
|
|
|
|
return;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
ITextChannel logChannel;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined)) == null)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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-01-08 23:33:42 +00:00
|
|
|
|
.WithThumbnailUrl(usr.AvatarUrl)
|
2017-01-09 10:56:40 +00:00
|
|
|
|
.WithDescription($"{usr}")
|
|
|
|
|
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
|
2017-01-08 23:33:42 +00:00
|
|
|
|
.WithFooter(efb => efb.WithText(currentTime))).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { _log.Warn(ex); }
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:28:33 +00:00
|
|
|
|
private static async Task _client_UserUnbanned(IUser usr, IGuild guild)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|
|
|
|
|
|| (logSetting.UserUnbannedId == null))
|
|
|
|
|
return;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
ITextChannel logChannel;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserUnbanned)) == null)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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-01-09 10:56:40 +00:00
|
|
|
|
.WithThumbnailUrl(usr.AvatarUrl)
|
|
|
|
|
.WithDescription(usr.ToString())
|
|
|
|
|
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
|
2017-01-08 23:33:42 +00:00
|
|
|
|
.WithFooter(efb => efb.WithText(currentTime))).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { _log.Warn(ex); }
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:28:33 +00:00
|
|
|
|
private static async Task _client_UserBanned(IUser usr, IGuild guild)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|
|
|
|
|
|| (logSetting.UserBannedId == null))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ITextChannel logChannel;
|
2016-12-31 16:34:21 +00:00
|
|
|
|
if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserBanned)) == null)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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-01-09 10:56:40 +00:00
|
|
|
|
.WithThumbnailUrl(usr.AvatarUrl)
|
|
|
|
|
.WithDescription(usr.ToString())
|
|
|
|
|
.AddField(efb => efb.WithName("Id").WithValue(usr.Id.ToString()))
|
2017-01-08 23:33:42 +00:00
|
|
|
|
.WithFooter(efb => efb.WithText(currentTime))).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) { _log.Warn(ex); }
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:28:33 +00:00
|
|
|
|
private static async Task _client_MessageDeleted(ulong arg1, Optional<SocketMessage> imsg)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-09-06 01:59:00 +00:00
|
|
|
|
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
var msg = (imsg.IsSpecified ? imsg.Value : null) as IUserMessage;
|
|
|
|
|
if (msg == null || msg.IsAuthor())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var channel = msg.Channel as ITextChannel;
|
|
|
|
|
if (channel == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out 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)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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))
|
2017-02-21 02:27:30 +00:00
|
|
|
|
.WithDescription(msg.Author.ToString())
|
|
|
|
|
.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("content")).WithValue(string.IsNullOrWhiteSpace(msg.Content) ? "-" : msg.Resolve(userHandling: TagHandling.FullName)).WithIsInline(false))
|
2017-01-09 10:56:40 +00:00
|
|
|
|
.AddField(efb => efb.WithName("Id").WithValue(msg.Id.ToString()).WithIsInline(false))
|
2017-01-08 23:33:42 +00:00
|
|
|
|
.WithFooter(efb => efb.WithText(currentTime));
|
2016-12-28 05:31:39 +00:00
|
|
|
|
if (msg.Attachments.Any())
|
2017-02-14 18:06:02 +00:00
|
|
|
|
embed.AddField(efb => efb.WithName(logChannel.Guild.GetLogText("attachments")).WithValue(string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))).WithIsInline(false));
|
2017-01-08 23:33:42 +00:00
|
|
|
|
|
|
|
|
|
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
2017-02-21 02:27:30 +00:00
|
|
|
|
catch (Exception ex)
|
2017-02-14 18:06:02 +00:00
|
|
|
|
{
|
2017-02-21 02:27:30 +00:00
|
|
|
|
_log.Warn(ex);
|
2017-02-14 18:06:02 +00:00
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:28:33 +00:00
|
|
|
|
private static async Task _client_MessageUpdated(Optional<SocketMessage> optmsg, SocketMessage imsg2)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
try
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-28 05:31:39 +00:00
|
|
|
|
var after = imsg2 as IUserMessage;
|
|
|
|
|
if (after == null || after.IsAuthor())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var before = (optmsg.IsSpecified ? optmsg.Value : null) as IUserMessage;
|
|
|
|
|
if (before == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var channel = after.Channel as ITextChannel;
|
|
|
|
|
if (channel == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (before.Content == after.Content)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LogSetting logSetting;
|
|
|
|
|
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out 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)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
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))
|
2017-01-09 10:56:40 +00:00
|
|
|
|
.WithDescription(after.Author.ToString())
|
2017-02-21 02:27:30 +00:00
|
|
|
|
.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))
|
2017-01-09 10:56:40 +00:00
|
|
|
|
.AddField(efb => efb.WithName("Id").WithValue(after.Id.ToString()).WithIsInline(false))
|
2017-01-08 23:33:42 +00:00
|
|
|
|
.WithFooter(efb => efb.WithText(currentTime));
|
|
|
|
|
|
|
|
|
|
await logChannel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-12-28 05:31:39 +00:00
|
|
|
|
}
|
2017-02-14 18:06:02 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-24 05:21:51 +00:00
|
|
|
|
public enum LogType
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-12 23:44:52 +00:00
|
|
|
|
Other,
|
|
|
|
|
MessageUpdated,
|
|
|
|
|
MessageDeleted,
|
|
|
|
|
UserJoined,
|
|
|
|
|
UserLeft,
|
|
|
|
|
UserBanned,
|
|
|
|
|
UserUnbanned,
|
|
|
|
|
UserUpdated,
|
|
|
|
|
ChannelCreated,
|
|
|
|
|
ChannelDestroyed,
|
|
|
|
|
ChannelUpdated,
|
|
|
|
|
UserPresence,
|
|
|
|
|
VoicePresence,
|
2016-12-24 05:21:51 +00:00
|
|
|
|
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-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-12 23:44:52 +00:00
|
|
|
|
ulong? id = null;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
switch (logChannelType)
|
|
|
|
|
{
|
2016-12-12 23:44:52 +00:00
|
|
|
|
case LogType.Other:
|
|
|
|
|
id = logSetting.LogOtherId;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
break;
|
2016-12-12 23:44:52 +00:00
|
|
|
|
case LogType.MessageUpdated:
|
|
|
|
|
id = logSetting.MessageUpdatedId;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
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;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
break;
|
2016-12-12 23:44:52 +00:00
|
|
|
|
case LogType.UserPresence:
|
|
|
|
|
id = logSetting.LogUserPresenceId;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
break;
|
2016-12-12 23:44:52 +00:00
|
|
|
|
case LogType.VoicePresence:
|
|
|
|
|
id = logSetting.LogVoicePresenceId;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
break;
|
2016-12-12 23:44:52 +00:00
|
|
|
|
case LogType.VoicePresenceTTS:
|
|
|
|
|
id = logSetting.LogVoicePresenceTTSId;
|
|
|
|
|
break;
|
2016-12-24 05:21:51 +00:00
|
|
|
|
case LogType.UserMuted:
|
|
|
|
|
id = logSetting.UserMutedId;
|
|
|
|
|
break;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
2016-12-12 23:44:52 +00:00
|
|
|
|
|
|
|
|
|
if (!id.HasValue)
|
|
|
|
|
{
|
|
|
|
|
UnsetLogSetting(guild.Id, logChannelType);
|
|
|
|
|
return null;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
2016-12-31 16:34:21 +00:00
|
|
|
|
var channel = await guild.GetTextChannelAsync(id.Value).ConfigureAwait(false);
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
|
|
|
|
if (channel == null)
|
2016-12-12 23:44:52 +00:00
|
|
|
|
{
|
|
|
|
|
UnsetLogSetting(guild.Id, logChannelType);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-09-05 10:27:58 +00:00
|
|
|
|
else
|
|
|
|
|
return channel;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 23:44:52 +00:00
|
|
|
|
private static void UnsetLogSetting(ulong guildId, LogType logChannelType)
|
|
|
|
|
{
|
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
2016-12-24 05:21:51 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-24 05:21:51 +00:00
|
|
|
|
public enum EnableDisable
|
|
|
|
|
{
|
2016-12-12 23:44:52 +00:00
|
|
|
|
Enable,
|
|
|
|
|
Disable
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-05 10:27:58 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 12:21:18 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.Administrator)]
|
2016-09-30 02:20:09 +00:00
|
|
|
|
[OwnerOnly]
|
2017-01-01 11:54:02 +00:00
|
|
|
|
public async Task LogServer(PermissionAction action)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2017-01-01 11:54:44 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-09-06 01:59:00 +00:00
|
|
|
|
LogSetting logSetting;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
2016-12-24 05:21:51 +00:00
|
|
|
|
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);
|
2016-12-24 10:15:22 +00:00
|
|
|
|
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
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);
|
2016-09-05 10:27:58 +00:00
|
|
|
|
else
|
2017-02-14 18:06:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("log_disabled").ConfigureAwait(false);
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-05 10:27:58 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 12:21:18 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.Administrator)]
|
2016-09-30 02:20:09 +00:00
|
|
|
|
[OwnerOnly]
|
2017-01-01 11:54:02 +00:00
|
|
|
|
public async Task LogIgnore()
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2017-01-01 11:54:44 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
int removed;
|
|
|
|
|
using (var uow = DbHandler.UnitOfWork())
|
|
|
|
|
{
|
2016-12-24 05:21:51 +00:00
|
|
|
|
var config = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id);
|
2016-09-05 10:27:58 +00:00
|
|
|
|
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);
|
2016-09-05 10:27:58 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2016-09-05 10:27:58 +00:00
|
|
|
|
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);
|
2016-09-05 10:27:58 +00:00
|
|
|
|
else
|
2017-02-14 18:06:02 +00:00
|
|
|
|
await ReplyConfirmLocalized("log_not_ignore", Format.Bold(channel.Mention + "(" + channel.Id + ")")).ConfigureAwait(false);
|
2016-09-05 10:27:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-06 01:59:00 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 12:21:18 +00:00
|
|
|
|
[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
|
|
|
|
}
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-06 21:34:00 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 12:21:18 +00:00
|
|
|
|
[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())
|
|
|
|
|
{
|
2016-12-24 05:21:51 +00:00
|
|
|
|
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;
|
2016-12-24 05:21:51 +00:00
|
|
|
|
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-12-24 05:21:51 +00:00
|
|
|
|
|
2016-09-06 21:34:00 +00:00
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
2016-09-05 10:27:58 +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)
|
2017-02-20 22:46:34 +00:00
|
|
|
|
=> NadekoTopLevelModule.GetTextStatic(key,
|
2017-02-14 18:06:02 +00:00
|
|
|
|
NadekoBot.Localization.GetCultureInfo(guild),
|
|
|
|
|
typeof(Administration).Name.ToLowerInvariant(),
|
|
|
|
|
replacements);
|
|
|
|
|
}
|
2016-12-24 05:21:51 +00:00
|
|
|
|
}
|