public ScorpBotCommand(string command, string text)
            : this()
        {
            this.Command = command;
            this.Command = this.Command.ToLower();
            this.Command = this.Command.Replace("!", "");

            this.Text = SpecialIdentifierStringBuilder.ConvertScorpBotText(text);

            this.GetRegexEntries(SFXRegexHeaderPattern, (string entry) =>
            {
                this.Actions.Add(new SoundAction(entry, 100));
                return(string.Empty);
            });

            int webRequestCount = 1;

            this.GetRegexEntries(ReadAPIRegexHeaderPattern, (string entry) =>
            {
                string si = "webrequest" + webRequestCount;
                this.Actions.Add(WebRequestAction.CreateForSpecialIdentifier(entry, si));
                webRequestCount++;
                return("$" + si);
            });

            this.Actions.Add(new ChatAction(this.Text));

            this.Requirements.Role.MixerRole = MixerRoleEnum.User;

            this.Enabled = true;
        }
예제 #2
0
 public override ActionBase GetAction()
 {
     if (!string.IsNullOrEmpty(this.WebRequestURLTextBox.Text))
     {
         WebRequestResponseActionTypeEnum responseType = EnumHelper.GetEnumValueFromString <WebRequestResponseActionTypeEnum>((string)this.ResponseActionComboBox.SelectedItem);
         if (responseType == WebRequestResponseActionTypeEnum.Chat)
         {
             if (!string.IsNullOrEmpty(this.ChatResponseTextBox.Text))
             {
                 return(WebRequestAction.CreateForChat(this.WebRequestURLTextBox.Text, this.ChatResponseTextBox.Text));
             }
         }
         else if (responseType == WebRequestResponseActionTypeEnum.Command)
         {
             if (this.CommandResponseComboBox.SelectedIndex >= 0)
             {
                 return(WebRequestAction.CreateForCommand(this.WebRequestURLTextBox.Text, (CommandBase)this.CommandResponseComboBox.SelectedItem, this.CommandResponseArgumentsTextBox.Text));
             }
         }
         else if (responseType == WebRequestResponseActionTypeEnum.SpecialIdentifier)
         {
             if (!string.IsNullOrEmpty(this.SpecialIdentifierResponseTextBox.Text) && this.SpecialIdentifierResponseTextBox.Text.All(c => Char.IsLetterOrDigit(c)))
             {
                 return(WebRequestAction.CreateForSpecialIdentifier(this.WebRequestURLTextBox.Text, this.SpecialIdentifierResponseTextBox.Text));
             }
         }
         else
         {
             return(new WebRequestAction(this.WebRequestURLTextBox.Text, WebRequestResponseActionTypeEnum.None));
         }
     }
     return(null);
 }
예제 #3
0
 public override ActionBase GetAction()
 {
     if (!string.IsNullOrEmpty(this.WebRequestURLTextBox.Text))
     {
         WebRequestResponseActionTypeEnum responseType = EnumHelper.GetEnumValueFromString <WebRequestResponseActionTypeEnum>((string)this.ResponseActionComboBox.SelectedItem);
         if (responseType == WebRequestResponseActionTypeEnum.Chat)
         {
             if (!string.IsNullOrEmpty(this.ChatResponseTextBox.Text))
             {
                 return(WebRequestAction.CreateForChat(this.WebRequestURLTextBox.Text, this.ChatResponseTextBox.Text));
             }
         }
         else if (responseType == WebRequestResponseActionTypeEnum.Command)
         {
             if (this.CommandResponseComboBox.SelectedIndex >= 0)
             {
                 return(WebRequestAction.CreateForCommand(this.WebRequestURLTextBox.Text, (CommandBase)this.CommandResponseComboBox.SelectedItem, this.CommandResponseArgumentsTextBox.Text));
             }
         }
         else if (responseType == WebRequestResponseActionTypeEnum.SpecialIdentifier)
         {
             if (!string.IsNullOrEmpty(this.SpecialIdentifierResponseTextBox.Text) && SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(this.SpecialIdentifierResponseTextBox.Text))
             {
                 return(WebRequestAction.CreateForSpecialIdentifier(this.WebRequestURLTextBox.Text, this.SpecialIdentifierResponseTextBox.Text));
             }
         }
         else if (responseType == WebRequestResponseActionTypeEnum.JSONToSpecialIdentifiers)
         {
             if (this.jsonToSpecialIdentifierPairs.Count > 0)
             {
                 foreach (JSONToSpecialIdentifierPair pairs in this.jsonToSpecialIdentifierPairs)
                 {
                     if (string.IsNullOrEmpty(pairs.JSONParameterName) || !SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(pairs.SpecialIdentifierName))
                     {
                         return(null);
                     }
                 }
                 return(WebRequestAction.CreateForJSONToSpecialIdentifiers(this.WebRequestURLTextBox.Text,
                                                                           this.jsonToSpecialIdentifierPairs.ToDictionary(p => p.JSONParameterName, p => p.SpecialIdentifierName)));
             }
         }
         else
         {
             return(new WebRequestAction(this.WebRequestURLTextBox.Text, WebRequestResponseActionTypeEnum.None));
         }
     }
     return(null);
 }
예제 #4
0
        public void ProcessData(CurrencyModel currency, CurrencyModel rank)
        {
            this.Text = SpecialIdentifierStringBuilder.ConvertScorpBotText(this.Text);

            this.Text = this.GetRegexEntries(this.Text, SFXRegexHeaderPattern, (string entry) =>
            {
                this.Actions.Add(new SoundAction(entry, 100));
                return(string.Empty);
            });

            int webRequestCount = 1;

            this.Text = this.GetRegexEntries(this.Text, ReadAPIRegexHeaderPattern, (string entry) =>
            {
                string si = "webrequest" + webRequestCount;
                this.Actions.Add(WebRequestAction.CreateForSpecialIdentifier(entry, si));
                webRequestCount++;
                return("$" + si);
            });

            if (this.Text.Contains("$toppoints("))
            {
                this.Text = SpecialIdentifierStringBuilder.ReplaceParameterVariablesEntries(this.Text, "$toppoints(", "$top", rank.SpecialIdentifier);
            }

            this.Text = this.Text.Replace("$points", "$" + rank.UserAmountSpecialIdentifier);
            this.Text = this.Text.Replace("$rank", "$" + rank.UserRankNameSpecialIdentifier);

            int readCount = 1;

            this.Text = this.GetRegexEntries(this.Text, ReadFileRegexHeaderPattern, (string entry) =>
            {
                string si = "read" + readCount;

                string[] splits   = entry.Split(new char[] { ',' });
                FileAction action = new FileAction(FileActionTypeEnum.ReadSpecificLineFromFile, si, splits[0]);
                if (splits.Length > 1)
                {
                    action.FileActionType = FileActionTypeEnum.ReadSpecificLineFromFile;
                    if (splits[1].Equals("first"))
                    {
                        action.LineIndexToRead = "1";
                    }
                    else if (splits[1].Equals("random"))
                    {
                        action.FileActionType = FileActionTypeEnum.ReadRandomLineFromFile;
                    }
                    else
                    {
                        action.LineIndexToRead = splits[1];
                    }
                }
                this.Actions.Add(action);

                readCount++;
                return("$" + si);
            });

            this.Text = this.GetRegexEntries(this.Text, WriteFileRegexHeaderPattern, (string entry) =>
            {
                string[] splits = entry.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                if (splits.Length == 1)
                {
                    this.Actions.Add(new FileAction(FileActionTypeEnum.AppendToFile, string.Empty, splits[0]));
                }
                else if (splits.Length == 2)
                {
                    this.Actions.Add(new FileAction(FileActionTypeEnum.AppendToFile, splits[1], splits[0]));
                }
                else if (splits.Length > 2)
                {
                    FileAction action = new FileAction(FileActionTypeEnum.AppendToFile, splits[1], splits[0]);
                    if (bool.TryParse(splits[2], out bool overwrite) && overwrite)
                    {
                        action.FileActionType = FileActionTypeEnum.SaveToFile;
                    }
                    this.Actions.Add(action);
                }
                return(string.Empty);
            });

            this.Actions.Add(new ChatAction(this.Text));
        }
예제 #5
0
        public void ProcessData(UserCurrencyViewModel currency, UserCurrencyViewModel rank)
        {
            this.Requirements = new RequirementViewModel();

            if (this.Cooldown > 0)
            {
                this.Requirements.Cooldown = new CooldownRequirementViewModel(CooldownTypeEnum.Individual, this.Cooldown);
            }

            if (!string.IsNullOrEmpty(this.Permission))
            {
                switch (this.Permission)
                {
                case "Subscriber":
                    this.Requirements.Role = new RoleRequirementViewModel(MixerRoleEnum.Subscriber);
                    break;

                case "Moderator":
                    this.Requirements.Role = new RoleRequirementViewModel(MixerRoleEnum.Mod);
                    break;

                case "Editor":
                    this.Requirements.Role = new RoleRequirementViewModel(MixerRoleEnum.ChannelEditor);
                    break;

                case "Min_Points":
                    this.Requirements.Role = new RoleRequirementViewModel(MixerRoleEnum.User);
                    if (!string.IsNullOrEmpty(this.PermInfo) && int.TryParse(this.PermInfo, out int cost))
                    {
                        this.Requirements.Currency = new CurrencyRequirementViewModel(currency, cost);
                    }
                    break;

                case "Min_Rank":
                    this.Requirements.Role = new RoleRequirementViewModel(MixerRoleEnum.User);
                    if (!string.IsNullOrEmpty(this.PermInfo))
                    {
                        UserRankViewModel minRank = rank.Ranks.FirstOrDefault(r => r.Name.ToLower().Equals(this.PermInfo.ToLower()));
                        if (rank != null)
                        {
                            this.Requirements.Rank = new CurrencyRequirementViewModel(rank, minRank);
                        }
                    }
                    break;

                default:
                    this.Requirements.Role = new RoleRequirementViewModel(MixerRoleEnum.User);
                    break;
                }
            }

            this.Response = SpecialIdentifierStringBuilder.ConvertStreamlabsChatBotText(this.Response);

            int readCount = 1;

            this.Response = this.GetRegexEntries(this.Response, ReadLineRegexHeaderPattern, (string entry) =>
            {
                string si = "read" + readCount;
                this.Actions.Add(new FileAction(FileActionTypeEnum.ReadFromFile, si, entry));
                readCount++;
                return("$" + si);
            });

            this.Response = this.GetRegexEntries(this.Response, ReadRandomLineRegexHeaderPattern, (string entry) =>
            {
                string si = "read" + readCount;
                this.Actions.Add(new FileAction(FileActionTypeEnum.ReadRandomLineFromFile, si, entry));
                readCount++;
                return("$" + si);
            });

            this.Response = this.GetRegexEntries(this.Response, ReadRandomLineRegexHeaderPattern, (string entry) =>
            {
                string si = "read" + readCount;

                string[] splits        = entry.Split(new char[] { ',' });
                FileAction action      = new FileAction(FileActionTypeEnum.ReadSpecificLineFromFile, si, splits[0]);
                action.LineIndexToRead = splits[1];
                this.Actions.Add(action);

                readCount++;
                return("$" + si);
            });

            int webRequestCount = 1;

            this.Response = this.GetRegexEntries(this.Response, ReadAPIRegexHeaderPattern, (string entry) =>
            {
                string si = "webrequest" + webRequestCount;
                this.Actions.Add(WebRequestAction.CreateForSpecialIdentifier(entry, si));
                webRequestCount++;
                return("$" + si);
            });

            this.Response = this.GetRegexEntries(this.Response, SaveToFileRegexHeaderPattern, (string entry) =>
            {
                string[] splits        = entry.Split(new char[] { ',' });
                FileAction action      = new FileAction(FileActionTypeEnum.AppendToFile, splits[1], splits[0]);
                action.LineIndexToRead = splits[1];
                this.Actions.Add(action);
                return(string.Empty);
            });

            this.Response = this.GetRegexEntries(this.Response, OverwriteFileRegexHeaderPattern, (string entry) =>
            {
                string[] splits        = entry.Split(new char[] { ',' });
                FileAction action      = new FileAction(FileActionTypeEnum.SaveToFile, splits[1], splits[0]);
                action.LineIndexToRead = splits[1];
                this.Actions.Add(action);
                return(string.Empty);
            });

            ChatAction chat = new ChatAction(this.Response);

            if (!string.IsNullOrEmpty(this.Usage) && this.Usage.Equals("SW"))
            {
                chat.IsWhisper = true;
            }
            this.Actions.Add(chat);
        }