Work on logserver. Migrations update. Updated discord.net
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
public partial class Administration {
|
||||
[Group]
|
||||
public class LogCommands
|
||||
{
|
||||
private DiscordSocketClient _client;
|
||||
|
||||
private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
|
||||
|
||||
public LogCommands(DiscordSocketClient client)
|
||||
{
|
||||
_client = client;
|
||||
_client.MessageReceived += _client_MessageReceived;
|
||||
}
|
||||
|
||||
private Task _client_MessageReceived(IMessage imsg)
|
||||
{
|
||||
var msg = imsg as IUserMessage;
|
||||
if (msg == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task LogServer(IUserMessage msg)
|
||||
{
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
466
src/NadekoBot/Modules/Administration/Commands/LogCommand-1.cs
Normal file
466
src/NadekoBot/Modules/Administration/Commands/LogCommand-1.cs
Normal file
@@ -0,0 +1,466 @@
|
||||
//using Discord;
|
||||
//using Discord.Commands;
|
||||
//using Discord.WebSocket;
|
||||
//using NadekoBot.Attributes;
|
||||
//using NadekoBot.Extensions;
|
||||
//using NadekoBot.Services;
|
||||
//using NadekoBot.Services.Database;
|
||||
//using NadekoBot.Services.Database.Models;
|
||||
//using NLog;
|
||||
//using System;
|
||||
//using System.Collections.Concurrent;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Reflection;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
//namespace NadekoBot.Modules.Administration
|
||||
//{
|
||||
// public partial class Administration
|
||||
// {
|
||||
// [Group]
|
||||
// public class LogCommands
|
||||
// {
|
||||
// private DiscordSocketClient _client { get; }
|
||||
// private Logger _log { get; }
|
||||
|
||||
// private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
|
||||
|
||||
// public ConcurrentDictionary<ulong, LogSetting> GuildLogSettings { get; }
|
||||
|
||||
// public LogCommands(DiscordSocketClient client)
|
||||
// {
|
||||
// _client = client;
|
||||
// _log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// GuildLogSettings = new ConcurrentDictionary<ulong, LogSetting>(uow.GuildConfigs
|
||||
// .GetAll()
|
||||
// .ToDictionary(g => g.GuildId, g => g.LogSetting));
|
||||
// }
|
||||
|
||||
// _client.MessageReceived += _client_MessageReceived;
|
||||
// _client.MessageUpdated += _client_MessageUpdated;
|
||||
// _client.MessageDeleted += _client_MessageDeleted;
|
||||
// _client.UserBanned += _client_UserBanned;
|
||||
// _client.UserUnbanned += _client_UserUnbanned;
|
||||
// _client.UserJoined += _client_UserJoined;
|
||||
// _client.UserLeft += _client_UserLeft;
|
||||
// _client.UserPresenceUpdated += _client_UserPresenceUpdated;
|
||||
// _client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
|
||||
// }
|
||||
|
||||
// private Task _client_UserVoiceStateUpdated(IUser iusr, IVoiceState before, IVoiceState after)
|
||||
// {
|
||||
// var usr = iusr as IGuildUser;
|
||||
// if (usr == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var beforeVch = before.VoiceChannel;
|
||||
// var afterVch = after.VoiceChannel;
|
||||
|
||||
// if (beforeVch == afterVch)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
// || !logSetting.LogVoicePresence
|
||||
// || !logSetting.IgnoredChannels.Any(ic => ic.ChannelId == after.VoiceChannel.Id))
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// ITextChannel logChannel;
|
||||
// if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var task = Task.Run(async () =>
|
||||
// {
|
||||
// if (beforeVch?.Guild == afterVch?.Guild)
|
||||
// {
|
||||
// await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel.").ConfigureAwait(false);
|
||||
// }
|
||||
// else if (beforeVch == null)
|
||||
// {
|
||||
// await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has joined **{afterVch.Name}** voice channel.").ConfigureAwait(false);
|
||||
// }
|
||||
// else if (afterVch == null)
|
||||
// {
|
||||
// await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has left **{beforeVch.Name}** voice channel.").ConfigureAwait(false);
|
||||
// }
|
||||
// });
|
||||
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// private Task _client_UserPresenceUpdated(IGuildUser usr, IPresence before, IPresence after)
|
||||
// {
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
// || !logSetting.LogUserPresence
|
||||
// || before.Status == after.Status)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// ITextChannel logChannel;
|
||||
// if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// private Task _client_UserLeft(IGuildUser usr)
|
||||
// {
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
// || !logSetting.IsLogging
|
||||
// || !logSetting.UserLeft)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var task = Task.Run(async () =>
|
||||
// {
|
||||
|
||||
// });
|
||||
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// private Task _client_UserJoined(IGuildUser usr)
|
||||
// {
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
// || !logSetting.IsLogging
|
||||
// || !logSetting.UserJoined)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var task = Task.Run(async () =>
|
||||
// {
|
||||
|
||||
// });
|
||||
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// private Task _client_UserUnbanned(IUser usr, IGuild guild)
|
||||
// {
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|
||||
// || !logSetting.IsLogging
|
||||
// || !logSetting.UserUnbanned)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var task = Task.Run(async () =>
|
||||
// {
|
||||
|
||||
// });
|
||||
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// private Task _client_UserBanned(IUser usr, IGuild guild)
|
||||
// {
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|
||||
// || !logSetting.IsLogging
|
||||
// || !logSetting.UserBanned)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var task = Task.Run(async () =>
|
||||
// {
|
||||
|
||||
// });
|
||||
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// private Task _client_MessageDeleted(ulong arg1, Optional<IMessage> imsg)
|
||||
// {
|
||||
// var msg = (imsg.IsSpecified ? imsg.Value : null) as IUserMessage;
|
||||
// if (msg == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var channel = msg.Channel as ITextChannel;
|
||||
// if (channel == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
// || !logSetting.IsLogging
|
||||
// || !logSetting.MessageDeleted)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var task = Task.Run(async () =>
|
||||
// {
|
||||
|
||||
// });
|
||||
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// private Task _client_MessageUpdated(Optional<IMessage> optmsg, IMessage imsg2)
|
||||
// {
|
||||
// var after = imsg2 as IUserMessage;
|
||||
// if (after == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var channel = after.Channel as ITextChannel;
|
||||
// if (channel == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
// || !logSetting.IsLogging
|
||||
// || !logSetting.MessageUpdated)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var task = Task.Run(async () =>
|
||||
// {
|
||||
|
||||
// });
|
||||
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// private Task _client_MessageReceived(IMessage imsg)
|
||||
// {
|
||||
// var msg = imsg as IUserMessage;
|
||||
// if (msg == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var channel = msg.Channel as ITextChannel;
|
||||
// if (channel == null)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// LogSetting logSetting;
|
||||
// if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
// || !logSetting.IsLogging
|
||||
// || !logSetting.MessageReceived)
|
||||
// return Task.CompletedTask;
|
||||
|
||||
// var task = Task.Run(() =>
|
||||
// {
|
||||
|
||||
// });
|
||||
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// private enum LogChannelType { Text, Voice, UserPresence };
|
||||
// private ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogChannelType logChannelType = LogChannelType.Text)
|
||||
// {
|
||||
// ulong id = 0;
|
||||
// switch (logChannelType)
|
||||
// {
|
||||
// case LogChannelType.Text:
|
||||
// id = logSetting.ChannelId;
|
||||
// break;
|
||||
// case LogChannelType.Voice:
|
||||
// id = logSetting.VoicePresenceChannelId;
|
||||
// break;
|
||||
// case LogChannelType.UserPresence:
|
||||
// id = logSetting.UserPresenceChannelId;
|
||||
// break;
|
||||
// }
|
||||
// var channel = guild.GetTextChannel(id);
|
||||
|
||||
// if (channel == null)
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// switch (logChannelType)
|
||||
// {
|
||||
// case LogChannelType.Text:
|
||||
// logSetting.IsLogging = false;
|
||||
// break;
|
||||
// case LogChannelType.Voice:
|
||||
// logSetting.LogVoicePresence = false;
|
||||
// break;
|
||||
// case LogChannelType.UserPresence:
|
||||
// logSetting.LogUserPresence = false;
|
||||
// break;
|
||||
// }
|
||||
// uow.Complete();
|
||||
// return null;
|
||||
// }
|
||||
// else
|
||||
// return channel;
|
||||
// }
|
||||
|
||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
// [RequireContext(ContextType.Guild)]
|
||||
// public async Task LogServer(IUserMessage msg)
|
||||
// {
|
||||
// var channel = (ITextChannel)msg.Channel;
|
||||
// GuildConfig config;
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// logSetting.IsLogging = !logSetting.IsLogging;
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync();
|
||||
// }
|
||||
|
||||
// if (config.LogSetting.IsLogging)
|
||||
// await channel.SendMessageAsync("`Logging enabled.`").ConfigureAwait(false);
|
||||
// else
|
||||
// await channel.SendMessageAsync("`Logging disabled.`").ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
// [RequireContext(ContextType.Guild)]
|
||||
// public async Task LogIgnore(IUserMessage imsg)
|
||||
// {
|
||||
// var channel = (ITextChannel)imsg.Channel;
|
||||
// int removed;
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
|
||||
// if (removed == 0)
|
||||
// logSetting.IgnoredChannels.Add(new IgnoredLogChannel { ChannelId = channel.Id });
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// if (removed == 0)
|
||||
// await channel.SendMessageAsync($"`Logging will now ignore {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
|
||||
// else
|
||||
// await channel.SendMessageAsync($"`Logging will no longer ignore {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
// [RequireContext(ContextType.Guild)]
|
||||
// public async Task LogAdd(IUserMessage msg, string eventName)
|
||||
// {
|
||||
// var channel = (ITextChannel)msg.Channel;
|
||||
// eventName = eventName.ToLowerInvariant();
|
||||
|
||||
// switch (eventName)
|
||||
// {
|
||||
// case "messagereceived":
|
||||
// case "messageupdated":
|
||||
// case "messagedeleted":
|
||||
// case "userjoined":
|
||||
// case "userleft":
|
||||
// case "userbanned":
|
||||
// case "userunbanned":
|
||||
// case "channelcreated":
|
||||
// case "channeldestroyed":
|
||||
// case "channelupdated":
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// logSetting.GetType().GetProperty(eventName).SetValue(logSetting, true);
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
// await channel.SendMessageAsync($"`Now logging {eventName} event.`").ConfigureAwait(false);
|
||||
// break;
|
||||
// default:
|
||||
// await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
// [RequireContext(ContextType.Guild)]
|
||||
// public async Task LogRemove(IUserMessage msg, string eventName)
|
||||
// {
|
||||
// var channel = (ITextChannel)msg.Channel;
|
||||
// eventName = eventName.ToLowerInvariant();
|
||||
|
||||
// switch (eventName)
|
||||
// {
|
||||
// case "messagereceived":
|
||||
// case "messageupdated":
|
||||
// case "messagedeleted":
|
||||
// case "userjoined":
|
||||
// case "userleft":
|
||||
// case "userbanned":
|
||||
// case "userunbanned":
|
||||
// case "channelcreated":
|
||||
// case "channeldestroyed":
|
||||
// case "channelupdated":
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// logSetting.GetType().GetProperty(eventName).SetValue(logSetting, false);
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
// await channel.SendMessageAsync($"`No longer logging {eventName} event.`").ConfigureAwait(false);
|
||||
// break;
|
||||
// default:
|
||||
// await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
// [RequireContext(ContextType.Guild)]
|
||||
// public async Task UserPresence(IUserMessage imsg)
|
||||
// {
|
||||
// var channel = (ITextChannel)imsg.Channel;
|
||||
// bool enabled;
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// enabled = logSetting.LogUserPresence = !config.LogSetting.LogUserPresence;
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// if (enabled)
|
||||
// await channel.SendMessageAsync($"`Logging user presence updates in {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
|
||||
// else
|
||||
// await channel.SendMessageAsync($"`Stopped logging user presence updates.`").ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
// [RequireContext(ContextType.Guild)]
|
||||
// public async Task VoicePresence(IUserMessage imsg)
|
||||
// {
|
||||
// var channel = (ITextChannel)imsg.Channel;
|
||||
// bool enabled;
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// enabled = config.LogSetting.LogVoicePresence = !config.LogSetting.LogVoicePresence;
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// if (enabled)
|
||||
// await channel.SendMessageAsync($"`Logging voice presence updates in {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
|
||||
// else
|
||||
// await channel.SendMessageAsync($"`Stopped logging voice presence updates.`").ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
// [RequireContext(ContextType.Guild)]
|
||||
// public async Task VoiPresIgnore(IUserMessage imsg, IVoiceChannel voiceChannel)
|
||||
// {
|
||||
// var channel = (ITextChannel)imsg.Channel;
|
||||
// int removed;
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// removed = logSetting.IgnoredVoicePresenceChannelIds.RemoveWhere(ivpc => ivpc.ChannelId == voiceChannel.Id);
|
||||
// if (removed == 0)
|
||||
// logSetting.IgnoredVoicePresenceChannelIds.Add(new IgnoredVoicePresenceChannel { ChannelId = voiceChannel.Id });
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// if (removed == 0)
|
||||
// await channel.SendMessageAsync($"`Enabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false);
|
||||
// else
|
||||
// await channel.SendMessageAsync($"`Disabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
@@ -1,485 +1,466 @@
|
||||
//using Discord;
|
||||
//using Discord.Commands;
|
||||
//using NadekoBot.Classes;
|
||||
//using NadekoBot.Extensions;
|
||||
//using NadekoBot.Modules.Permissions.Classes;
|
||||
//using System;
|
||||
//using System.Collections.Concurrent;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
////todo DB
|
||||
////todo Add flags for every event
|
||||
//namespace NadekoBot.Modules.Administration
|
||||
//{
|
||||
// public class LogCommand : DiscordCommand
|
||||
// {
|
||||
// private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class LogCommands
|
||||
{
|
||||
private DiscordSocketClient _client { get; }
|
||||
private Logger _log { get; }
|
||||
|
||||
// private ConcurrentBag<KeyValuePair<Channel, string>> voicePresenceUpdates = new ConcurrentBag<KeyValuePair<Channel, string>>();
|
||||
private string prettyCurrentTime => $"【{DateTime.Now:HH:mm:ss}】";
|
||||
|
||||
// public LogCommand(DiscordModule module) : base(module)
|
||||
// {
|
||||
// NadekoBot.Client.MessageReceived += MsgRecivd;
|
||||
// NadekoBot.Client.MessageDeleted += MsgDltd;
|
||||
// NadekoBot.Client.MessageUpdated += MsgUpdtd;
|
||||
// NadekoBot.Client.UserUpdated += UsrUpdtd;
|
||||
// NadekoBot.Client.UserBanned += UsrBanned;
|
||||
// NadekoBot.Client.UserLeft += UsrLeft;
|
||||
// NadekoBot.Client.UserJoined += UsrJoined;
|
||||
// NadekoBot.Client.UserUnbanned += UsrUnbanned;
|
||||
// NadekoBot.Client.ChannelCreated += ChannelCreated;
|
||||
// NadekoBot.Client.ChannelDestroyed += ChannelDestroyed;
|
||||
// NadekoBot.Client.ChannelUpdated += ChannelUpdated;
|
||||
public ConcurrentDictionary<ulong, LogSetting> GuildLogSettings { get; }
|
||||
|
||||
public LogCommands(DiscordSocketClient client)
|
||||
{
|
||||
_client = client;
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
// NadekoBot.Client.MessageReceived += async (s, e) =>
|
||||
// {
|
||||
// if (e.Channel.IsPrivate || umsg.Author.Id == NadekoBot.Client.CurrentUser.Id)
|
||||
// return;
|
||||
// if (!SpecificConfigurations.Default.Of(e.Server.Id).SendPrivateMessageOnMention) return;
|
||||
// try
|
||||
// {
|
||||
// var usr = e.Message.MentionedUsers.FirstOrDefault(u => u != umsg.Author);
|
||||
// if (usr?.Status != UserStatus.Offline)
|
||||
// return;
|
||||
// await channel.SendMessageAsync($"User `{usr.Name}` is offline. PM sent.").ConfigureAwait(false);
|
||||
// await usr.SendMessageAsync(
|
||||
// $"User `{umsg.Author.Username}` mentioned you on " +
|
||||
// $"`{e.Server.Name}` server while you were offline.\n" +
|
||||
// $"`Message:` {e.Message.Text}").ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// };
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
GuildLogSettings = new ConcurrentDictionary<ulong, LogSetting>(uow.GuildConfigs
|
||||
.GetAll()
|
||||
.ToDictionary(g => g.GuildId, g => g.LogSetting));
|
||||
}
|
||||
|
||||
// // start the userpresence queue
|
||||
_client.MessageReceived += _client_MessageReceived;
|
||||
_client.MessageUpdated += _client_MessageUpdated;
|
||||
_client.MessageDeleted += _client_MessageDeleted;
|
||||
_client.UserBanned += _client_UserBanned;
|
||||
_client.UserUnbanned += _client_UserUnbanned;
|
||||
_client.UserJoined += _client_UserJoined;
|
||||
_client.UserLeft += _client_UserLeft;
|
||||
_client.UserPresenceUpdated += _client_UserPresenceUpdated;
|
||||
_client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
|
||||
}
|
||||
|
||||
// NadekoBot.OnReady += () => Task.Run(async () =>
|
||||
// {
|
||||
// while (true)
|
||||
// {
|
||||
// var toSend = new Dictionary<Channel, string>();
|
||||
// //take everything from the queue and merge the messages which are going to the same channel
|
||||
// KeyValuePair<Channel, string> item;
|
||||
// while (voicePresenceUpdates.TryTake(out item))
|
||||
// {
|
||||
// if (toSend.ContainsKey(item.Key))
|
||||
// {
|
||||
// toSend[item.Key] = toSend[item.Key] + Environment.NewLine + item.Value;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// toSend.Add(item.Key, item.Value);
|
||||
// }
|
||||
// }
|
||||
// //send merged messages to each channel
|
||||
// foreach (var k in toSend)
|
||||
// {
|
||||
// try { await k.Key.SendMessageAsync(Environment.NewLine + k.Value).ConfigureAwait(false); } catch { }
|
||||
// }
|
||||
private Task _client_UserVoiceStateUpdated(IUser iusr, IVoiceState before, IVoiceState after)
|
||||
{
|
||||
var usr = iusr as IGuildUser;
|
||||
if (usr == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// await Task.Delay(5000);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
var beforeVch = before.VoiceChannel;
|
||||
var afterVch = after.VoiceChannel;
|
||||
|
||||
// private async void ChannelUpdated(object sender, ChannelUpdatedEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// var chId = config.LogServerChannel;
|
||||
// if (chId == null || config.LogserverIgnoreChannels.Contains(e.After.Id))
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// if (e.Before.Name != e.After.Name)
|
||||
// await ch.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{e.Before.Name}` (*{e.After.Id}*)
|
||||
// `New:` {e.After.Name}").ConfigureAwait(false);
|
||||
// else if (e.Before.Topic != e.After.Topic)
|
||||
// await ch.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{e.After.Name}` (*{e.After.Id}*)
|
||||
// `Old:` {e.Before.Topic}
|
||||
// `New:` {e.After.Topic}").ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
if (beforeVch == afterVch)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// private async void ChannelDestroyed(object sender, ChannelEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// var chId = config.LogServerChannel;
|
||||
// if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// await ch.SendMessageAsync($"❗`{prettyCurrentTime}`❗`Channel Deleted:` #{e.Channel.Name} (*{e.Channel.Id}*)").ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| !logSetting.LogVoicePresence
|
||||
|| !logSetting.IgnoredChannels.Any(ic => ic.ChannelId == after.VoiceChannel.Id))
|
||||
return Task.CompletedTask;
|
||||
|
||||
// private async void ChannelCreated(object sender, ChannelEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// var chId = config.LogServerChannel;
|
||||
// if (chId == null || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// await ch.SendMessageAsync($"`{prettyCurrentTime}`🆕`Channel Created:` #{e.Channel.Mention} (*{e.Channel.Id}*)").ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// private async void UsrUnbanned(object sender, UserEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
|
||||
// if (chId == null)
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// await ch.SendMessageAsync($"`{prettyCurrentTime}`♻`User was unbanned:` **{umsg.Author.Username}** ({umsg.Author.Id})").ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
if (beforeVch?.Guild == afterVch?.Guild)
|
||||
{
|
||||
await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel.").ConfigureAwait(false);
|
||||
}
|
||||
else if (beforeVch == null)
|
||||
{
|
||||
await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has joined **{afterVch.Name}** voice channel.").ConfigureAwait(false);
|
||||
}
|
||||
else if (afterVch == null)
|
||||
{
|
||||
await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has left **{beforeVch.Name}** voice channel.").ConfigureAwait(false);
|
||||
}
|
||||
});
|
||||
|
||||
// private async void UsrJoined(object sender, UserEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
|
||||
// if (chId == null)
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// await ch.SendMessageAsync($"`{prettyCurrentTime}`✅`User joined:` **{umsg.Author.Username}** ({umsg.Author.Id})").ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// private async void UsrLeft(object sender, UserEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
|
||||
// if (chId == null)
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// await ch.SendMessageAsync($"`{prettyCurrentTime}`❗`User left:` **{umsg.Author.Username}** ({umsg.Author.Id})").ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
private Task _client_UserPresenceUpdated(IGuildUser usr, IPresence before, IPresence after)
|
||||
{
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| !logSetting.LogUserPresence
|
||||
|| before.Status == after.Status)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// private async void UsrBanned(object sender, UserEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
|
||||
// if (chId == null)
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// await ch.SendMessageAsync($"❗`{prettyCurrentTime}`❌`User banned:` **{umsg.Author.Username}** ({umsg.Author.Id})").ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
ITextChannel logChannel;
|
||||
if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// private async void MsgRecivd(object sender, MessageEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if (e.Server == null || e.Channel.IsPrivate || umsg.Author.Id == NadekoBot.Client.CurrentUser.Id)
|
||||
// return;
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// var chId = config.LogServerChannel;
|
||||
// if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// if (!string.IsNullOrWhiteSpace(e.Message.Text))
|
||||
// {
|
||||
// await ch.SendMessageAsync(
|
||||
// $@"🕔`{prettyCurrentTime}` **New Message** `#{e.Channel.Name}`
|
||||
//👤`{umsg.Author?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await ch.SendMessageAsync(
|
||||
// $@"🕔`{prettyCurrentTime}` **File Uploaded** `#{e.Channel.Name}`
|
||||
//👤`{umsg.Author?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false);
|
||||
// }
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
// private async void MsgDltd(object sender, MessageEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if (e.Server == null || e.Channel.IsPrivate || umsg.Author?.Id == NadekoBot.Client.CurrentUser.Id)
|
||||
// return;
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// var chId = config.LogServerChannel;
|
||||
// if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// if (!string.IsNullOrWhiteSpace(e.Message.Text))
|
||||
// {
|
||||
// await ch.SendMessageAsync(
|
||||
// $@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{e.Channel.Name}`
|
||||
//👤`{umsg.Author?.ToString() ?? ("NULL")}` {e.Message.Text.Unmention()}").ConfigureAwait(false);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await ch.SendMessageAsync(
|
||||
// $@"🕔`{prettyCurrentTime}` **File Deleted** `#{e.Channel.Name}`
|
||||
//👤`{umsg.Author?.ToString() ?? ("NULL")}` {e.Message.Attachments.FirstOrDefault()?.ProxyUrl}").ConfigureAwait(false);
|
||||
// }
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
// private async void MsgUpdtd(object sender, MessageUpdatedEventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if (e.Server == null || e.Channel.IsPrivate || umsg.Author?.Id == NadekoBot.Client.CurrentUser.Id)
|
||||
// return;
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// var chId = config.LogServerChannel;
|
||||
// if (chId == null || e.Channel.Id == chId || config.LogserverIgnoreChannels.Contains(e.Channel.Id))
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// await ch.SendMessageAsync(
|
||||
// $@"🕔`{prettyCurrentTime}` **Message** 📝 `#{e.Channel.Name}`
|
||||
//👤`{umsg.Author?.ToString() ?? ("NULL")}`
|
||||
// `Old:` {e.Before.Text.Unmention()}
|
||||
// `New:` {e.After.Text.Unmention()}").ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
// private async void UsrUpdtd(object sender, UserUpdatedEventArgs e)
|
||||
// {
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// try
|
||||
// {
|
||||
// var chId = config.LogPresenceChannel;
|
||||
// if (chId != null)
|
||||
// {
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) != null)
|
||||
// {
|
||||
// if (e.Before.Status != e.After.Status)
|
||||
// {
|
||||
// voicePresenceUpdates.Add(new KeyValuePair<Channel, string>(ch, $"`{prettyCurrentTime}`**{e.Before.Name}** is now **{e.After.Status}**."));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch { }
|
||||
private Task _client_UserLeft(IGuildUser usr)
|
||||
{
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| !logSetting.IsLogging
|
||||
|| !logSetting.UserLeft)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// try
|
||||
// {
|
||||
// ulong notifyChBeforeId;
|
||||
// ulong notifyChAfterId;
|
||||
// Channel notifyChBefore = null;
|
||||
// Channel notifyChAfter = null;
|
||||
// var beforeVch = e.Before.VoiceChannel;
|
||||
// var afterVch = e.After.VoiceChannel;
|
||||
// var notifyLeave = false;
|
||||
// var notifyJoin = false;
|
||||
// if ((beforeVch != null || afterVch != null) && (beforeVch != afterVch)) // this means we need to notify for sure.
|
||||
// {
|
||||
// if (beforeVch != null && config.VoiceChannelLog.TryGetValue(beforeVch.Id, out notifyChBeforeId) && (notifyChBefore = e.Before.Server.TextChannels.FirstOrDefault(tc => tc.Id == notifyChBeforeId)) != null)
|
||||
// {
|
||||
// notifyLeave = true;
|
||||
// }
|
||||
// if (afterVch != null && config.VoiceChannelLog.TryGetValue(afterVch.Id, out notifyChAfterId) && (notifyChAfter = e.After.Server.TextChannels.FirstOrDefault(tc => tc.Id == notifyChAfterId)) != null)
|
||||
// {
|
||||
// notifyJoin = true;
|
||||
// }
|
||||
// if ((notifyLeave && notifyJoin) && (notifyChAfter == notifyChBefore))
|
||||
// {
|
||||
// await notifyChAfter.SendMessageAsync($"🎼`{prettyCurrentTime}` {e.Before.Name} moved from **{beforeVch.Mention}** to **{afterVch.Mention}** voice channel.").ConfigureAwait(false);
|
||||
// }
|
||||
// else if (notifyJoin)
|
||||
// {
|
||||
// await notifyChAfter.SendMessageAsync($"🎼`{prettyCurrentTime}` {e.Before.Name} has joined **{afterVch.Mention}** voice channel.").ConfigureAwait(false);
|
||||
// }
|
||||
// else if (notifyLeave)
|
||||
// {
|
||||
// await notifyChBefore.SendMessageAsync($"🎼`{prettyCurrentTime}` {e.Before.Name} has left **{beforeVch.Mention}** voice channel.").ConfigureAwait(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch { }
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
|
||||
// try
|
||||
// {
|
||||
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
|
||||
// if (chId == null)
|
||||
// return;
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
// string str = $"🕔`{prettyCurrentTime}`";
|
||||
// if (e.Before.Name != e.After.Name)
|
||||
// str += $"**Name Changed**👤`{e.Before?.ToString()}`\n\t\t`New:`{e.After.ToString()}`";
|
||||
// else if (e.Before.Nickname != e.After.Nickname)
|
||||
// str += $"**Nickname Changed**👤`{e.Before?.ToString()}`\n\t\t`Old:` {e.Before.Nickname}#{e.Before.Discriminator}\n\t\t`New:` {e.After.Nickname}#{e.After.Discriminator}";
|
||||
// else if (e.Before.AvatarUrl != e.After.AvatarUrl)
|
||||
// str += $"**Avatar Changed**👤`{e.Before?.ToString()}`\n\t {await e.Before.AvatarUrl.ShortenUrl()} `=>` {await e.After.AvatarUrl.ShortenUrl()}";
|
||||
// else if (!e.Before.Roles.SequenceEqual(e.After.Roles))
|
||||
// {
|
||||
// if (e.Before.Roles.Count() < e.After.Roles.Count())
|
||||
// {
|
||||
// var diffRoles = e.After.Roles.Where(r => !e.Before.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
|
||||
// str += $"**User's Roles changed ⚔➕**👤`{e.Before?.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role.";
|
||||
// }
|
||||
// else if (e.Before.Roles.Count() > e.After.Roles.Count())
|
||||
// {
|
||||
// var diffRoles = e.Before.Roles.Where(r => !e.After.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
|
||||
// str += $"**User's Roles changed ⚔➖**👤`{e.Before?.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role.";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine("SEQUENCE NOT EQUAL BUT NO DIFF ROLES - REPORT TO KWOTH on #NADEKOLOG server");
|
||||
// return;
|
||||
// }
|
||||
});
|
||||
|
||||
// }
|
||||
// else
|
||||
// return;
|
||||
// await ch.SendMessageAsync(str).ConfigureAwait(false);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// public override void Init(CommandGroupBuilder cgb)
|
||||
// {
|
||||
private Task _client_UserJoined(IGuildUser usr)
|
||||
{
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|
||||
|| !logSetting.IsLogging
|
||||
|| !logSetting.UserJoined)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// cgb.CreateCommand(Module.Prefix + "spmom")
|
||||
// .Description($"Toggles whether mentions of other offline users on your server will send a pm to them. **Needs Manage Server Permissions.**| `{Prefix}spmom`")
|
||||
// .AddCheck(SimpleCheckers.ManageServer())
|
||||
// .Do(async e =>
|
||||
// {
|
||||
// var specificConfig = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// specificConfig.SendPrivateMessageOnMention =
|
||||
// !specificConfig.SendPrivateMessageOnMention;
|
||||
// if (specificConfig.SendPrivateMessageOnMention)
|
||||
// await channel.SendMessageAsync(":ok: I will send private messages " +
|
||||
// "to mentioned offline users.").ConfigureAwait(false);
|
||||
// else
|
||||
// await channel.SendMessageAsync(":ok: I won't send private messages " +
|
||||
// "to mentioned offline users anymore.").ConfigureAwait(false);
|
||||
// });
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
|
||||
// cgb.CreateCommand(Module.Prefix + "logserver")
|
||||
// .Description($"Toggles logging in this channel. Logs every message sent/deleted/edited on the server. **Bot Owner Only!** | `{Prefix}logserver`")
|
||||
// .AddCheck(SimpleCheckers.OwnerOnly())
|
||||
// .AddCheck(SimpleCheckers.ManageServer())
|
||||
// .Do(async e =>
|
||||
// {
|
||||
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;
|
||||
// if (chId == null)
|
||||
// {
|
||||
// SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel = e.Channel.Id;
|
||||
// await channel.SendMessageAsync($"❗**I WILL BEGIN LOGGING SERVER ACTIVITY IN THIS CHANNEL**❗").ConfigureAwait(false);
|
||||
// return;
|
||||
// }
|
||||
// Channel ch;
|
||||
// if ((ch = e.Server.TextChannels.Where(tc => tc.Id == chId).FirstOrDefault()) == null)
|
||||
// return;
|
||||
});
|
||||
|
||||
// SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel = null;
|
||||
// await channel.SendMessageAsync($"❗**NO LONGER LOGGING IN {ch.Mention} CHANNEL**❗").ConfigureAwait(false);
|
||||
// });
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task _client_UserUnbanned(IUser usr, IGuild guild)
|
||||
{
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|
||||
|| !logSetting.IsLogging
|
||||
|| !logSetting.UserUnbanned)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// cgb.CreateCommand(Prefix + "logignore")
|
||||
// .Description($"Toggles whether the {Prefix}logserver command ignores this channel. Useful if you have hidden admin channel and public log channel. **Bot Owner Only!**| `{Prefix}logignore`")
|
||||
// .AddCheck(SimpleCheckers.OwnerOnly())
|
||||
// .AddCheck(SimpleCheckers.ManageServer())
|
||||
// .Do(async e =>
|
||||
// {
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// if (config.LogserverIgnoreChannels.Remove(e.Channel.Id))
|
||||
// {
|
||||
// await channel.SendMessageAsync($"`{Prefix}logserver will stop ignoring this channel.`");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// config.LogserverIgnoreChannels.Add(e.Channel.Id);
|
||||
// await channel.SendMessageAsync($"`{Prefix}logserver will ignore this channel.`");
|
||||
// }
|
||||
// });
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
|
||||
// cgb.CreateCommand(Module.Prefix + "userpresence")
|
||||
// .Description($"Starts logging to this channel when someone from the server goes online/offline/idle. **Needs Manage Server Permissions.**| `{Prefix}userpresence`")
|
||||
// .AddCheck(SimpleCheckers.ManageServer())
|
||||
// .Do(async e =>
|
||||
// {
|
||||
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel;
|
||||
// if (chId == null)
|
||||
// {
|
||||
// SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel = e.Channel.Id;
|
||||
// await channel.SendMessageAsync($"**User presence notifications enabled.**").ConfigureAwait(false);
|
||||
// return;
|
||||
// }
|
||||
// SpecificConfigurations.Default.Of(e.Server.Id).LogPresenceChannel = null;
|
||||
// await channel.SendMessageAsync($"**User presence notifications disabled.**").ConfigureAwait(false);
|
||||
// });
|
||||
});
|
||||
|
||||
// cgb.CreateCommand(Module.Prefix + "voicepresence")
|
||||
// .Description($"Toggles logging to this channel whenever someone joins or leaves a voice channel you are in right now. **Needs Manage Server Permissions.**| `{Prefix}voicerpresence`")
|
||||
// .Parameter("all", ParameterType.Optional)
|
||||
// .AddCheck(SimpleCheckers.ManageServer())
|
||||
// .Do(async e =>
|
||||
// {
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
// var config = SpecificConfigurations.Default.Of(e.Server.Id);
|
||||
// if (all?.ToLower() == "all")
|
||||
// {
|
||||
// foreach (var voiceChannel in e.Server.VoiceChannels)
|
||||
// {
|
||||
// config.VoiceChannelLog.TryAdd(voiceChannel.Id, e.Channel.Id);
|
||||
// }
|
||||
// await channel.SendMessageAsync("Started logging user presence for **ALL** voice channels!").ConfigureAwait(false);
|
||||
// return;
|
||||
// }
|
||||
private Task _client_UserBanned(IUser usr, IGuild guild)
|
||||
{
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(guild.Id, out logSetting)
|
||||
|| !logSetting.IsLogging
|
||||
|| !logSetting.UserBanned)
|
||||
return Task.CompletedTask;
|
||||
|
||||
// if (umsg.Author.VoiceChannel == null)
|
||||
// {
|
||||
// await channel.SendMessageAsync("💢 You are not in a voice channel right now. If you are, please rejoin it.").ConfigureAwait(false);
|
||||
// return;
|
||||
// }
|
||||
// ulong throwaway;
|
||||
// if (!config.VoiceChannelLog.TryRemove(umsg.Author.VoiceChannel.Id, out throwaway))
|
||||
// {
|
||||
// config.VoiceChannelLog.TryAdd(umsg.Author.VoiceChannel.Id, e.Channel.Id);
|
||||
// await channel.SendMessageAsync($"`Logging user updates for` {umsg.Author.VoiceChannel.Mention} `voice channel.`").ConfigureAwait(false);
|
||||
// }
|
||||
// else
|
||||
// await channel.SendMessageAsync($"`Stopped logging user updates for` {umsg.Author.VoiceChannel.Mention} `voice channel.`").ConfigureAwait(false);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task _client_MessageDeleted(ulong arg1, Optional<IMessage> imsg)
|
||||
{
|
||||
var msg = (imsg.IsSpecified ? imsg.Value : null) as IUserMessage;
|
||||
if (msg == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
|| !logSetting.IsLogging
|
||||
|| !logSetting.MessageDeleted)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task _client_MessageUpdated(Optional<IMessage> optmsg, IMessage imsg2)
|
||||
{
|
||||
var after = imsg2 as IUserMessage;
|
||||
if (after == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var channel = after.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
|| !logSetting.IsLogging
|
||||
|| !logSetting.MessageUpdated)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task _client_MessageReceived(IMessage imsg)
|
||||
{
|
||||
var msg = imsg as IUserMessage;
|
||||
if (msg == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
if (channel == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
LogSetting logSetting;
|
||||
if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out logSetting)
|
||||
|| !logSetting.IsLogging
|
||||
|| !logSetting.MessageReceived)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private enum LogChannelType { Text, Voice, UserPresence };
|
||||
private ITextChannel TryGetLogChannel(IGuild guild, LogSetting logSetting, LogChannelType logChannelType = LogChannelType.Text)
|
||||
{
|
||||
ulong id = 0;
|
||||
switch (logChannelType)
|
||||
{
|
||||
case LogChannelType.Text:
|
||||
id = logSetting.ChannelId;
|
||||
break;
|
||||
case LogChannelType.Voice:
|
||||
id = logSetting.VoicePresenceChannelId;
|
||||
break;
|
||||
case LogChannelType.UserPresence:
|
||||
id = logSetting.UserPresenceChannelId;
|
||||
break;
|
||||
}
|
||||
var channel = guild.GetTextChannel(id);
|
||||
|
||||
if (channel == null)
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
switch (logChannelType)
|
||||
{
|
||||
case LogChannelType.Text:
|
||||
logSetting.IsLogging = false;
|
||||
break;
|
||||
case LogChannelType.Voice:
|
||||
logSetting.LogVoicePresence = false;
|
||||
break;
|
||||
case LogChannelType.UserPresence:
|
||||
logSetting.LogUserPresence = false;
|
||||
break;
|
||||
}
|
||||
uow.Complete();
|
||||
return null;
|
||||
}
|
||||
else
|
||||
return channel;
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task LogServer(IUserMessage msg)
|
||||
{
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
GuildConfig config;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
logSetting.IsLogging = !logSetting.IsLogging;
|
||||
config.LogSetting = logSetting;
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
|
||||
if (config.LogSetting.IsLogging)
|
||||
await channel.SendMessageAsync("`Logging enabled.`").ConfigureAwait(false);
|
||||
else
|
||||
await channel.SendMessageAsync("`Logging disabled.`").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task LogIgnore(IUserMessage imsg)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
int removed;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
removed = logSetting.IgnoredChannels.RemoveWhere(ilc => ilc.ChannelId == channel.Id);
|
||||
if (removed == 0)
|
||||
logSetting.IgnoredChannels.Add(new IgnoredLogChannel { ChannelId = channel.Id });
|
||||
config.LogSetting = logSetting;
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (removed == 0)
|
||||
await channel.SendMessageAsync($"`Logging will now ignore {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
|
||||
else
|
||||
await channel.SendMessageAsync($"`Logging will no longer ignore {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task LogAdd(IUserMessage msg, string eventName)
|
||||
//{
|
||||
// var channel = (ITextChannel)msg.Channel;
|
||||
// eventName = eventName.ToLowerInvariant();
|
||||
|
||||
// switch (eventName)
|
||||
// {
|
||||
// case "messagereceived":
|
||||
// case "messageupdated":
|
||||
// case "messagedeleted":
|
||||
// case "userjoined":
|
||||
// case "userleft":
|
||||
// case "userbanned":
|
||||
// case "userunbanned":
|
||||
// case "channelcreated":
|
||||
// case "channeldestroyed":
|
||||
// case "channelupdated":
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// logSetting.GetType().GetProperty(eventName).SetValue(logSetting, true);
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
// await channel.SendMessageAsync($"`Now logging {eventName} event.`").ConfigureAwait(false);
|
||||
// break;
|
||||
// default:
|
||||
// await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false);
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task LogRemove(IUserMessage msg, string eventName)
|
||||
//{
|
||||
// var channel = (ITextChannel)msg.Channel;
|
||||
// eventName = eventName.ToLowerInvariant();
|
||||
|
||||
// switch (eventName)
|
||||
// {
|
||||
// case "messagereceived":
|
||||
// case "messageupdated":
|
||||
// case "messagedeleted":
|
||||
// case "userjoined":
|
||||
// case "userleft":
|
||||
// case "userbanned":
|
||||
// case "userunbanned":
|
||||
// case "channelcreated":
|
||||
// case "channeldestroyed":
|
||||
// case "channelupdated":
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// logSetting.GetType().GetProperty(eventName).SetValue(logSetting, false);
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
// await channel.SendMessageAsync($"`No longer logging {eventName} event.`").ConfigureAwait(false);
|
||||
// break;
|
||||
// default:
|
||||
// await channel.SendMessageAsync($"`Event \"{eventName}\" not found.`").ConfigureAwait(false);
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task UserPresence(IUserMessage imsg)
|
||||
//{
|
||||
// var channel = (ITextChannel)imsg.Channel;
|
||||
// bool enabled;
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// enabled = logSetting.LogUserPresence = !config.LogSetting.LogUserPresence;
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// if (enabled)
|
||||
// await channel.SendMessageAsync($"`Logging user presence updates in {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
|
||||
// else
|
||||
// await channel.SendMessageAsync($"`Stopped logging user presence updates.`").ConfigureAwait(false);
|
||||
//}
|
||||
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task VoicePresence(IUserMessage imsg)
|
||||
//{
|
||||
// var channel = (ITextChannel)imsg.Channel;
|
||||
// bool enabled;
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// enabled = config.LogSetting.LogVoicePresence = !config.LogSetting.LogVoicePresence;
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// if (enabled)
|
||||
// await channel.SendMessageAsync($"`Logging voice presence updates in {channel.Name} ({channel.Id}) channel.`").ConfigureAwait(false);
|
||||
// else
|
||||
// await channel.SendMessageAsync($"`Stopped logging voice presence updates.`").ConfigureAwait(false);
|
||||
//}
|
||||
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task VoiPresIgnore(IUserMessage imsg, IVoiceChannel voiceChannel)
|
||||
//{
|
||||
// var channel = (ITextChannel)imsg.Channel;
|
||||
// int removed;
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
// LogSetting logSetting = GuildLogSettings.GetOrAdd(channel.Guild.Id, (id) => config.LogSetting);
|
||||
// removed = logSetting.IgnoredVoicePresenceChannelIds.RemoveWhere(ivpc => ivpc.ChannelId == voiceChannel.Id);
|
||||
// if (removed == 0)
|
||||
// logSetting.IgnoredVoicePresenceChannelIds.Add(new IgnoredVoicePresenceChannel { ChannelId = voiceChannel.Id });
|
||||
// config.LogSetting = logSetting;
|
||||
// await uow.CompleteAsync().ConfigureAwait(false);
|
||||
// }
|
||||
|
||||
// if (removed == 0)
|
||||
// await channel.SendMessageAsync($"`Enabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false);
|
||||
// else
|
||||
// await channel.SendMessageAsync($"`Disabled logging voice presence updates for {voiceChannel.Name} ({voiceChannel.Id}) channel.`").ConfigureAwait(false);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user