Exemplo n.º 1
0
        private async Task HandleClear(ChatMessage msg)
        {
            Relationships relation = null;

            m_currentSettings.Users.TryGetValue(msg.UserId, out relation);
            if (relation == null || relation.Friends.Count == 0)
            {
                await CommandUtils.SendResponse(m_firehose, msg, "I didn't find any friends to clear. 😭");

                return;
            }

            // Delete the friend pairings.
            List <int> toRemove = new List <int>();

            lock (relation.Friends)
            {
                toRemove = relation.Friends.ToList <int>();
                relation.Friends.Clear();
            }

            // Delete the followings
            foreach (int friendUserId in relation.Friends)
            {
                UpdateList(friendUserId, msg.UserId, false, false);
            }

            await CommandUtils.SendResponse(m_firehose, msg, "I cleared out all of your friends. Who needs them anyways?");

            SaveSettings();
            return;
        }
Exemplo n.º 2
0
        private async Task HandleLurk(ChatMessage msg)
        {
            bool isLurking = true;

            while (true)
            {
                Relationships relation;
                if (m_currentSettings.Users.TryGetValue(msg.UserId, out relation))
                {
                    relation.IsLurking = !relation.IsLurking;
                    isLurking          = relation.IsLurking;
                    break;
                }
                else
                {
                    Relationships rel = new Relationships()
                    {
                        IsLurking = true
                    };
                    if (m_currentSettings.Users.TryAdd(msg.UserId, rel))
                    {
                        break;
                    }
                }
            }
            await CommandUtils.SendResponse(m_firehose, msg, (isLurking ? "You're now lurking. 🙈 Your friends won't be notified when you join channels. Use ^lurk to stop lurking." : "No longer lurking, welcome back! 👋"));

            SaveSettings();
        }
Exemplo n.º 3
0
        private async Task HandleWhisperCommand(ChatMessage msg)
        {
            string userName = CommandUtils.GetSingleWordArgument(msg.Text);

            if (userName == null)
            {
                await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "I can globally whisper anyone on Mixer for you - they will get it no matter what channel they are watching. Give me a user name and the message you want to send.", true);

                return;
            }
            string message = CommandUtils.GetStringAfterFirstTwoWords(msg.Text);

            if (message == null)
            {
                await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "What do you want to say? Give me a user name and the message you want to send.", true);

                return;
            }

            int whispers = await CommandUtils.GlobalWhisper(m_firehose, userName, $"{msg.UserName} says: {message}");

            if (whispers == 0)
            {
                await CommandUtils.SendCantFindUser(m_firehose, msg, userName);
            }
            else
            {
                await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"I sent your message to {await MixerUtils.GetProperUserName(userName)} in {whispers} channels", true);
            }
        }
Exemplo n.º 4
0
        private async Task HandleAddOrRemove(ChatMessage msg, bool add)
        {
            // Get the target they want to add
            string friendUserName = CommandUtils.GetSecondSingleWordArgument(msg.Text);

            if (friendUserName == null)
            {
                await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"Who are we {(add ? "adding" : "removing")} as a friend? Specify a user name after the command.", true);

                return;
            }
            int?friendUserId = await MixerUtils.GetUserId(friendUserName);

            if (!friendUserId.HasValue)
            {
                await CommandUtils.SendMixerUserNotFound(m_firehose, msg, friendUserName);

                return;
            }

            // Add the friend to their list
            bool addedToFriends   = UpdateList(msg.UserId, friendUserId.Value, add, true);
            bool addedToFollowers = UpdateList(friendUserId.Value, msg.UserId, add, false);
            await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"You're {(add ? (!addedToFriends && !addedToFollowers ? "still" : "now") : "no longer")} friends with @{await MixerUtils.GetProperUserName(friendUserName)}{(add ? "! ❤️" : ". 💔")}", true);

            SaveSettings();
        }
Exemplo n.º 5
0
 public async void OnCommand(string command, ChatMessage msg)
 {
     if (command.Equals("msgstats"))
     {
         await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, GetCurrentStatsOutput(10), CommandUtils.ShouldForceIsWhisper(msg));
     }
 }
Exemplo n.º 6
0
        private async Task HandleClearMock(ChatMessage msg)
        {
            if (!CommandUtils.HasAdvancePermissions(msg.UserId))
            {
                await CommandUtils.SendAccessDenied(m_firehose, msg.ChannelId, msg.UserName);

                return;
            }

            // Clear all.
            m_mockDict.Clear();

            await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "I'm not mocking anyone anymore. 😢", msg.IsWhisper);
        }
Exemplo n.º 7
0
        private async Task HandleExit(ChatMessage msg)
        {
            if (!CommandUtils.HasAdvancePermissions(msg.UserId))
            {
                await CommandUtils.SendAccessDenied(m_firehose, msg);

                return;
            }
            await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"👋 Later! Powering down.", msg.IsWhisper);

            // Give the message time to send.
            await Task.Delay(1000);

            Environment.Exit(-1);
        }
Exemplo n.º 8
0
        private async Task HandleEcho(ChatMessage msg)
        {
            if (!CommandUtils.HasAdvancePermissions(msg.UserId))
            {
                await CommandUtils.SendAccessDenied(m_firehose, msg.ChannelId, msg.UserName);

                return;
            }
            string body = CommandUtils.GetCommandBody(msg.Text);

            if (!String.IsNullOrWhiteSpace(body))
            {
                await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, body, msg.IsWhisper);
            }
        }
Exemplo n.º 9
0
        public async void OnCommand(string command, ChatMessage msg)
        {
            if (command.Equals("friend") || command.Equals("friends"))
            {
                string secondaryCommand = CommandUtils.GetSingleWordArgument(msg.Text);
                if (secondaryCommand == null || secondaryCommand.Equals("help"))
                {
                    await CommandUtils.SendResponse(m_firehose, msg, $"Friends allows you interact with others through me and get notifications when they enter channels on Mixer. The friends subcommands are: find, list, add, remove, lurk, clear, help. Example: ^friends add Quinninator", true);

                    return;
                }
                if (secondaryCommand.Equals("add"))
                {
                    await HandleAddOrRemove(msg, true);
                }
                else if (secondaryCommand.Equals("remove"))
                {
                    await HandleAddOrRemove(msg, false);
                }
                else if (secondaryCommand.Equals("list"))
                {
                    await HandleList(msg);
                }
                else if (secondaryCommand.Equals("clear"))
                {
                    await HandleClear(msg);
                }
                else if (secondaryCommand.Equals("find"))
                {
                    await HandleFind(msg);
                }
                else if (secondaryCommand.Equals("lurk"))
                {
                    await HandleLurk(msg);
                }
            }
            else if (command.Equals("lurk"))
            {
                await HandleLurk(msg);
            }
        }
Exemplo n.º 10
0
        private async Task HandleFind(ChatMessage msg)
        {
            // See if we have a notification setup for this user.
            Relationships relation;

            if (!m_currentSettings.Users.TryGetValue(msg.UserId, out relation))
            {
                await CommandUtils.SendResponse(m_firehose, msg, "You don't have any friends. 😞", true);

                return;
            }

            // Get a local copy of the friends.
            List <int> friends;

            lock (relation.Friends)
            {
                friends = relation.Friends.ToList <int>();
            }
            await CommandUtils.SendResponse(m_firehose, msg, await FindOnlineFriends(friends), true);
        }
Exemplo n.º 11
0
        private async Task HandleFindCommand(ChatMessage msg)
        {
            string userName = CommandUtils.GetSingleWordArgument(msg.Text);

            if (userName == null)
            {
                await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"Find who? 🔍 You must specify a user name to find!", CommandUtils.ShouldForceIsWhisper(msg));

                return;
            }

            int?userId = await MixerUtils.GetUserId(userName);

            if (!userId.HasValue)
            {
                await CommandUtils.SendMixerUserNotFound(m_firehose, msg, userName);

                return;
            }

            // Find the user.
            List <int> channelIds = CreeperCarl.GetActiveChannelIds(userId.Value);

            if (channelIds == null)
            {
                await CommandUtils.SendCantFindUser(m_firehose, msg, userName);
            }
            else
            {
                // Go async to get the names.
                var _ignored = Task.Run(async() =>
                {
                    // Build the string.
                    string output = $"I found {await MixerUtils.GetProperUserName(userName)} in the following channels: " + await CommandUtils.FormatChannelIds(channelIds, 250) + ".";
                    await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, output, CommandUtils.ShouldForceIsWhisper(msg));
                }).ConfigureAwait(false);
            }
        }
Exemplo n.º 12
0
        private async Task HandleList(ChatMessage msg)
        {
            Relationships relation;

            if (m_currentSettings.Users.TryGetValue(msg.UserId, out relation))
            {
                string     output = "Your current friends are ";
                List <int> friends;
                lock (relation.Friends)
                {
                    friends = relation.Friends.ToList <int>();
                }
                output += await CommandUtils.FormatUserIds(friends, 250);

                await CommandUtils.SendResponse(m_firehose, msg, output, true);
            }
            else
            {
                await CommandUtils.SendResponse(m_firehose, msg, "It doesn't look like you have any friends yet. 😞", true);

                return;
            }
        }
Exemplo n.º 13
0
        private async Task HandleSummon(ChatMessage msg)
        {
            string summonUserName = CommandUtils.GetSingleWordArgument(msg.Text);

            if (summonUserName == null)
            {
                await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"Let me know who you want so summon. Give me a user name after the command.", msg.IsWhisper);

                return;
            }
            string channelName = await MixerUtils.GetChannelName(msg.ChannelId);

            if (channelName == null)
            {
                await CommandUtils.SendMixerUserNotFound(m_firehose, msg, summonUserName, true);

                return;
            }

            // Get the summon user's id.
            int?actionReceiverId = await MixerUtils.GetUserId(summonUserName);

            if (!actionReceiverId.HasValue)
            {
                await CommandUtils.SendCantFindUser(m_firehose, msg, summonUserName);

                return;
            }

            // Make sure they are friends, otherwise we don't want to do this.
            if (!(await CommandUtils.CheckForMutualFriendsAndMessageIfNot(m_firehose, msg, actionReceiverId.Value, "summon")))
            {
                return;
            }

            // Check to see if the user is running the extension.
            //if (await CheckIfUserHasAnActiveExtension(summonUserName))
            //{
            //    // The user has an active extension
            //    if (await PostSummonToExtension(summonUserName, msg.UserName, channelName))
            //    {
            //        await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"I send an extension summon to {summonUserName}", msg.IsWhisper);
            //    }
            //    else
            //    {
            //        await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"That's not right... I failed to send extension summon to {summonUserName}.", msg.IsWhisper);
            //    }
            //}
            //else
            //{
            // The user doesn't have the extension! Whisper them.
            string properChannelName = await MixerUtils.GetProperUserName(channelName);

            int whispers = await CommandUtils.GlobalWhisper(m_firehose, summonUserName, $"{msg.UserName} summons you to @{properChannelName}'s channel! https://mixer.com/{properChannelName}");

            if (whispers == 0)
            {
                await CommandUtils.SendCantFindUser(m_firehose, msg, summonUserName);
            }
            else
            {
                await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"I summoned {await MixerUtils.GetUserName(actionReceiverId.Value)} in {whispers} channel{(whispers > 1 ? "s" : "")}.", msg.IsWhisper);
            }
            //}
        }
Exemplo n.º 14
0
        public async void OnChatMessage(ChatMessage msg)
        {
            if (msg.Text.StartsWith("^") || msg.IsWhisper)
            {
                // Get the raw command.
                string command    = msg.Text;
                int    firstSpace = msg.Text.IndexOf(' ');
                if (firstSpace != -1)
                {
                    command = msg.Text.Substring(0, firstSpace);
                }
                if (command.StartsWith("^"))
                {
                    command = command.Substring(1);
                }
                command = command.ToLower();

                // Filter short commands.
                if (command.Length < 3)
                {
                    return;
                }

                // See if we can handle it internally.
                if (command.Equals("help") || command.Equals("command") || command.Equals("commands"))
                {
                    string response = $"Hello @{msg.UserName}! You can talk to me in any Mixer channel by entering '^<command>' or whispering a command. Commands: ";
                    if (CommandUtils.HasAdvancePermissions(msg.UserId))
                    {
                        response += $"hello, whisper, summon, find, friend, lurk, ping, echo, mock, pmock, cmock, userstats, msgstats, exit, about";
                    }
                    else
                    {
                        response = $"hello, whisper, summon, find, friend, lurk, userstats, msgstats, about";
                    }
                    await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, response, CommandUtils.ShouldForceIsWhisper(msg));
                }
                if (command.Equals("about"))
                {
                    await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "Hey there! I'm Karl! 🤗 I'm an experimental global chat observer created by @Quinninator and @BoringNameHere. To see what I can do, try whispering me ^commands.", CommandUtils.ShouldForceIsWhisper(msg));
                }
                else if (command.Equals("hello") | command.Equals("hi"))
                {
                    await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, $"👋 @{msg.UserName}", CommandUtils.ShouldForceIsWhisper(msg));
                }
                else if (command.Equals("ping"))
                {
                    await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "Pong!", CommandUtils.ShouldForceIsWhisper(msg));
                }
                else if (command.Equals("exit"))
                {
                    await HandleExit(msg);
                }
                else if (command.Equals("echo"))
                {
                    await HandleEcho(msg);
                }
                else if (command.Equals("find"))
                {
                    await HandleFindCommand(msg);
                }
                else if (command.Equals("whisper"))
                {
                    await HandleWhisperCommand(msg);
                }
                else if (command.Equals("summon"))
                {
                    await HandleSummon(msg);
                }
                else if (command.Equals("mock"))
                {
                    await HandleMockToggle(msg, true);
                }
                else if (command.Equals("pmock"))
                {
                    await HandleMockToggle(msg, false);
                }
                else if (command.Equals("cmock"))
                {
                    await HandleClearMock(msg);
                }
                else
                {
                    // If we can't handle it internally, fire it to the others.
                    m_commandCallback.OnCommand(command, msg);
                }
            }
            else
            {
                // Check if we need to mock.
                CheckForMock(msg);
            }
        }
Exemplo n.º 15
0
        private async Task HandleMockToggle(ChatMessage msg, bool isPrivate)
        {
            if (!CommandUtils.HasAdvancePermissions(msg.UserId))
            {
                await CommandUtils.SendAccessDenied(m_firehose, msg.ChannelId, msg.UserName);

                return;
            }

            // Find the user name.
            string userName = CommandUtils.GetSingleWordArgument(msg.Text);

            if (userName == null)
            {
                await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, "I need a user name.", true);

                return;
            }

            // Get the user id.
            int?userId = await MixerUtils.GetUserId(userName);

            if (!userId.HasValue || userName.Length == 0)
            {
                await CommandUtils.SendMixerUserNotFound(m_firehose, msg, userName);

                return;
            }

            // Update the map.
            bool removed = false;
            bool currentValue;

            if (m_mockDict.TryGetValue(userId.Value, out currentValue))
            {
                // Remove if it's the same toggle.
                if (currentValue == isPrivate)
                {
                    removed = true;
                    m_mockDict.TryRemove(userId.Value, out currentValue);
                }
                // Otherwise, toggle it
                else
                {
                    m_mockDict.TryUpdate(userId.Value, isPrivate, currentValue);
                    currentValue = isPrivate;
                }
            }
            else
            {
                // If they are not in the map, add them.
                m_mockDict.TryAdd(userId.Value, isPrivate);
                currentValue = isPrivate;
            }

            string output;

            if (removed)
            {
                output = $"I'm no longer mocking {await MixerUtils.GetProperUserName(userName)}. Lucky them.";
            }
            else
            {
                output = $"I'm now {(currentValue ? "privately" : "publically")} mocking {await MixerUtils.GetProperUserName(userName)} 😮";
            }
            await CommandUtils.SendResponse(m_firehose, msg.ChannelId, msg.UserName, output, msg.IsWhisper);

            return;
        }