Beispiel #1
0
        private void PubSub_OnRewardRedeemed(object sender, OnRewardRedeemedArgs e)
        {
            Console.WriteLine(e.RewardTitle.Trim() + " was redeemed!");

            bool useKeywords = !String.IsNullOrEmpty(e.Message);

            Setting settings = repository.LoadSettings();

            if (String.IsNullOrEmpty(settings.Application))
            {
                Console.WriteLine("is there any point?");
                return;
            }

            List <Trigger> triggers = repository.GetTriggers().Where(trigger => !String.IsNullOrEmpty(trigger.RewardName)).ToList <Trigger>();

            foreach (Trigger trigger in triggers)
            {
                if (trigger.RewardName != e.RewardTitle.Trim())
                {
                    continue;
                }

                if (useKeywords)
                {
                    if (!PassesKeywordCheck(trigger.Keywords, e.Message))
                    {
                        continue;
                    }
                }

                Console.WriteLine("matched!!");
                SendKeystroke.Send(settings.Application, trigger.CharAnimTriggerKeyValue);

                DateTime triggeredAt = DateTime.Now;

                repository.UpdateTriggerUsage(trigger.Name, triggeredAt);

                BotTriggeredArgs args = new BotTriggeredArgs {
                    TriggeredAt = triggeredAt
                };
                BotTriggered?.Invoke(this, args);

                if (settings.LoggingEnabled)
                {
                    Logger.Write($"{trigger.Name} (REWARD: {e.RewardTitle.Trim()})", e.DisplayName, e.RewardCost, e.Message);
                }

                if (useKeywords)
                {
                    break;
                }
            }
        }
Beispiel #2
0
        public void RefreshCharAnimStatus()
        {
            string processName = presenter.GetApplicationName();

            if (SendKeystroke.ApplicationRunning(processName) && !String.IsNullOrEmpty(processName))
            {
                lbl_CharAnimStatus.ForeColor = Color.ForestGreen;
                lbl_CharAnimStatus.Text = $"{processName} found!";
            }
            else
            {
                lbl_CharAnimStatus.ForeColor = Color.Red;

                if (String.IsNullOrEmpty(processName))
                    lbl_CharAnimStatus.Text = "Set application in settings!";
                else
                    lbl_CharAnimStatus.Text = $"{processName} missing :(";

            }
        }
Beispiel #3
0
        private void Client_OnMessageReceived(object sender, OnMessageReceivedArgs e)
        {
            ChatMessage message = e.ChatMessage;

            Setting settings = repository.LoadSettings();

            if (message.Channel.ToLower() != settings.Username.ToLower())
            {
                Console.WriteLine("wrong timeline, friend");
                return;
            }

            if (String.IsNullOrEmpty(settings.Application))
            {
                Console.WriteLine("is there any point?");
                return;
            }

            if (IsOnCooldown(settings.GlobalLastTriggered, settings.GlobalCooldown, settings.GlobalCooldownUnit))
            {
                Console.WriteLine("trigger on global cooldown");
                return;
            }

            List <Trigger> triggers = repository.GetTriggers().Where(trigger => String.IsNullOrEmpty(trigger.RewardName)).ToList <Trigger>();

            foreach (Trigger trigger in triggers)
            {
                if (IsOnCooldown(trigger.LastTriggered, trigger.Cooldown, trigger.CooldownUnit))
                {
                    Console.WriteLine("trigger on cooldown");
                    continue;
                }

                bool bitsRequired = (trigger.BitsEnabled && trigger.BitsAmount > 0);
                if (!bitsRequired && trigger.Keywords == "[]")
                {
                    Console.WriteLine("either bits or keywords needed");
                    continue;
                }

                if (bitsRequired && message.Bits == 0)
                {
                    Console.WriteLine("bits expected and none given");
                    continue;
                }

                bool validBits = false;
                switch (trigger.BitsCondition)
                {
                case 0:
                    validBits = message.Bits >= trigger.BitsAmount;
                    break;

                case 1:
                    validBits = message.Bits <= trigger.BitsAmount;
                    break;

                case 2:
                    validBits = message.Bits == trigger.BitsAmount;
                    break;

                case 3:
                    validBits = message.Bits >= trigger.BitsAmount && message.Bits <= trigger.BitsAmount2;
                    break;
                }

                if (!bitsRequired && trigger.Keywords != "[]")
                {
                    validBits = true;
                }

                if (!validBits)
                {
                    Console.WriteLine("not enough bits given");
                    continue;
                }
                ;

                if (message.IsBroadcaster == false && (trigger.UserLevelEveryone || (trigger.UserLevelSubs && message.IsSubscriber) || (trigger.UserLevelVips && message.IsVip) || (trigger.UserLevelMods && message.IsModerator)) == false)
                {
                    Console.WriteLine("wrong userlevel");
                    continue;
                }
                ;

                if (trigger.Keywords != "[]" && !PassesKeywordCheck(trigger.Keywords, message.Message))
                {
                    continue;
                }

                Console.WriteLine("matched!!");
                if (trigger.CharAnimTriggerKeyChar == "midi")
                {
                    if (trigger.CharAnimTriggerKeyValue > 127)
                    {
                        trigger.CharAnimTriggerKeyValue = 127;
                    }

                    Console.WriteLine("Sending midi message!!");
                    byte[] dataOn = new byte[3];
                    dataOn[0] = Convert.ToByte("10010000", 2);
                    dataOn[1] = (byte)trigger.CharAnimTriggerKeyValue;
                    dataOn[2] = 127;
                    midiController.sendCommand(dataOn);

                    byte[] dataOff = new byte[3];
                    dataOff[0] = Convert.ToByte("10000000", 2);
                    dataOff[1] = (byte)trigger.CharAnimTriggerKeyValue;
                    dataOff[2] = 0;
                    midiController.sendCommand(dataOff);
                }
                else
                {
                    SendKeystroke.Send(settings.Application, trigger.CharAnimTriggerKeyValue);
                }

                DateTime triggeredAt = DateTime.Now;

                repository.UpdateTriggerUsage(trigger.Name, triggeredAt);

                BotTriggeredArgs args = new BotTriggeredArgs {
                    TriggeredAt = triggeredAt
                };
                BotTriggered?.Invoke(this, args);

                if (settings.LoggingEnabled)
                {
                    Logger.Write(trigger.Name, message.DisplayName, message.Bits, message.Message);
                }
            }
        }