Example #1
0
        private async Task ProcessCardRedemption(JObject jobj)
        {
            string cardData           = string.Empty;
            StreamlootsCardModel card = jobj["data"].ToObject <StreamlootsCardModel>();

            if (card != null)
            {
                UserViewModel user = this.GetUser(card.data.Username);

                EventTrigger trigger = new EventTrigger(EventTypeEnum.StreamlootsCardRedeemed, user);
                trigger.SpecialIdentifiers["streamlootscardname"]     = card.data.cardName;
                trigger.SpecialIdentifiers["streamlootscardimage"]    = card.imageUrl;
                trigger.SpecialIdentifiers["streamlootscardhasvideo"] = (!string.IsNullOrEmpty(card.videoUrl)).ToString();
                trigger.SpecialIdentifiers["streamlootscardvideo"]    = card.videoUrl;
                trigger.SpecialIdentifiers["streamlootscardsound"]    = card.soundUrl;

                string message = card.data.Message;
                if (string.IsNullOrEmpty(message))
                {
                    message = card.data.LongMessage;
                }
                trigger.SpecialIdentifiers["streamlootsmessage"] = message;

                await ChannelSession.Services.Events.PerformEvent(trigger);
            }
        }
        private async Task ProcessCardRedemption(JObject jobj)
        {
            string cardData           = string.Empty;
            StreamlootsCardModel card = jobj["data"].ToObject <StreamlootsCardModel>();

            if (card != null && !string.IsNullOrEmpty(card.data?.cardName))
            {
                UserViewModel user = this.GetUser(card.data.Username);

                Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>();
                specialIdentifiers["streamlootscardname"]         = card.data.cardName;
                specialIdentifiers["streamlootscarddescription"]  = card.data.description;
                specialIdentifiers["streamlootscardimage"]        = card.imageUrl;
                specialIdentifiers["streamlootscardhasvideo"]     = (!string.IsNullOrEmpty(card.videoUrl)).ToString();
                specialIdentifiers["streamlootscardvideo"]        = card.videoUrl;
                specialIdentifiers["streamlootscardsound"]        = card.soundUrl;
                specialIdentifiers["streamlootscardalertmessage"] = card.message;

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

                List <string> arguments = new List <string>();
                if (!string.IsNullOrEmpty(message))
                {
                    arguments = new List <string>(message.Split(' '));
                }

                await ChannelSession.Services.Events.PerformEvent(EventTypeEnum.StreamlootsCardRedeemed, new CommandParametersModel(user, arguments, specialIdentifiers));

                StreamlootsCardCommandModel command = ChannelSession.Services.Command.StreamlootsCardCommands.FirstOrDefault(c => string.Equals(c.Name, card.data.cardName, StringComparison.CurrentCultureIgnoreCase));
                if (command != null)
                {
                    Dictionary <string, string> cardsCommandSpecialIdentifiers = new Dictionary <string, string>(specialIdentifiers);
                    await ChannelSession.Services.Command.Queue(command, new CommandParametersModel(user, platform : user.Platform, arguments : arguments, specialIdentifiers : cardsCommandSpecialIdentifiers));
                }

                await ChannelSession.Services.Alerts.AddAlert(new AlertChatMessageViewModel(user.Platform, user, string.Format("{0} Redeemed {1} Card", user.FullDisplayName, card.data.cardName), ChannelSession.Settings.AlertStreamlootsColor));
            }
        }