コード例 #1
0
        private async Task RunGameWispCommand(EventCommand command, GameWispSubscribeEvent subscribeEvent)
        {
            if (command != null)
            {
                UserViewModel user = new UserViewModel(0, subscribeEvent.Username);

                UserModel userModel = await ChannelSession.Connection.GetUser(subscribeEvent.Username);

                if (userModel != null)
                {
                    user = new UserViewModel(userModel);
                }

                GameWispTier tier = null;
                if (ChannelSession.Services.GameWisp != null)
                {
                    tier = ChannelSession.Services.GameWisp.ChannelInfo.GetActiveTiers().FirstOrDefault(t => t.ID.ToString().Equals(subscribeEvent.TierID));
                }

                command.AddSpecialIdentifier("subscribemonths", subscribeEvent.SubscribeMonths.ToString());
                command.AddSpecialIdentifier("subscribeamount", subscribeEvent.Amount);
                if (tier != null)
                {
                    command.AddSpecialIdentifier("subscribetier", tier.Title);
                }

                await command.Perform(user);
            }
        }
コード例 #2
0
        protected override async Task ProcessReceivedPacket(string packetJSON)
        {
            if (!string.IsNullOrEmpty(packetJSON))
            {
                GawkBoxAlert alert = JsonConvert.DeserializeObject <GawkBoxAlert>(packetJSON);
                if (alert != null && alert.Gifts.Count > 0)
                {
                    UserDonationModel donation = alert.ToGenericDonation();
                    GlobalEvents.DonationOccurred(donation);

                    UserViewModel user = new UserViewModel(0, donation.UserName);

                    UserModel userModel = await ChannelSession.Connection.GetUser(user.UserName);

                    if (userModel != null)
                    {
                        user = new UserViewModel(userModel);
                    }

                    EventCommand command = ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.GawkBoxDonation));
                    if (command != null)
                    {
                        command.AddSpecialIdentifier("donationsource", EnumHelper.GetEnumName(donation.Source));
                        command.AddSpecialIdentifier("donationamount", donation.AmountText);
                        command.AddSpecialIdentifier("donationmessage", donation.Message);
                        command.AddSpecialIdentifier("donationimage", donation.ImageLink);
                        await command.Perform(user);
                    }
                }
            }
        }
コード例 #3
0
        private async Task BackgroundDonationCheck()
        {
            Dictionary <int, StreamlabsDonation> donationsReceived = new Dictionary <int, StreamlabsDonation>();

            foreach (StreamlabsDonation donation in await this.GetDonations())
            {
                donationsReceived[donation.ID] = donation;
            }

            while (!this.cancellationTokenSource.Token.IsCancellationRequested)
            {
                try
                {
                    foreach (StreamlabsDonation slDonation in await this.GetDonations())
                    {
                        if (!donationsReceived.ContainsKey(slDonation.ID))
                        {
                            donationsReceived[slDonation.ID] = slDonation;
                            UserDonationModel donation = slDonation.ToGenericDonation();
                            GlobalEvents.DonationOccurred(donation);

                            UserViewModel user = new UserViewModel(0, donation.UserName);

                            UserModel userModel = await ChannelSession.Connection.GetUser(user.UserName);

                            if (userModel != null)
                            {
                                user = new UserViewModel(userModel);
                            }

                            EventCommand command = ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.StreamlabsDonation));
                            if (command != null)
                            {
                                command.AddSpecialIdentifier("donationsource", EnumHelper.GetEnumName(donation.Source));
                                command.AddSpecialIdentifier("donationamount", donation.AmountText);
                                command.AddSpecialIdentifier("donationmessage", donation.Message);
                                command.AddSpecialIdentifier("donationimage", donation.ImageLink);
                                await command.Perform(user);
                            }
                        }
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

                await Task.Delay(10000);
            }
        }
コード例 #4
0
        private async Task BackgroundDonationCheck()
        {
            int             currentCampaign = 0;
            TiltifyCampaign campaign        = null;
            Dictionary <int, TiltifyDonation> donationsReceived = new Dictionary <int, TiltifyDonation>();

            while (!this.cancellationTokenSource.Token.IsCancellationRequested)
            {
                try
                {
                    if (ChannelSession.Settings.TiltifyCampaign != currentCampaign)
                    {
                        currentCampaign = ChannelSession.Settings.TiltifyCampaign;
                        donationsReceived.Clear();

                        IEnumerable <TiltifyCampaign> campaigns = await this.GetCampaigns(this.user);

                        campaign = campaigns.FirstOrDefault(c => c.ID.Equals(currentCampaign));
                        if (campaign != null)
                        {
                            foreach (TiltifyDonation donation in await this.GetCampaignDonations(campaign))
                            {
                                donationsReceived[donation.ID] = donation;
                            }
                        }
                    }

                    if (campaign != null)
                    {
                        foreach (TiltifyDonation tDonation in await this.GetCampaignDonations(campaign))
                        {
                            if (!donationsReceived.ContainsKey(tDonation.ID))
                            {
                                donationsReceived[tDonation.ID] = tDonation;
                                UserDonationModel donation = tDonation.ToGenericDonation();
                                GlobalEvents.DonationOccurred(donation);

                                UserViewModel user = new UserViewModel(0, donation.UserName);

                                UserModel userModel = await ChannelSession.Connection.GetUser(user.UserName);

                                if (userModel != null)
                                {
                                    user = new UserViewModel(userModel);
                                }

                                EventCommand command = ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.TiltifyDonation));
                                if (command != null)
                                {
                                    command.AddSpecialIdentifier("donationsource", EnumHelper.GetEnumName(donation.Source));
                                    command.AddSpecialIdentifier("donationamount", donation.AmountText);
                                    command.AddSpecialIdentifier("donationmessage", donation.Message);
                                    command.AddSpecialIdentifier("donationimage", donation.ImageLink);
                                    await command.Perform(user);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

                await Task.Delay(10000);
            }
        }
コード例 #5
0
        private async void ConstellationClient_OnSubscribedEventOccurred(object sender, ConstellationLiveEventModel e)
        {
            UserViewModel user     = null;
            bool?         followed = null;
            ChannelModel  channel  = null;

            JToken userToken;

            if (e.payload.TryGetValue("user", out userToken))
            {
                user = new UserViewModel(userToken.ToObject <UserModel>());

                JToken subscribeStartToken;
                if (e.payload.TryGetValue("since", out subscribeStartToken))
                {
                    user.SubscribeDate = subscribeStartToken.ToObject <DateTimeOffset>();
                }

                if (e.payload.TryGetValue("following", out JToken followedToken))
                {
                    followed = (bool)followedToken;
                }
            }
            else if (e.payload.TryGetValue("hoster", out userToken))
            {
                channel = userToken.ToObject <ChannelModel>();
                user    = new UserViewModel(channel.id, channel.token);
            }

            if (e.channel.Equals(ConstellationClientWrapper.ChannelUpdateEvent.ToString()))
            {
                if (e.payload["online"] != null)
                {
                    bool online = e.payload["online"].ToObject <bool>();
                    user = ChannelSession.GetCurrentUser();
                    if (online)
                    {
                        if (this.CanUserRunEvent(user, EnumHelper.GetEnumName(OtherEventTypeEnum.MixerChannelStreamStart)))
                        {
                            this.LogUserRunEvent(user, EnumHelper.GetEnumName(OtherEventTypeEnum.MixerChannelStreamStart));
                            await this.RunEventCommand(this.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.MixerChannelStreamStart)), user);
                        }
                    }
                    else
                    {
                        if (this.CanUserRunEvent(user, EnumHelper.GetEnumName(OtherEventTypeEnum.MixerChannelStreamStop)))
                        {
                            this.LogUserRunEvent(user, EnumHelper.GetEnumName(OtherEventTypeEnum.MixerChannelStreamStop));
                            await this.RunEventCommand(this.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.MixerChannelStreamStop)), user);
                        }
                    }
                }
            }
            else if (e.channel.Equals(ConstellationClientWrapper.ChannelFollowEvent.ToString()))
            {
                if (followed.GetValueOrDefault())
                {
                    if (this.CanUserRunEvent(user, ConstellationClientWrapper.ChannelFollowEvent.ToString()))
                    {
                        this.LogUserRunEvent(user, ConstellationClientWrapper.ChannelFollowEvent.ToString());

                        foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values)
                        {
                            user.Data.AddCurrencyAmount(currency, currency.OnFollowBonus);
                        }

                        if (this.OnFollowOccurred != null)
                        {
                            this.OnFollowOccurred(this, user);
                        }

                        await this.RunEventCommand(this.FindMatchingEventCommand(e.channel), user);
                    }
                }
                else
                {
                    if (this.CanUserRunEvent(user, EnumHelper.GetEnumName(OtherEventTypeEnum.MixerUserUnfollow)))
                    {
                        this.LogUserRunEvent(user, EnumHelper.GetEnumName(OtherEventTypeEnum.MixerUserUnfollow));
                        await this.RunEventCommand(this.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.MixerUserUnfollow)), user);
                    }

                    if (this.OnUnfollowOccurred != null)
                    {
                        this.OnUnfollowOccurred(this, user);
                    }
                }
            }
            else if (e.channel.Equals(ConstellationClientWrapper.ChannelHostedEvent.ToString()))
            {
                if (this.CanUserRunEvent(user, ConstellationClientWrapper.ChannelHostedEvent.ToString()))
                {
                    this.LogUserRunEvent(user, ConstellationClientWrapper.ChannelHostedEvent.ToString());

                    int viewerCount = 0;
                    if (channel != null)
                    {
                        viewerCount = (int)channel.viewersCurrent;
                    }

                    foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values)
                    {
                        user.Data.AddCurrencyAmount(currency, currency.OnHostBonus);
                    }

                    if (this.OnHostedOccurred != null)
                    {
                        this.OnHostedOccurred(this, new Tuple <UserViewModel, int>(user, viewerCount));
                    }

                    EventCommand command = this.FindMatchingEventCommand(e.channel);
                    if (command != null)
                    {
                        command.AddSpecialIdentifier("hostviewercount", viewerCount.ToString());
                        await this.RunEventCommand(command, user);
                    }
                }
            }
            else if (e.channel.Equals(ConstellationClientWrapper.ChannelSubscribedEvent.ToString()))
            {
                if (this.CanUserRunEvent(user, ConstellationClientWrapper.ChannelSubscribedEvent.ToString()))
                {
                    this.LogUserRunEvent(user, ConstellationClientWrapper.ChannelSubscribedEvent.ToString());

                    user.SubscribeDate = DateTimeOffset.Now;
                    foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values)
                    {
                        user.Data.AddCurrencyAmount(currency, currency.OnSubscribeBonus);
                    }

                    if (this.OnSubscribedOccurred != null)
                    {
                        this.OnSubscribedOccurred(this, user);
                    }

                    await this.RunEventCommand(this.FindMatchingEventCommand(e.channel), user);
                }
            }
            else if (e.channel.Equals(ConstellationClientWrapper.ChannelResubscribedEvent.ToString()) || e.channel.Equals(ConstellationClientWrapper.ChannelResubscribedSharedEvent.ToString()))
            {
                if (this.CanUserRunEvent(user, ConstellationClientWrapper.ChannelResubscribedEvent.ToString()))
                {
                    this.LogUserRunEvent(user, ConstellationClientWrapper.ChannelResubscribedEvent.ToString());

                    foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values)
                    {
                        user.Data.AddCurrencyAmount(currency, currency.OnSubscribeBonus);
                    }

                    int resubMonths = 0;
                    if (e.payload.TryGetValue("totalMonths", out JToken resubMonthsToken))
                    {
                        resubMonths = (int)resubMonthsToken;
                    }

                    if (this.OnResubscribedOccurred != null)
                    {
                        this.OnResubscribedOccurred(this, new Tuple <UserViewModel, int>(user, resubMonths));
                    }

                    await this.RunEventCommand(this.FindMatchingEventCommand(ConstellationClientWrapper.ChannelResubscribedEvent.ToString()), user);
                }
            }

            if (this.OnEventOccurred != null)
            {
                this.OnEventOccurred(this, e);
            }
        }
コード例 #6
0
        private async void ConstellationClient_OnSubscribedEventOccurred(object sender, ConstellationLiveEventModel e)
        {
            ChannelModel  channel = null;
            UserViewModel user    = null;

            JToken userToken;

            if (e.payload.TryGetValue("user", out userToken))
            {
                user = new UserViewModel(userToken.ToObject <UserModel>());

                JToken subscribeStartToken;
                if (e.payload.TryGetValue("since", out subscribeStartToken))
                {
                    user.SubscribeDate = subscribeStartToken.ToObject <DateTimeOffset>();
                }
            }
            else if (e.payload.TryGetValue("hoster", out userToken))
            {
                channel = userToken.ToObject <ChannelModel>();
                user    = new UserViewModel(channel.id, channel.token);
            }

            if (user != null)
            {
                UserDataViewModel userData = ChannelSession.Settings.UserData.GetValueIfExists(user.ID, new UserDataViewModel(user));

                if (e.channel.Equals(ConstellationClientWrapper.ChannelFollowEvent.ToString()))
                {
                    foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values)
                    {
                        userData.SetCurrencyAmount(currency, currency.OnFollowBonus);
                    }
                }
                else if (e.channel.Equals(ConstellationClientWrapper.ChannelHostedEvent.ToString()))
                {
                    foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values)
                    {
                        userData.SetCurrencyAmount(currency, currency.OnHostBonus);
                    }
                }
                else if (e.channel.Equals(ConstellationClientWrapper.ChannelSubscribedEvent.ToString()) || e.channel.Equals(ConstellationClientWrapper.ChannelResubscribedEvent.ToString()) ||
                         e.channel.Equals(ConstellationClientWrapper.ChannelResubscribedSharedEvent.ToString()))
                {
                    foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values)
                    {
                        userData.SetCurrencyAmount(currency, currency.OnSubscribeBonus);
                    }
                }

                if (e.channel.Equals(ConstellationClientWrapper.ChannelSubscribedEvent.ToString()))
                {
                    user.SubscribeDate = DateTimeOffset.Now;
                }
            }

            if (e.channel.Equals(ConstellationClientWrapper.ChannelUpdateEvent.ToString()))
            {
                IDictionary <string, JToken> payloadValues = e.payload;
                if (payloadValues.ContainsKey("online") && (bool)payloadValues["online"])
                {
                    UptimeChatCommand.SetUptime(DateTimeOffset.Now);
                }
            }
            else
            {
                foreach (EventCommand command in ChannelSession.Settings.EventCommands)
                {
                    EventCommand foundCommand = null;

                    if (command.MatchesEvent(e))
                    {
                        foundCommand = command;
                    }

                    if (command.EventType == ConstellationEventTypeEnum.channel__id__subscribed && e.channel.Equals(ConstellationClientWrapper.ChannelResubscribeSharedEvent.ToString()))
                    {
                        foundCommand = command;
                    }

                    if (foundCommand != null)
                    {
                        if (command.EventType == ConstellationEventTypeEnum.channel__id__hosted && channel != null)
                        {
                            foundCommand.AddSpecialIdentifier("hostviewercount", channel.viewersCurrent.ToString());
                        }

                        if (user != null)
                        {
                            await foundCommand.Perform(user);
                        }
                        else
                        {
                            await foundCommand.Perform();
                        }

                        return;
                    }
                }
            }

            if (this.OnEventOccurred != null)
            {
                this.OnEventOccurred(this, e);
            }
        }