From e8adbde9d7ad12a813d7806e86cf8c3294e7e6f1 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 24 Feb 2016 04:00:50 +0100 Subject: [PATCH] .voicepresence added - closes #26 --- NadekoBot/Commands/LogCommand.cs | 37 +++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/NadekoBot/Commands/LogCommand.cs b/NadekoBot/Commands/LogCommand.cs index 2fc6c59e..6002fd87 100644 --- a/NadekoBot/Commands/LogCommand.cs +++ b/NadekoBot/Commands/LogCommand.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Threading.Tasks; using Discord.Commands; using Discord; +using System.Collections.Generic; namespace NadekoBot.Commands { class LogCommand : DiscordCommand { @@ -16,7 +17,9 @@ namespace NadekoBot.Commands { ConcurrentDictionary logs = new ConcurrentDictionary(); ConcurrentDictionary loggingPresences = new ConcurrentDictionary(); - + // + ConcurrentDictionary voiceChannelLog = new ConcurrentDictionary(); + public override Func DoFunc() => async e => { if (e.User.Id != NadekoBot.OwnerID || !e.User.ServerPermissions.ManageServer) @@ -76,6 +79,18 @@ namespace NadekoBot.Commands { } catch { } + try { + if (e.Before.VoiceChannel != null && voiceChannelLog.ContainsKey(e.Before.VoiceChannel)) { + if (e.After.VoiceChannel != e.Before.VoiceChannel) + await voiceChannelLog[e.Before.VoiceChannel].SendMessage($"🎼`{e.Before.Name} has left the` {e.Before.VoiceChannel.Mention} `voice channel.`"); + } + if (e.After.VoiceChannel != null && voiceChannelLog.ContainsKey(e.After.VoiceChannel)) { + if (e.After.VoiceChannel != e.Before.VoiceChannel) + await voiceChannelLog[e.After.VoiceChannel].SendMessage($"🎼`{e.After.Name} has joined the`{e.After.VoiceChannel.Mention} `voice channel.`"); + } + } + catch { } + try { Channel ch; if (!logs.TryGetValue(e.Server, out ch)) @@ -113,6 +128,26 @@ namespace NadekoBot.Commands { await e.Channel.SendMessage($"**User presence notifications disabled.**"); }); + + cgb.CreateCommand(".voicepresence") + .Description("Toggles logging to this channel whenever someone joins or leaves a voice channel you are in right now.") + .Do(async e => { + if (e.User.Id != NadekoBot.OwnerID || + !e.User.ServerPermissions.ManageServer) + return; + + if (e.User.VoiceChannel == null) { + await e.Channel.SendMessage("💢 You are not in a voice channel right now. If you are, please rejoin it."); + return; + } + Channel throwaway; + if (!voiceChannelLog.TryRemove(e.User.VoiceChannel, out throwaway)) { + voiceChannelLog.TryAdd(e.User.VoiceChannel, e.Channel); + await e.Channel.SendMessage($"`Logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`"); + } + else + await e.Channel.SendMessage($"`Stopped logging user updates for` {e.User.VoiceChannel.Mention} `voice channel.`"); + }); } } }