Logging almost done

This commit is contained in:
Kwoth 2016-09-06 23:34:00 +02:00
parent e50e4f15c3
commit 97d976ea4d
7 changed files with 130 additions and 345 deletions

View File

@ -33,170 +33,8 @@
// NadekoBot.Client.ChannelDestroyed += ChannelDestroyed;
// NadekoBot.Client.ChannelUpdated += ChannelUpdated;
// 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 { }
// };
// // start the userpresence queue
// 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 { }
// }
// await Task.Delay(5000);
// }
// });
// }
// 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 { }
// }
// 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 { }
// }
// 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 { }
// }
// 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 { }
// }
// 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 { }
// }
// 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 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 { }
// }
// private async void MsgRecivd(object sender, MessageEventArgs e)
// {
@ -226,112 +64,9 @@
// }
// 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 { }
// 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 { }
// try
// {
// var chId = SpecificConfigurations.Default.Of(e.Server.Id).LogServerChannel;

View File

@ -29,12 +29,14 @@ namespace NadekoBot.Modules.Administration
public ConcurrentDictionary<ulong, LogSetting> GuildLogSettings { get; }
private ConcurrentDictionary<ITextChannel, List<string>> UserPresenceUpdates { get; }
private ConcurrentDictionary<ITextChannel, List<string>> UserPresenceUpdates { get; } = new ConcurrentDictionary<ITextChannel, List<string>>();
private Timer t;
private IGoogleApiService _google { get; }
public LogCommands(DiscordSocketClient client)
public LogCommands(DiscordSocketClient client, IGoogleApiService google)
{
_client = client;
_google = google;
_log = LogManager.GetCurrentClassLogger();
using (var uow = DbHandler.UnitOfWork())
@ -50,11 +52,8 @@ namespace NadekoBot.Modules.Administration
foreach (var key in keys)
{
List<string> messages;
UserPresenceUpdates.TryRemove(key, out messages);
foreach (var msg in messages)
{
await key.SendMessageAsync(msg);
}
if (UserPresenceUpdates.TryRemove(key, out messages))
try { await key.SendMessageAsync(string.Join(Environment.NewLine, messages)); } catch { } //502/403
}
}, null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10));
@ -68,18 +67,61 @@ namespace NadekoBot.Modules.Administration
_client.UserLeft += _client_UserLeft;
_client.UserPresenceUpdated += _client_UserPresenceUpdated;
_client.UserVoiceStateUpdated += _client_UserVoiceStateUpdated;
_client.UserUpdated += _client_UserUpdated;
_client.ChannelCreated += _client_ChannelCreated;
_client.ChannelDestroyed += _client_ChannelDestroyed;
_client.ChannelUpdated += _client_ChannelUpdated;
}
private Task _client_UserUpdated(IGuildUser before, IGuildUser after)
{
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting)
|| !logSetting.IsLogging
|| !logSetting.UserUpdated)
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(before.Guild, logSetting)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
string str = $"🕔`{prettyCurrentTime}`";
if (before.Username != after.Username)
str += $"**Name Changed**👤`{before.Username}#{before.Discriminator}`\n\t\t`New:`{after.ToString()}`";
else if (before.Nickname != after.Nickname)
str += $"**Nickname Changed**👤`{before.Username}#{before.Discriminator}`\n\t\t`Old:` {before.Nickname}#{before.Discriminator}\n\t\t`New:` {after.Nickname}#{after.Discriminator}";
else if (before.AvatarUrl != after.AvatarUrl)
str += $"**Avatar Changed**👤`{before.Username}#{before.Discriminator}`\n\t {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}";
else if (!before.Roles.SequenceEqual(after.Roles))
{
if (before.Roles.Count() < after.Roles.Count())
{
var diffRoles = after.Roles.Where(r => !before.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
str += $"**User's Roles changed ⚔➕**👤`{before.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role.";
}
else if (before.Roles.Count() > after.Roles.Count())
{
var diffRoles = before.Roles.Where(r => !after.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
str += $"**User's Roles changed ⚔➖**👤`{before.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role.";
}
}
else
return;
await logChannel.SendMessageAsync(str).ConfigureAwait(false);
});
return Task.CompletedTask;
}
private Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
{
var before = cbefore as ITextChannel;
var before = cbefore as IGuildChannel;
if (before == null)
return Task.CompletedTask;
var after = (ITextChannel)cafter;
var after = (IGuildChannel)cafter;
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out logSetting)
@ -88,7 +130,7 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = before.Guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(before.Guild, logSetting)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
@ -97,10 +139,10 @@ namespace NadekoBot.Modules.Administration
await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{after.Name}` ({after.Id})
`Old:` {before.Name}
`New:` {after.Name}").ConfigureAwait(false);
else if (before.Topic != after.Topic)
else if ((before as ITextChannel).Topic != (after as ITextChannel).Topic)
await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{after.Name}` ({after.Id})
`Old:` {before.Topic}
`New:` {after.Topic}").ConfigureAwait(false);
`Old:` {((ITextChannel)before).Topic}
`New:` {((ITextChannel)after).Topic}").ConfigureAwait(false);
});
return Task.CompletedTask;
@ -119,7 +161,7 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = ch.Guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(ch.Guild, logSetting)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
@ -143,7 +185,7 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = ch.Guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(ch.Guild, logSetting)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
@ -169,29 +211,28 @@ namespace NadekoBot.Modules.Administration
LogSetting logSetting;
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out logSetting)
|| !logSetting.LogVoicePresence
|| !logSetting.IgnoredChannels.Any(ic => ic.ChannelId == after.VoiceChannel.Id))
|| logSetting.IgnoredChannels.Any(ic => ic.ChannelId == after.VoiceChannel.Id))
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogChannelType.Voice)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
_log.Info("Voice state");
string str = null;
if (beforeVch?.Guild == afterVch?.Guild)
{
await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel.").ConfigureAwait(false);
str = $"🎼`{prettyCurrentTime}` {usr.Username} moved from **{beforeVch.Name}** to **{afterVch.Name}** voice channel.";
}
else if (beforeVch == null)
{
await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has joined **{afterVch.Name}** voice channel.").ConfigureAwait(false);
str = $"🎼`{prettyCurrentTime}` {usr.Username} has joined **{afterVch.Name}** voice channel.";
}
else if (afterVch == null)
{
await logChannel.SendMessageAsync($"🎼`{prettyCurrentTime}` {usr.Username} has left **{beforeVch.Name}** voice channel.").ConfigureAwait(false);
str = $"🎼`{prettyCurrentTime}` {usr.Username} has left **{beforeVch.Name}** voice channel.";
}
});
if(str != null)
UserPresenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; });
return Task.CompletedTask;
}
@ -205,16 +246,15 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = usr.Guild.GetTextChannel(logSetting.UserPresenceChannelId)) == null)
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting, LogChannelType.UserPresence)) == null)
return Task.CompletedTask;
string str;
if (before.Status != after.Status)
str = $"`{prettyCurrentTime}`**{usr.Username}** is now **{after.Status}**.";
else
str = $"`{prettyCurrentTime}`**{usr.Username}** is now playing **{after.Status}**.";
var task = Task.Run(async () =>
{
if(before.Status != after.Status)
await logChannel.SendMessageAsync($"`{prettyCurrentTime}`**{usr.Username}** is now **{after.Status}**.");
else
await logChannel.SendMessageAsync($"`{prettyCurrentTime}`**{usr.Username}** is now playing **{after.Status}**.");
});
UserPresenceUpdates.AddOrUpdate(logChannel, new List<string>() { str }, (id, list) => { list.Add(str); return list; });
return Task.CompletedTask;
}
@ -228,7 +268,7 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
@ -248,7 +288,7 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = usr.Guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(usr.Guild, logSetting)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
@ -268,7 +308,7 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(guild, logSetting)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
@ -288,7 +328,7 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(guild, logSetting)) == null)
return Task.CompletedTask;
var task = Task.Run(async () =>
@ -302,11 +342,9 @@ namespace NadekoBot.Modules.Administration
private Task _client_MessageDeleted(ulong arg1, Optional<IMessage> imsg)
{
var msg = (imsg.IsSpecified ? imsg.Value : null) as IUserMessage;
if (msg == null)
if (msg == null || msg.IsAuthor())
return Task.CompletedTask;
var ch = msg.Channel as ITextChannel;
var channel = msg.Channel as ITextChannel;
if (channel == null)
return Task.CompletedTask;
@ -318,14 +356,16 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = channel.Guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == msg.Id)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{ch.Name}`
👤`{msg.Author.Username}`: {msg.Content}
`Attachements`: {string.Join(", ", msg.Attachments.Select(a=>a.ProxyUrl))}").ConfigureAwait(false);
var str = $@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{channel.Name}`
👤`{msg.Author.Username}`: {msg.Resolve(userHandling:UserMentionHandling.NameAndDiscriminator)}";
if (msg.Attachments.Any())
str += $"{Environment.NewLine}`Attachements`: {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}";
await logChannel.SendMessageAsync(str).ConfigureAwait(false);
});
return Task.CompletedTask;
@ -334,7 +374,7 @@ namespace NadekoBot.Modules.Administration
private Task _client_MessageUpdated(Optional<IMessage> optmsg, IMessage imsg2)
{
var after = imsg2 as IUserMessage;
if (after == null)
if (after == null || after.IsAuthor())
return Task.CompletedTask;
var before = (optmsg.IsSpecified ? optmsg.Value : null) as IUserMessage;
@ -352,15 +392,15 @@ namespace NadekoBot.Modules.Administration
return Task.CompletedTask;
ITextChannel logChannel;
if ((logChannel = channel.Guild.GetTextChannel(logSetting.ChannelId)) == null)
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == after.Channel.Id)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
await logChannel.SendMessageAsync($@"🕔`{prettyCurrentTime}` **Message** 📝 `#{channel.Name}`
👤`{before.Author.Username}`
`Old:` {before.Content}
`New:` {after.Content}").ConfigureAwait(false);
`Old:` {before.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}
`New:` {after.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}").ConfigureAwait(false);
});
return Task.CompletedTask;
@ -369,7 +409,7 @@ namespace NadekoBot.Modules.Administration
private Task _client_MessageReceived(IMessage imsg)
{
var msg = imsg as IUserMessage;
if (msg == null)
if (msg == null || msg.IsAuthor())
return Task.CompletedTask;
var channel = msg.Channel as ITextChannel;
@ -382,9 +422,17 @@ namespace NadekoBot.Modules.Administration
|| !logSetting.MessageReceived)
return Task.CompletedTask;
var task = Task.Run(() =>
ITextChannel logChannel;
if ((logChannel = TryGetLogChannel(channel.Guild, logSetting)) == null || logChannel.Id == imsg.Channel.Id)
return Task.CompletedTask;
var task = Task.Run(async () =>
{
_log.Info("Message received");
var str = $@"🕔`{prettyCurrentTime}` **New Message** `#{channel.Name}`
👤`{msg.Author.Username}`: {msg.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}";
if (msg.Attachments.Any())
str += $"{Environment.NewLine}`Attachements`: {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}";
await logChannel.SendMessageAsync(str).ConfigureAwait(false);
});
return Task.CompletedTask;
@ -569,26 +617,27 @@ namespace NadekoBot.Modules.Administration
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);
// }
[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 logSetting = uow.GuildConfigs.For(channel.Guild.Id).LogSetting;
GuildLogSettings.AddOrUpdate(channel.Guild.Id, (id) => logSetting, (id, old) => logSetting);
enabled = logSetting.LogVoicePresence = !logSetting.LogVoicePresence;
if (enabled)
logSetting.VoicePresenceChannelId = channel.Id;
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);
//}
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)]

View File

@ -71,7 +71,7 @@ namespace NadekoBot.Modules.Administration
var usrMsg = umsg as IUserMessage;
var channel = usrMsg.Channel as ITextChannel;
if (channel == null || await usrMsg.IsAuthor())
if (channel == null || usrMsg.IsAuthor())
return;
Ratelimiter limiter;
if (!RatelimitingChannels.TryGetValue(channel.Id, out limiter))

View File

@ -8,10 +8,10 @@ namespace NadekoBot.Modules
{
public class DiscordModule
{
protected ILocalization _l;
protected CommandService _commands;
protected DiscordSocketClient _client;
protected Logger _log;
protected ILocalization _l { get; }
protected CommandService _commands { get; }
protected DiscordSocketClient _client { get; }
protected Logger _log { get; }
public DiscordModule(ILocalization loc, CommandService cmds, DiscordSocketClient client)
{

View File

@ -199,7 +199,7 @@ namespace NadekoBot.Modules.Gambling
var msg = imsg as IUserMessage;
if (msg == null)
return;
if (await msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel)
if (msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel)
return;
messagesSinceGameStarted++;
}

View File

@ -35,7 +35,7 @@ namespace NadekoBot
Client = new DiscordSocketClient(new DiscordSocketConfig
{
AudioMode = Discord.Audio.AudioMode.Outgoing,
LargeThreshold = 200,
MessageCacheSize = 10,
LogLevel = LogSeverity.Warning,
});

View File

@ -36,8 +36,8 @@ namespace NadekoBot.Extensions
public static async Task<IUserMessage> Reply(this IUserMessage msg, string content) =>
await msg.Channel.SendMessageAsync(content).ConfigureAwait(false);
public static Task<bool> IsAuthor(this IUserMessage msg) =>
Task.FromResult(NadekoBot.Client.GetCurrentUser().Id == msg.Author.Id);
public static bool IsAuthor(this IUserMessage msg) =>
NadekoBot.Client.GetCurrentUser().Id == msg.Author.Id;
public static IEnumerable<IUser> Members(this IRole role) =>
NadekoBot.Client.GetGuild(role.GuildId)?.GetUsers().Where(u => u.Roles.Contains(role)) ?? Enumerable.Empty<IUser>();
@ -227,5 +227,6 @@ namespace NadekoBot.Extensions
public static ulong GiB(this ulong value) => value.MiB() * 1024;
public static ulong GB(this ulong value) => value.MB() * 1000;
public static string Unmention(this string str) => str.Replace("@", "ම");
}
}