Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public async void OnUserActivity(AdvanceUserActivity activity)
        {
            // Only look at joins.
            if (!activity.IsJoin)
            {
                return;
            }

            // See if we have a notification setup for this user.
            Relationships relation;

            if (m_currentSettings.Users.TryGetValue(activity.UserId, out relation))
            {
                // Only send out notifications every so often.
                bool doFriendsCheck   = (DateTime.Now - relation.LastFriendsCheckTime) > c_minTimeBetweenFriendsCheck;
                bool doOnlineAnnounce = !relation.IsLurking && (DateTime.Now - relation.LastOnlineAnnounceTime) > c_minTimeBetweenOnlineAnnounce;
                if (!doFriendsCheck && !doOnlineAnnounce)
                {
                    return;
                }
                relation.LastFriendsCheckTime = relation.LastOnlineAnnounceTime = DateTime.Now;

                // Get the user data
                string userName = await MixerUtils.GetUserName(activity.UserId);

                if (userName == null)
                {
                    return;
                }
                string channelName = await MixerUtils.GetChannelName(activity.ChannelId);

                if (channelName == null)
                {
                    return;
                }

                if (doOnlineAnnounce)
                {
                    // Send notifications that the user is now online
                    List <int> notifiy = null;
                    lock (relation.UsersWhoFriended)
                    {
                        notifiy = relation.UsersWhoFriended.ToList <int>();
                    }
                    foreach (var userId in notifiy)
                    {
                        await CommandUtils.GlobalWhisper(m_firehose, userId, $"@{userName} has become active in @{channelName}");
                    }
                }

                if (doFriendsCheck)
                {
                    // Tell them what friends they have online.
                    List <int> friends;
                    lock (relation.Friends)
                    {
                        friends = relation.Friends.ToList <int>();
                    }
                    if (friends.Count > 0)
                    {
                        await CommandUtils.GlobalWhisper(m_firehose, activity.UserId, userName, await FindOnlineFriends(friends));
                    }
                }
            }
        }
Esempio n. 3
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);
            }
            //}
        }