2016-09-05 12:27:58 +02:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using NadekoBot.Extensions;
|
2017-10-13 06:14:54 +02:00
|
|
|
|
using NadekoBot.Core.Services;
|
|
|
|
|
using NadekoBot.Core.Services.Database.Models;
|
2016-09-05 12:27:58 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 21:42:36 +02:00
|
|
|
|
using NadekoBot.Common;
|
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Common.TypeReaders.Models;
|
|
|
|
|
using NadekoBot.Modules.Administration.Services;
|
|
|
|
|
using static NadekoBot.Modules.Administration.Services.LogCommandService;
|
2016-09-05 12:27:58 +02:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Administration
|
|
|
|
|
{
|
|
|
|
|
public partial class Administration
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-06-16 17:47:02 +02:00
|
|
|
|
[NoPublicBot]
|
2017-07-15 18:34:34 +02:00
|
|
|
|
public class LogCommands : NadekoSubmodule<LogCommandService>
|
2016-09-05 12:27:58 +02:00
|
|
|
|
{
|
2017-06-01 05:12:00 +02:00
|
|
|
|
private readonly DbService _db;
|
2016-09-05 12:27:58 +02:00
|
|
|
|
|
2017-07-15 18:34:34 +02:00
|
|
|
|
public LogCommands(DbService db)
|
2016-12-28 06:31:39 +01:00
|
|
|
|
{
|
2017-06-01 05:12:00 +02:00
|
|
|
|
_db = db;
|
2016-12-13 00:44:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-24 06:21:51 +01:00
|
|
|
|
public enum EnableDisable
|
|
|
|
|
{
|
2016-12-13 00:44:52 +01:00
|
|
|
|
Enable,
|
|
|
|
|
Disable
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 05:09:44 +02:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-05 12:27:58 +02:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 13:21:18 +01:00
|
|
|
|
[RequireUserPermission(GuildPermission.Administrator)]
|
2016-09-30 04:20:09 +02:00
|
|
|
|
[OwnerOnly]
|
2017-01-01 12:54:02 +01:00
|
|
|
|
public async Task LogServer(PermissionAction action)
|
2016-09-05 12:27:58 +02:00
|
|
|
|
{
|
2017-01-01 12:54:44 +01:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-09-06 03:59:00 +02:00
|
|
|
|
LogSetting logSetting;
|
2017-05-27 19:42:23 +02:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-09-05 12:27:58 +02:00
|
|
|
|
{
|
2016-12-24 06:21:51 +01:00
|
|
|
|
logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting;
|
2017-07-15 18:34:34 +02:00
|
|
|
|
_service.GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting);
|
2016-12-13 00:44:52 +01: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-09 00:33:42 +01:00
|
|
|
|
logSetting.UserMutedId =
|
2016-12-13 00:44:52 +01:00
|
|
|
|
logSetting.LogVoicePresenceTTSId = (action.Value ? channel.Id : (ulong?)null);
|
2016-12-24 11:15:22 +01:00
|
|
|
|
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
2016-09-05 12:27:58 +02:00
|
|
|
|
}
|
2016-12-13 00:44:52 +01:00
|
|
|
|
if (action.Value)
|
2017-02-14 19:06:02 +01:00
|
|
|
|
await ReplyConfirmLocalized("log_all").ConfigureAwait(false);
|
2016-09-05 12:27:58 +02:00
|
|
|
|
else
|
2017-02-14 19:06:02 +01:00
|
|
|
|
await ReplyConfirmLocalized("log_disabled").ConfigureAwait(false);
|
2016-09-05 12:27:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 05:09:44 +02:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-05 12:27:58 +02:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 13:21:18 +01:00
|
|
|
|
[RequireUserPermission(GuildPermission.Administrator)]
|
2016-09-30 04:20:09 +02:00
|
|
|
|
[OwnerOnly]
|
2017-01-01 12:54:02 +01:00
|
|
|
|
public async Task LogIgnore()
|
2016-09-05 12:27:58 +02:00
|
|
|
|
{
|
2017-01-01 12:54:44 +01:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-09-05 12:27:58 +02:00
|
|
|
|
int removed;
|
2017-05-27 19:42:23 +02:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-09-05 12:27:58 +02:00
|
|
|
|
{
|
2016-12-24 06:21:51 +01:00
|
|
|
|
var config = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id);
|
2017-07-15 18:34:34 +02:00
|
|
|
|
LogSetting logSetting = _service.GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
2016-09-05 12:27:58 +02:00
|
|
|
|
removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
|
2016-10-18 03:26:41 +02:00
|
|
|
|
config.LogSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
|
2016-09-05 12:27:58 +02:00
|
|
|
|
if (removed == 0)
|
2016-10-18 03:26:41 +02:00
|
|
|
|
{
|
|
|
|
|
var toAdd = new IgnoredLogChannel { ChannelId = channel.Id };
|
|
|
|
|
logSetting.IgnoredChannels.Add(toAdd);
|
|
|
|
|
config.LogSetting.IgnoredChannels.Add(toAdd);
|
|
|
|
|
}
|
2016-09-05 12:27:58 +02:00
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (removed == 0)
|
2017-02-14 19:06:02 +01:00
|
|
|
|
await ReplyConfirmLocalized("log_ignore", Format.Bold(channel.Mention + "(" + channel.Id + ")")).ConfigureAwait(false);
|
2016-09-05 12:27:58 +02:00
|
|
|
|
else
|
2017-02-14 19:06:02 +01:00
|
|
|
|
await ReplyConfirmLocalized("log_not_ignore", Format.Bold(channel.Mention + "(" + channel.Id + ")")).ConfigureAwait(false);
|
2016-09-05 12:27:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 05:09:44 +02:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-06 03:59:00 +02:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 13:21:18 +01:00
|
|
|
|
[RequireUserPermission(GuildPermission.Administrator)]
|
2016-12-24 14:13:48 +01:00
|
|
|
|
[OwnerOnly]
|
2017-01-01 12:54:02 +01:00
|
|
|
|
public async Task LogEvents()
|
2016-09-06 03:59:00 +02:00
|
|
|
|
{
|
2017-07-13 17:45:46 +05:30
|
|
|
|
await Context.Channel.SendConfirmAsync(Format.Bold(GetText("log_events")) + "\n" +
|
|
|
|
|
$"```fix\n{string.Join(", ", Enum.GetNames(typeof(LogType)).Cast<string>())}```")
|
2017-02-17 23:57:28 +01:00
|
|
|
|
.ConfigureAwait(false);
|
2016-09-06 03:59:00 +02:00
|
|
|
|
}
|
2016-09-05 12:27:58 +02:00
|
|
|
|
|
2016-10-05 05:09:44 +02:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-06 23:34:00 +02:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-31 13:21:18 +01:00
|
|
|
|
[RequireUserPermission(GuildPermission.Administrator)]
|
2016-12-24 14:13:48 +01:00
|
|
|
|
[OwnerOnly]
|
2017-01-01 12:54:02 +01:00
|
|
|
|
public async Task Log(LogType type)
|
2016-09-06 23:34:00 +02:00
|
|
|
|
{
|
2017-01-01 12:54:44 +01:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-12-13 00:44:52 +01:00
|
|
|
|
ulong? channelId = null;
|
2017-05-27 19:42:23 +02:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-09-06 23:34:00 +02:00
|
|
|
|
{
|
2016-12-24 06:21:51 +01:00
|
|
|
|
var logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting;
|
2017-07-15 18:34:34 +02:00
|
|
|
|
_service.GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case LogType.Other:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.LogOtherId = (logSetting.LogOtherId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.MessageUpdated:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.MessageUpdatedId = (logSetting.MessageUpdatedId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.MessageDeleted:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.MessageDeletedId = (logSetting.MessageDeletedId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserJoined:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.UserJoinedId = (logSetting.UserJoinedId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserLeft:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.UserLeftId = (logSetting.UserLeftId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserBanned:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.UserBannedId = (logSetting.UserBannedId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserUnbanned:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.UserUnbannedId = (logSetting.UserUnbannedId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserUpdated:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.UserUpdatedId = (logSetting.UserUpdatedId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
2016-12-24 06:21:51 +01:00
|
|
|
|
case LogType.UserMuted:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.UserMutedId = (logSetting.UserMutedId == null ? (ulong?)channel.Id : default);
|
2016-12-24 06:21:51 +01:00
|
|
|
|
break;
|
2016-12-13 00:44:52 +01:00
|
|
|
|
case LogType.ChannelCreated:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.ChannelCreatedId = (logSetting.ChannelCreatedId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.ChannelDestroyed:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.ChannelDestroyedId = (logSetting.ChannelDestroyedId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.ChannelUpdated:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.ChannelUpdatedId = (logSetting.ChannelUpdatedId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserPresence:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.LogUserPresenceId = (logSetting.LogUserPresenceId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.VoicePresence:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.LogVoicePresenceId = (logSetting.LogVoicePresenceId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
case LogType.VoicePresenceTTS:
|
2017-10-17 07:03:56 +02:00
|
|
|
|
channelId = logSetting.LogVoicePresenceTTSId = (logSetting.LogVoicePresenceTTSId == null ? (ulong?)channel.Id : default);
|
2016-12-13 00:44:52 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2016-12-24 06:21:51 +01:00
|
|
|
|
|
2016-09-06 23:34:00 +02:00
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
2016-09-05 12:27:58 +02:00
|
|
|
|
|
2016-12-13 00:44:52 +01:00
|
|
|
|
if (channelId != null)
|
2017-02-14 19:06:02 +01:00
|
|
|
|
await ReplyConfirmLocalized("log", Format.Bold(type.ToString())).ConfigureAwait(false);
|
2016-09-06 23:34:00 +02:00
|
|
|
|
else
|
2017-02-14 19:06:02 +01:00
|
|
|
|
await ReplyConfirmLocalized("log_stop", Format.Bold(type.ToString())).ConfigureAwait(false);
|
2016-09-06 23:34:00 +02:00
|
|
|
|
}
|
2016-09-05 12:27:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-24 06:21:51 +01:00
|
|
|
|
}
|