Ejemplo n.º 1
0
        public static string DownloadString(string url, WebRequestAction webRequestAction = null, bool forceSsl3 = false)
        {
            string result = null;

            PerformWebClientAction(new WebClientAction((client) => { result = client.DownloadString(url); }), webRequestAction, forceSsl3);
            return(result);
        }
        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;
        }
Ejemplo n.º 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) && 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);
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
        public static void PerformWebClientAction(WebClientAction webClientAction, WebRequestAction webRequestAction = null, bool forceSsl3 = false)
        {
            if (!forceSsl3)
            {
                try
                {
                    using (ExtendedWebClient client = new ExtendedWebClient(webRequestAction))
                    {
                        webClientAction(client);
                    }
                }
                catch (WebException ex)
                {
                    log.Error(ex.GetType().Name + ": " + ex.Message + " (" + ex.Status + ") -> Retry with SSL3");
                }
            }

            // now try using ssl3:
            // http://poweredbydotnet.blogspot.de/2012/03/solving-received-unexpected-eof-or-0.html
            SecurityProtocolType oldType = ServicePointManager.SecurityProtocol;

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            try
            {
                using (ExtendedWebClient client = new ExtendedWebClient(webRequestAction))
                {
                    webClientAction(client);
                    ServicePointManager.SecurityProtocol = oldType;
                }
            }
            catch
            {
                ServicePointManager.SecurityProtocol = oldType;
                throw;
            }
        }
Ejemplo n.º 6
0
 public WebRequestActionControl(ActionContainerControl containerControl, WebRequestAction action) : this(containerControl) { this.action = action; }
Ejemplo n.º 7
0
 public static void DownloadFile(string url, string file, WebRequestAction webRequestAction = null, bool forceSsl3 = false)
 {
     PerformWebClientAction(new WebClientAction((client) => { client.DownloadFile(url, file); }), webRequestAction, forceSsl3);
 }
Ejemplo n.º 8
0
 public ExtendedWebClient(WebRequestAction action)
 {
     this.action = action;
 }
Ejemplo n.º 9
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));
        }
 public WebRequestActionControl(WebRequestAction action) : this()
 {
     this.action = action;
 }
Ejemplo n.º 11
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);
        }