From e9b8084cc47c6abcd3df181144b636ef5c9bacde Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 18 Feb 2016 06:50:25 +0100 Subject: [PATCH] .userpresence added --- NadekoBot/Commands/LogCommand.cs | 43 ++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/NadekoBot/Commands/LogCommand.cs b/NadekoBot/Commands/LogCommand.cs index fa544f2b..f02f3d34 100644 --- a/NadekoBot/Commands/LogCommand.cs +++ b/NadekoBot/Commands/LogCommand.cs @@ -15,7 +15,8 @@ namespace NadekoBot.Commands { } ConcurrentDictionary logs = new ConcurrentDictionary(); - + ConcurrentDictionary loggingPresences = new ConcurrentDictionary(); + public override Func DoFunc() => async e => { if (e.User.Id != NadekoBot.OwnerID || e.User.Server.Owner.Id != e.User.Id) @@ -64,17 +65,33 @@ namespace NadekoBot.Commands { catch { } } private async void UsrUpdtd(object sender, UserUpdatedEventArgs e) { + try { + Channel ch; + if (loggingPresences.TryGetValue(e.Server, out ch)) + if (e.Before.Status != e.After.Status) { + var msg = await ch.SendMessage($"**{e.Before.Name}** is now **{e.After.Status}**."); + Task.Run(async () => { + try { + Task.Delay(4000); + msg.Delete(); + } + catch { } + }); + } + } + catch { } + try { Channel ch; if (!logs.TryGetValue(e.Server, out ch)) return; - string str = $"`Type:` **User updated** `Time:` **{DateTime.Now}**\n"; + string str = $"`Type:` **User updated** `Time:` **{DateTime.Now}** `User:` **{e.Before.Name}**\n"; if (e.Before.Name != e.After.Name) - str += $"**Name changed** `FROM` **{e.Before.Name}** `TO` **{e.After.Name}**"; + str += $"`New name:` **{e.After.Name}**"; else if (e.Before.AvatarUrl != e.After.AvatarUrl) - str += $"**Avatar url changed**\n `FROM`\n {e.Before.AvatarUrl}\n `TO` {e.After.AvatarUrl}"; + str += $"`New Avatar:` {e.After.AvatarUrl}"; else if (e.Before.Status != e.After.Status) - str += $"**Status changed FROM** `{e.Before.Status}` **TO** `{e.After.Status}`"; + str += $"Status `{e.Before.Status}` -> `{e.After.Status}`"; else return; await ch.SendMessage(str); @@ -85,6 +102,22 @@ namespace NadekoBot.Commands { cgb.CreateCommand(".logserver") .Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.") .Do(DoFunc()); + + cgb.CreateCommand(".userpresence") + .Description("Starts logging to this channel when someone from the server goes online/offline/idle. BOT OWNER ONLY. SERVER OWNER ONLY.") + .Do(async e => { + if (e.User.Id != NadekoBot.OwnerID || + e.User.Server.Owner.Id != e.User.Id) + return; + Channel ch; + if (!loggingPresences.TryRemove(e.Server, out ch)) { + loggingPresences.TryAdd(e.Server, e.Channel); + await e.Channel.SendMessage($"**User presence notifications enabled.**"); + return; + } + + await e.Channel.SendMessage($"**User presence notifications disabled.**"); + }); } } }