コード例 #1
0
        public void Save(RedemptionOption redemptionOption)
        {
            EnsureFolderCreated();

            var existingOptions = new List <RedemptionOption>();
            var fullPath        = FullFileName(RedemptionOptionsFileName);

            if (File.Exists(fullPath))
            {
                var RedemptionOptionsJson = File.ReadAllText(fullPath);
                existingOptions = JsonConvert.DeserializeObject <List <RedemptionOption> >(RedemptionOptionsJson);
            }

            var existingOption = existingOptions.Find(x => x.RewardName == redemptionOption.RewardName);

            if (existingOption != null)
            {
                existingOptions.Remove(existingOption);
            }

            existingOptions.Add(redemptionOption);

            var newJson = JsonConvert.SerializeObject(existingOptions);

            File.WriteAllText(fullPath, newJson);
        }
        public void UpdateRedemptionOption(RedemptionOption redemptionOption, OptionAction optionAction, string audioFileName)
        {
            redemptionOption.SetOptionAction(optionAction);
            if (audioFileName != string.Empty)
            {
                redemptionOption.SetAudioFile(audioFileName);
            }

            repository.Save(redemptionOption);
        }
コード例 #3
0
        public void Handle(PointRedemption pointRedemption, RedemptionOption redemptionOption)
        {
            if (redemptionOption == null)
            {
                return;
            }

            var audioFileReader = new AudioFileReader(redemptionOption.AudioFile);

            waveOutDevice.Init(audioFileReader);
            waveOutDevice.Play();

            // Could add a way to log that a redemption was successful
        }
        public void UpdateRedemptionOption(RedemptionOption redemptionOption, OptionAction optionAction, string command, bool requiresInput, bool executeOnRedeemer, bool respondInChat, string chatResponse)
        {
            redemptionOption.SetOptionAction(optionAction);
            if (command != string.Empty)
            {
                redemptionOption.SetChatCommand(command, requiresInput, executeOnRedeemer);
            }

            if (chatResponse != string.Empty)
            {
                redemptionOption.SetChatResponse(chatResponse, respondInChat);
            }

            repository.Save(redemptionOption);
        }
        // Message status returns:
        // UNFULFILLED
        private void TwitchClient_OnRewardRedeemed(object sender, RewardRedeemedEvent e)
        {
            // TODO make proper mitigation of this issue.
            if (!string.Equals(e.Status, "UNFULFILLED", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var pointRedemption = new PointRedemption
            {
                DisplayName = e.DisplayName,
                Message     = e.Message,
                RewardId    = e.RewardId,
                RewardName  = e.RewardTitle,
                TimeStamp   = e.TimeStamp
            };

            var redemptionOption = repository.GetRedemptionOption(e.RewardTitle);

            if (redemptionOption == null)
            {
                redemptionOption = new RedemptionOption(e.RewardTitle);
                repository.Save(redemptionOption);
                OnNewRedemptionRewardDetected?.Invoke(this, "NEW REWARD DETECTED; NEEDS SETUP!");
            }
            else if (redemptionOption.OptionAction == OptionAction.NoAction)
            {
                OnExistingRedemptionRewardNeedingSetup?.Invoke(this, "EXISTING REWARD DETECTED, STILL NEED SETUP!");
            }
            else
            {
                // REDEEM THAT FUCKERRR!
                var redeemer = redeemerOchestrator.GetRedeemer(redemptionOption.OptionAction);
                redeemer.Handle(pointRedemption, redemptionOption);
            }

            repository.Save(pointRedemption);
            OnRewardRedeemed?.Invoke(this, pointRedemption);
        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox source = (ListBox)sender;

            ActiveSelection = (RedemptionOption)source.SelectedItem;

            if (ActiveSelection != null)
            {
                textBox_redemptionName.Text = ActiveSelection.RewardName;
                comboBox1.SelectedIndex     = (int)ActiveSelection.OptionAction;

                if (ActiveSelection.OptionAction == OptionAction.AudioCommand)
                {
                    EnableAudioCommandFields();
                }
                else if (ActiveSelection.OptionAction == OptionAction.TwitchCommand)
                {
                    EnableTwitchCommandFields();
                }

                button_save.Enabled = true;
            }
        }
コード例 #7
0
        public void Handle(PointRedemption pointRedemption, RedemptionOption redemptionOption)
        {
            if (redemptionOption.ExecuteOnRedeemer)
            {
                twitchClient.SendChatMessage($"{redemptionOption.ChatCommand} {pointRedemption.DisplayName}");
            }
            else if (redemptionOption.UsesInput)
            {
                twitchClient.SendChatMessage($"{redemptionOption.ChatCommand} {pointRedemption.Message}");
            }
            else
            {
                twitchClient.SendChatMessage($"{redemptionOption.ChatCommand}");
            }

            if (redemptionOption.RespondInChat)
            {
                // Not happy about blocking thread. Hmm
                Thread.Sleep(ResponseDelay);
                twitchClient.SendChatMessage($"{redemptionOption.ChatResponse}");
            }

            // Could add a way to log that a redemption was successful
        }
 public void DeleteRewardOption(RedemptionOption redemptionOption)
 {
     repository.DeleteRedemptionOption(redemptionOption.RewardName);
 }
        public void UpdateRedemptionOption(RedemptionOption redemptionOption, OptionAction optionAction)
        {
            redemptionOption.SetOptionAction(optionAction);

            repository.Save(redemptionOption);
        }