Nickname, role changes are logged. Slightly prettier
This commit is contained in:
parent
37d462712c
commit
55fd2c69bc
@ -78,7 +78,10 @@ namespace NadekoBot.Modules.Administration
|
|||||||
_client.UserPresenceUpdated += _client_UserPresenceUpdated;
|
_client.UserPresenceUpdated += _client_UserPresenceUpdated;
|
||||||
_client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
|
_client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
|
||||||
_client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated_TTS;
|
_client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated_TTS;
|
||||||
|
_client.GuildUserUpdated += _client_GuildUserUpdated;
|
||||||
|
#if !GLOBAL_NADEKO
|
||||||
_client.UserUpdated += _client_UserUpdated;
|
_client.UserUpdated += _client_UserUpdated;
|
||||||
|
#endif
|
||||||
|
|
||||||
_client.ChannelCreated += _client_ChannelCreated;
|
_client.ChannelCreated += _client_ChannelCreated;
|
||||||
_client.ChannelDestroyed += _client_ChannelDestroyed;
|
_client.ChannelDestroyed += _client_ChannelDestroyed;
|
||||||
@ -88,6 +91,35 @@ namespace NadekoBot.Modules.Administration
|
|||||||
MuteCommands.UserUnmuted += MuteCommands_UserUnmuted;
|
MuteCommands.UserUnmuted += MuteCommands_UserUnmuted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async void _client_UserUpdated(SocketUser before, SocketUser after)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var str = "";
|
||||||
|
if (before.Username != after.Username)
|
||||||
|
str = $"👤__**{before.Username}#{before.Discriminator}**__ **| Name Changed |** 🆔 `{before.Id}`\n\t\t`New:` **{after.ToString()}**";
|
||||||
|
else if (before.AvatarUrl != after.AvatarUrl)
|
||||||
|
str = $"👤__**{before.Username}#{before.Discriminator}**__ **| Avatar Changed |** 🆔 `{before.Id}`\n\t🖼 {await NadekoBot.Google.ShortenUrl(before.AvatarUrl)} `=>` {await NadekoBot.Google.ShortenUrl(after.AvatarUrl)}";
|
||||||
|
|
||||||
|
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.VoicePresenceTTS)) == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
|
||||||
private static async void _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
|
private static async void _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -228,17 +260,10 @@ namespace NadekoBot.Modules.Administration
|
|||||||
catch (Exception ex) { _log.Warn(ex); }
|
catch (Exception ex) { _log.Warn(ex); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async void _client_UserUpdated(SocketUser uBefore, SocketUser uAfter)
|
private static async void _client_GuildUserUpdated(SocketGuildUser before, SocketGuildUser after)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var before = uBefore as SocketGuildUser;
|
|
||||||
if (before == null)
|
|
||||||
return;
|
|
||||||
var after = uAfter as SocketGuildUser;
|
|
||||||
if (after == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
LogSetting logSetting;
|
LogSetting logSetting;
|
||||||
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting)
|
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting)
|
||||||
|| (logSetting.UserUpdatedId == null))
|
|| (logSetting.UserUpdatedId == null))
|
||||||
@ -247,30 +272,25 @@ namespace NadekoBot.Modules.Administration
|
|||||||
ITextChannel logChannel;
|
ITextChannel logChannel;
|
||||||
if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null)
|
if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.UserUpdated)) == null)
|
||||||
return;
|
return;
|
||||||
string str = $"🕔`{prettyCurrentTime}`";
|
var str = "";
|
||||||
|
if (before.Nickname != after.Nickname)
|
||||||
if (before.Username != after.Username)
|
str = $"👤__**{before.Username}#{before.Discriminator}**__ **| Nickname Changed |** 🆔 `{before.Id}`\n\t\t`Old:` **{before.Nickname}**\n\t\t`New:` **{after.Nickname}**";
|
||||||
str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Name Changed |** 🆔 `{before.Id}`\n\t\t`New:` **{after.ToString()}**";
|
|
||||||
else if (before.Nickname != after.Nickname)
|
|
||||||
str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Nickname Changed |** 🆔 `{before.Id}`\n\t\t`Old:` **{before.Nickname}#{before.Discriminator}**\n\t\t`New:` **{after.Nickname}#{after.Discriminator}**";
|
|
||||||
else if (before.AvatarUrl != after.AvatarUrl)
|
|
||||||
str += $"👤__**{before.Username}#{before.Discriminator}**__ **| Avatar Changed |** 🆔 `{before.Id}`\n\t🖼 {await NadekoBot.Google.ShortenUrl(before.AvatarUrl)} `=>` {await NadekoBot.Google.ShortenUrl(after.AvatarUrl)}";
|
|
||||||
else if (!before.RoleIds.SequenceEqual(after.RoleIds))
|
else if (!before.RoleIds.SequenceEqual(after.RoleIds))
|
||||||
{
|
{
|
||||||
if (before.RoleIds.Count < after.RoleIds.Count)
|
if (before.RoleIds.Count < after.RoleIds.Count)
|
||||||
{
|
{
|
||||||
var diffRoles = after.RoleIds.Where(r => !before.RoleIds.Contains(r)).Select(r => "**" + before.Guild.GetRole(r).Name + "**");
|
var diffRoles = after.RoleIds.Where(r => !before.RoleIds.Contains(r)).Select(r => "**" + before.Guild.GetRole(r).Name + "**");
|
||||||
str += $"👤__**{before.ToString()}**__ **| User's Role Added |** 🆔 `{before.Id}`\n\t✅ {string.Join(", ", diffRoles).SanitizeMentions()}\n\t\t⚔ **`{string.Join(", ", after.GetRoles().Select(r => r.Name)).SanitizeMentions()}`** ⚔";
|
str = $"👤__**{before.ToString()}**__ **| User's Role Added |** 🆔 `{before.Id}`\n\t✅ {string.Join(", ", diffRoles).SanitizeMentions()}\n\t\t⚔ **`{string.Join(", ", after.GetRoles().Select(r => r.Name)).SanitizeMentions()}`** ⚔";
|
||||||
}
|
}
|
||||||
else if (before.RoleIds.Count > after.RoleIds.Count)
|
else if (before.RoleIds.Count > after.RoleIds.Count)
|
||||||
{
|
{
|
||||||
var diffRoles = before.RoleIds.Where(r => !after.RoleIds.Contains(r)).Select(r => "**" + before.Guild.GetRole(r).Name + "**");
|
var diffRoles = before.RoleIds.Where(r => !after.RoleIds.Contains(r)).Select(r => "**" + before.Guild.GetRole(r).Name + "**");
|
||||||
str += $"👤__**{before.ToString()}**__ **| User's Role Removed |** 🆔 `{before.Id}`\n\t🚮 {string.Join(", ", diffRoles).SanitizeMentions()}\n\t\t⚔ **`{string.Join(", ", after.GetRoles().Select(r => r.Name)).SanitizeMentions()}`** ⚔";
|
str = $"👤__**{before.ToString()}**__ **| User's Role Removed |** 🆔 `{before.Id}`\n\t🚮 {string.Join(", ", diffRoles).SanitizeMentions()}\n\t\t⚔ **`{string.Join(", ", after.GetRoles().Select(r => r.Name)).SanitizeMentions()}`** ⚔";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
try { await logChannel.SendMessageAsync("🕔`{prettyCurrentTime}` " + str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||||
}
|
}
|
||||||
catch (Exception ex) { _log.Warn(ex); }
|
catch (Exception ex) { _log.Warn(ex); }
|
||||||
}
|
}
|
||||||
@ -745,9 +765,9 @@ namespace NadekoBot.Modules.Administration
|
|||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
if (action.Value)
|
if (action.Value)
|
||||||
await channel.SendMessageAsync("✅ Logging all events on this channel.").ConfigureAwait(false);
|
await channel.SendConfirmAsync("Logging all events in this channel.").ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
await channel.SendMessageAsync("ℹ️ Logging disabled.").ConfigureAwait(false);
|
await channel.SendConfirmAsync("Logging disabled.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -774,9 +794,9 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (removed == 0)
|
if (removed == 0)
|
||||||
await channel.SendMessageAsync($"🆗 Logging will **now ignore** #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false);
|
await channel.SendConfirmAsync($"Logging will IGNORE **{channel.Mention} ({channel.Id})**").ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
await channel.SendMessageAsync($"ℹ️ Logging will **no longer ignore** #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false);
|
await channel.SendConfirmAsync($"Logging will NOT IGNORE **{channel.Mention} ({channel.Id})**").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -853,9 +873,9 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (channelId != null)
|
if (channelId != null)
|
||||||
await channel.SendMessageAsync($"✅ Logging `{type}` event in #⃣ `{channel.Name} ({channel.Id})`").ConfigureAwait(false);
|
await channel.SendConfirmAsync($"Logging **{type}** event in this channel.").ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
await channel.SendMessageAsync($"ℹ️ Stopped logging `{type}` event.").ConfigureAwait(false);
|
await channel.SendConfirmAsync($"Stopped logging **{type}** event.").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
public async Task Leave([Remainder] string guildStr)
|
public async Task Leave([Remainder] string guildStr)
|
||||||
{
|
{
|
||||||
guildStr = guildStr.Trim().ToUpperInvariant();
|
guildStr = guildStr.Trim().ToUpperInvariant();
|
||||||
var server = NadekoBot.Client.GetGuilds().FirstOrDefault(g => g.Id.ToString().Trim().ToUpperInvariant() == guildStr) ??
|
var server = NadekoBot.Client.GetGuilds().FirstOrDefault(g => g.Id.ToString() == guildStr) ??
|
||||||
NadekoBot.Client.GetGuilds().FirstOrDefault(g => g.Name.Trim().ToUpperInvariant() == guildStr);
|
NadekoBot.Client.GetGuilds().FirstOrDefault(g => g.Name.Trim().ToUpperInvariant() == guildStr);
|
||||||
|
|
||||||
if (server == null)
|
if (server == null)
|
||||||
|
@ -91,7 +91,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[RequireUserPermission(ChannelPermission.ManageMessages)]
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
||||||
public async Task Cleverbot()
|
public async Task Cleverbot()
|
||||||
{
|
{
|
||||||
var channel = (ITextChannel)Context.Channel;
|
var channel = (ITextChannel)Context.Channel;
|
||||||
|
@ -311,7 +311,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
if (page < 0)
|
if (page < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var guilds = NadekoBot.Client.GetGuilds().OrderBy(g => g.Name).Skip((page - 1) * 15).Take(15);
|
var guilds = await Task.Run(() => NadekoBot.Client.GetGuilds().OrderBy(g => g.Name).Skip((page - 1) * 15).Take(15)).ConfigureAwait(false);
|
||||||
|
|
||||||
if (!guilds.Any())
|
if (!guilds.Any())
|
||||||
{
|
{
|
||||||
|
@ -38,6 +38,8 @@ namespace NadekoBot
|
|||||||
private uint _connectedCount = 0;
|
private uint _connectedCount = 0;
|
||||||
private uint _downloadedCount = 0;
|
private uint _downloadedCount = 0;
|
||||||
|
|
||||||
|
private int _guildCount = 0;
|
||||||
|
|
||||||
private IReadOnlyList<DiscordSocketClient> Clients { get; }
|
private IReadOnlyList<DiscordSocketClient> Clients { get; }
|
||||||
|
|
||||||
public ShardedDiscordClient(DiscordSocketConfig discordSocketConfig)
|
public ShardedDiscordClient(DiscordSocketConfig discordSocketConfig)
|
||||||
@ -70,8 +72,8 @@ namespace NadekoBot
|
|||||||
client.ChannelCreated += arg => { ChannelCreated(arg); return Task.CompletedTask; };
|
client.ChannelCreated += arg => { ChannelCreated(arg); return Task.CompletedTask; };
|
||||||
client.ChannelDestroyed += arg => { ChannelDestroyed(arg); return Task.CompletedTask; };
|
client.ChannelDestroyed += arg => { ChannelDestroyed(arg); return Task.CompletedTask; };
|
||||||
client.ChannelUpdated += (arg1, arg2) => { ChannelUpdated(arg1, arg2); return Task.CompletedTask; };
|
client.ChannelUpdated += (arg1, arg2) => { ChannelUpdated(arg1, arg2); return Task.CompletedTask; };
|
||||||
client.JoinedGuild += (arg1) => { JoinedGuild(arg1); return Task.CompletedTask; };
|
client.JoinedGuild += (arg1) => { JoinedGuild(arg1); ++_guildCount; return Task.CompletedTask; };
|
||||||
client.LeftGuild += (arg1) => { LeftGuild(arg1); return Task.CompletedTask; };
|
client.LeftGuild += (arg1) => { LeftGuild(arg1); --_guildCount; return Task.CompletedTask; };
|
||||||
|
|
||||||
_log.Info($"Shard #{i} initialized.");
|
_log.Info($"Shard #{i} initialized.");
|
||||||
#if GLOBAL_NADEKO
|
#if GLOBAL_NADEKO
|
||||||
@ -106,10 +108,18 @@ namespace NadekoBot
|
|||||||
Clients.SelectMany(c => c.Guilds);
|
Clients.SelectMany(c => c.Guilds);
|
||||||
|
|
||||||
public int GetGuildsCount() =>
|
public int GetGuildsCount() =>
|
||||||
Clients.Sum(c => c.Guilds.Count);
|
_guildCount;
|
||||||
|
|
||||||
public SocketGuild GetGuild(ulong id) =>
|
public SocketGuild GetGuild(ulong id)
|
||||||
Clients.Select(c => c.GetGuild(id)).FirstOrDefault(g => g != null);
|
{
|
||||||
|
foreach (var c in Clients)
|
||||||
|
{
|
||||||
|
var g = c.GetGuild(id);
|
||||||
|
if (g != null)
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Task<IDMChannel> GetDMChannelAsync(ulong channelId) =>
|
public Task<IDMChannel> GetDMChannelAsync(ulong channelId) =>
|
||||||
Clients[0].GetDMChannelAsync(channelId);
|
Clients[0].GetDMChannelAsync(channelId);
|
||||||
@ -134,6 +144,7 @@ namespace NadekoBot
|
|||||||
await c.ConnectAsync().ConfigureAwait(false);
|
await c.ConnectAsync().ConfigureAwait(false);
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
_log.Info($"Shard #{c.ShardId} connected after {sw.Elapsed.TotalSeconds:F2}s ({++_connectedCount}/{Clients.Count})");
|
_log.Info($"Shard #{c.ShardId} connected after {sw.Elapsed.TotalSeconds:F2}s ({++_connectedCount}/{Clients.Count})");
|
||||||
|
_guildCount += c.Guilds.Count;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user