.userpresence added

This commit is contained in:
Master Kwoth 2016-02-18 06:50:25 +01:00
parent 4404150693
commit e9b8084cc4

View File

@ -15,7 +15,8 @@ namespace NadekoBot.Commands {
} }
ConcurrentDictionary<Server, Channel> logs = new ConcurrentDictionary<Server, Channel>(); ConcurrentDictionary<Server, Channel> logs = new ConcurrentDictionary<Server, Channel>();
ConcurrentDictionary<Server, Channel> loggingPresences = new ConcurrentDictionary<Server, Channel>();
public override Func<CommandEventArgs, Task> DoFunc() => async e => { public override Func<CommandEventArgs, Task> DoFunc() => async e => {
if (e.User.Id != NadekoBot.OwnerID || if (e.User.Id != NadekoBot.OwnerID ||
e.User.Server.Owner.Id != e.User.Id) e.User.Server.Owner.Id != e.User.Id)
@ -64,17 +65,33 @@ namespace NadekoBot.Commands {
catch { } catch { }
} }
private async void UsrUpdtd(object sender, UserUpdatedEventArgs e) { 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 { try {
Channel ch; Channel ch;
if (!logs.TryGetValue(e.Server, out ch)) if (!logs.TryGetValue(e.Server, out ch))
return; 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) 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) 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) 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 else
return; return;
await ch.SendMessage(str); await ch.SendMessage(str);
@ -85,6 +102,22 @@ namespace NadekoBot.Commands {
cgb.CreateCommand(".logserver") cgb.CreateCommand(".logserver")
.Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.") .Description("Toggles logging in this channel. Logs every message sent/deleted/edited on the server. BOT OWNER ONLY. SERVER OWNER ONLY.")
.Do(DoFunc()); .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.**");
});
} }
} }
} }