Exemplo n.º 1
0
 public async Task RunEventCommand(EventCommand command, UserViewModel user)
 {
     if (command != null)
     {
         if (user != null)
         {
             await command.Perform(user);
         }
         else
         {
             await command.Perform();
         }
     }
 }
 public async Task RunEventCommand(EventCommand command, UserViewModel user, IEnumerable <string> arguments = null, Dictionary <string, string> extraSpecialIdentifiers = null)
 {
     if (command != null)
     {
         if (user != null)
         {
             await command.Perform(user, arguments : arguments, extraSpecialIdentifiers : extraSpecialIdentifiers);
         }
         else
         {
             await command.Perform(await ChannelSession.GetCurrentUser(), arguments : arguments, extraSpecialIdentifiers : extraSpecialIdentifiers);
         }
     }
 }
        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);
            }
        }
Exemplo n.º 4
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));
                }

                Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>();
                specialIdentifiers["subscribemonths"] = subscribeEvent.SubscribeMonths.ToString();
                specialIdentifiers["subscribeamount"] = subscribeEvent.Amount;
                if (tier != null)
                {
                    specialIdentifiers["subscribetier"] = tier.Title;
                }

                await command.Perform(user, arguments : null, extraSpecialIdentifiers : specialIdentifiers);
            }
        }
Exemplo n.º 5
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);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private async Task BackgroundDonationCheck()
        {
            HashSet <ulong> existingRetweets = new HashSet <ulong>();

            while (!this.cancellationTokenSource.Token.IsCancellationRequested)
            {
                try
                {
                    EventCommand command = ChannelSession.Settings.EventCommands.FirstOrDefault(c => c.OtherEventType.Equals(OtherEventTypeEnum.TwitterStreamTweetRetweet));
                    if (command != null)
                    {
                        IEnumerable <Tweet> tweets = await this.GetLatestTweets();

                        if (tweets.Count() > 0)
                        {
                            Tweet streamTweet = tweets.FirstOrDefault(t => t.IsStreamTweet);
                            if (streamTweet != null)
                            {
                                IEnumerable <Tweet> retweets = await this.GetRetweets(streamTweet);

                                if (retweets != null)
                                {
                                    foreach (Tweet retweet in retweets)
                                    {
                                        if (!existingRetweets.Contains(retweet.ID))
                                        {
                                            existingRetweets.Add(retweet.ID);

                                            IEnumerable <UserViewModel> users = await ChannelSession.ActiveUsers.GetAllUsers();

                                            UserViewModel user = users.FirstOrDefault(u => u.TwitterURL != null && u.TwitterURL.Equals(string.Format("https://twitter.com/{0}", retweet.UserName)));
                                            if (user == null)
                                            {
                                                UserModel userModel = await ChannelSession.Connection.GetUser(retweet.UserName);

                                                if (userModel != null)
                                                {
                                                    user = new UserViewModel(userModel);
                                                }
                                                else
                                                {
                                                    user = new UserViewModel(0, retweet.UserName);
                                                }
                                            }

                                            await command.Perform(user);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

                await Task.Delay(60000);
            }
        }
Exemplo n.º 7
0
        private async Task BackgroundDonationCheck()
        {
            Dictionary <string, ExtraLifeDonation> donationsReceived = new Dictionary <string, ExtraLifeDonation>();

            IEnumerable <ExtraLifeDonation> donations = (this.includeTeamDonations) ? await this.GetTeamDonations() : await this.GetParticipantDonations();

            foreach (ExtraLifeDonation donation in donations)
            {
                if (!string.IsNullOrEmpty(donation.donorID))
                {
                    donationsReceived[donation.donorID] = donation;
                }
            }

            while (!this.cancellationTokenSource.Token.IsCancellationRequested)
            {
                try
                {
                    donations = (this.includeTeamDonations) ? await this.GetTeamDonations() : await this.GetParticipantDonations();

                    foreach (ExtraLifeDonation elDonation in donations)
                    {
                        if (!string.IsNullOrEmpty(elDonation.donorID) && !donationsReceived.ContainsKey(elDonation.donorID))
                        {
                            donationsReceived[elDonation.donorID] = elDonation;

                            UserDonationModel donation = elDonation.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.ExtraLifeDonation));
                            if (command != null)
                            {
                                await command.Perform(user, arguments : null, extraSpecialIdentifiers : donation.GetSpecialIdentifiers());
                            }
                        }
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

                await Task.Delay(20000);
            }
        }
Exemplo n.º 8
0
        private async Task ProcessPurchase(JObject jobj)
        {
            var purchase = jobj["data"].ToObject <StreamlootsPurchaseModel>();

            if (purchase != null)
            {
                UserViewModel user   = new UserViewModel(0, purchase.data.Username);
                UserViewModel giftee = (string.IsNullOrEmpty(purchase.data.Giftee)) ? null : new UserViewModel(0, purchase.data.Giftee);

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

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

                if (giftee != null)
                {
                    UserModel gifteeModel = await ChannelSession.Connection.GetUser(giftee.UserName);

                    if (gifteeModel != null)
                    {
                        giftee = new UserViewModel(gifteeModel);
                    }
                }

                EventCommand         command   = null;
                IEnumerable <string> arguments = null;
                if (giftee == null)
                {
                    command = ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.StreamlootsPackPurchased));
                }
                else
                {
                    command   = ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.StreamlootsPackGifted));
                    arguments = new List <string>()
                    {
                        giftee.UserName
                    };
                }

                if (command != null)
                {
                    Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>();
                    specialIdentifiers.Add("streamlootspurchasequantity", purchase.data.Quantity.ToString());

                    await command.Perform(user, arguments, extraSpecialIdentifiers : specialIdentifiers);
                }
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        private async Task ProcessCardRedemption(JObject jobj)
        {
            string cardData           = string.Empty;
            StreamlootsCardModel card = jobj["data"].ToObject <StreamlootsCardModel>();

            if (card != null)
            {
                UserViewModel user = new UserViewModel(0, card.data.Username);

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

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

                EventCommand command = ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.StreamlootsCardRedeemed));
                if (command != null)
                {
                    Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>();
                    specialIdentifiers.Add("streamlootscardname", card.data.cardName);
                    specialIdentifiers.Add("streamlootscardimage", card.imageUrl);
                    specialIdentifiers.Add("streamlootscardhasvideo", (!string.IsNullOrEmpty(card.videoUrl)).ToString());
                    specialIdentifiers.Add("streamlootscardvideo", card.videoUrl);
                    specialIdentifiers.Add("streamlootscardsound", card.soundUrl);

                    string message = card.data.Message;
                    if (string.IsNullOrEmpty(message))
                    {
                        message = card.data.LongMessage;
                    }
                    specialIdentifiers.Add("streamlootsmessage", message);

                    await command.Perform(user, arguments : null, extraSpecialIdentifiers : specialIdentifiers);
                }
            }
        }
Exemplo n.º 11
0
        public async Task PerformEvent(EventTrigger trigger)
        {
            if (this.CanPerformEvent(trigger))
            {
                UserViewModel user = trigger.User;
                if (user == null)
                {
                    user = ChannelSession.GetCurrentUser();
                }

                if (this.userEventTracking.ContainsKey(trigger.Type))
                {
                    this.userEventTracking[trigger.Type].Add(user.ID);
                }

                EventCommand command = this.GetEventCommand(trigger.Type);
                if (command != null)
                {
                    Logger.Log(LogLevel.Debug, $"Performing event trigger: {trigger.Type}");

                    await command.Perform(user, platform : trigger.Platform, arguments : trigger.Arguments, extraSpecialIdentifiers : trigger.SpecialIdentifiers);
                }
            }
        }
Exemplo n.º 12
0
        private async Task BackgroundDonationCheck()
        {
            try
            {
                this.members = new List <PatreonCampaignMember>(await this.GetCampaignMembers());
                foreach (PatreonCampaignMember member in this.members)
                {
                    this.currentMembersAndTiers[member.UserID] = member.TierID;
                }
            }
            catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

            while (!this.cancellationTokenSource.Token.IsCancellationRequested)
            {
                await Task.Delay(60000);

                try
                {
                    IEnumerable <PatreonCampaignMember> pledges = await this.GetCampaignMembers();

                    if (pledges.Count() > 0)
                    {
                        this.members = pledges.ToList();
                        foreach (PatreonCampaignMember member in this.members)
                        {
                            if (!this.currentMembersAndTiers.ContainsKey(member.UserID) || !this.currentMembersAndTiers[member.UserID].Equals(member.TierID))
                            {
                                PatreonTier tier = this.Campaign.GetTier(member.TierID);
                                if (tier != null)
                                {
                                    UserViewModel user = new UserViewModel(0, member.User.LookupName);

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

                                    if (userModel != null)
                                    {
                                        user = await ChannelSession.ActiveUsers.GetUserByID(userModel.id);

                                        if (user == null)
                                        {
                                            user = new UserViewModel(userModel);
                                        }
                                        user.Data.PatreonUserID = member.UserID;
                                        await user.RefreshDetails(force : true);
                                    }

                                    EventCommand command = ChannelSession.Constellation.FindMatchingEventCommand(EnumHelper.GetEnumName(OtherEventTypeEnum.PatreonSubscribed));
                                    if (command != null)
                                    {
                                        Dictionary <string, string> extraSpecialIdentifiers = new Dictionary <string, string>();
                                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierNameSpecialIdentifier]   = tier.Title;
                                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierAmountSpecialIdentifier] = tier.Amount.ToString();
                                        extraSpecialIdentifiers[SpecialIdentifierStringBuilder.PatreonTierImageSpecialIdentifier]  = tier.ImageUrl;
                                        await command.Perform(user, arguments : null, extraSpecialIdentifiers : extraSpecialIdentifiers);
                                    }
                                }
                            }
                            this.currentMembersAndTiers[member.UserID] = member.TierID;
                        }
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }
            }
        }
Exemplo n.º 13
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);
            }
        }
Exemplo n.º 14
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);
            }
        }