2016-09-05 10:27:58 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using NadekoBot.Extensions;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services;
|
|
|
|
|
using NadekoBot.Core.Services.Database.Models;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00: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 10:27:58 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Administration
|
|
|
|
|
{
|
|
|
|
|
public partial class Administration
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-06-16 15:47:02 +00:00
|
|
|
|
[NoPublicBot]
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public class LogCommands : NadekoSubmodule<LogCommandService>
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2017-06-01 03:12:00 +00:00
|
|
|
|
private readonly DbService _db;
|
2016-09-05 10:27:58 +00:00
|
|
|
|
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public LogCommands(DbService db)
|
2016-12-28 05:31:39 +00:00
|
|
|
|
{
|
2017-06-01 03:12:00 +00:00
|
|
|
|
_db = db;
|
2016-12-12 23:44:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
2017-05-27 17:42:23 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-24 05:21:51 +00:00
|
|
|
|
logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting;
|
2017-07-15 16:34:34 +00:00
|
|
|
|
_service.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;
|
2017-05-27 17:42:23 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-09-05 10:27:58 +00:00
|
|
|
|
{
|
2016-12-24 05:21:51 +00:00
|
|
|
|
var config = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id);
|
2017-07-15 16:34:34 +00:00
|
|
|
|
LogSetting logSetting = _service.GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
2016-09-05 10:27:58 +00:00
|
|
|
|
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-07-13 12:15:46 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync(Format.Bold(GetText("log_events")) + "\n" +
|
|
|
|
|
$"```fix\n{string.Join(", ", Enum.GetNames(typeof(LogType)).Cast<string>())}```")
|
2017-02-17 22:57:28 +00:00
|
|
|
|
.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;
|
2017-05-27 17:42:23 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2016-09-06 21:34:00 +00:00
|
|
|
|
{
|
2016-12-24 05:21:51 +00:00
|
|
|
|
var logSetting = uow.GuildConfigs.LogSettingsFor(channel.Guild.Id).LogSetting;
|
2017-07-15 16:34:34 +00:00
|
|
|
|
_service.GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case LogType.Other:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.LogOtherId = (logSetting.LogOtherId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.MessageUpdated:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.MessageUpdatedId = (logSetting.MessageUpdatedId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.MessageDeleted:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.MessageDeletedId = (logSetting.MessageDeletedId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserJoined:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.UserJoinedId = (logSetting.UserJoinedId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserLeft:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.UserLeftId = (logSetting.UserLeftId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserBanned:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.UserBannedId = (logSetting.UserBannedId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserUnbanned:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.UserUnbannedId = (logSetting.UserUnbannedId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserUpdated:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.UserUpdatedId = (logSetting.UserUpdatedId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
2016-12-24 05:21:51 +00:00
|
|
|
|
case LogType.UserMuted:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.UserMutedId = (logSetting.UserMutedId == null ? (ulong?)channel.Id : default);
|
2016-12-24 05:21:51 +00:00
|
|
|
|
break;
|
2016-12-12 23:44:52 +00:00
|
|
|
|
case LogType.ChannelCreated:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.ChannelCreatedId = (logSetting.ChannelCreatedId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.ChannelDestroyed:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.ChannelDestroyedId = (logSetting.ChannelDestroyedId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.ChannelUpdated:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.ChannelUpdatedId = (logSetting.ChannelUpdatedId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.UserPresence:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.LogUserPresenceId = (logSetting.LogUserPresenceId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.VoicePresence:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.LogVoicePresenceId = (logSetting.LogVoicePresenceId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
break;
|
|
|
|
|
case LogType.VoicePresenceTTS:
|
2017-10-17 05:03:56 +00:00
|
|
|
|
channelId = logSetting.LogVoicePresenceTTSId = (logSetting.LogVoicePresenceTTSId == null ? (ulong?)channel.Id : default);
|
2016-12-12 23:44:52 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-24 05:21:51 +00:00
|
|
|
|
}
|