Esempio n. 1
0
        protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                using (HttpResponseMessage response = await httpClient.GetAsync(await this.ReplaceStringWithSpecialModifiers(this.Url, user, arguments, encode: true)))
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string webRequestResult = await response.Content.ReadAsStringAsync();

                        if (!string.IsNullOrEmpty(webRequestResult))
                        {
                            if (this.ResponseAction == WebRequestResponseActionTypeEnum.Chat)
                            {
                                if (ChannelSession.Chat != null)
                                {
                                    await ChannelSession.Chat.SendMessage(await this.ReplaceSpecialIdentifiers(this.ResponseChatText, user, arguments, webRequestResult));
                                }
                            }
                            else if (this.ResponseAction == WebRequestResponseActionTypeEnum.Command)
                            {
                                CommandBase command = ChannelSession.AllCommands.FirstOrDefault(c => c.ID.Equals(this.ResponseCommandID));

#pragma warning disable CS0612 // Type or member is obsolete
                                if (command == null && !string.IsNullOrEmpty(this.ResponseCommandName))
                                {
                                    command = ChannelSession.Settings.ChatCommands.FirstOrDefault(c => c.Name.Equals(this.ResponseCommandName));
                                    if (command != null)
                                    {
                                        this.ResponseCommandID = command.ID;
                                    }
                                }
                                this.ResponseCommandName = null;
#pragma warning restore CS0612 // Type or member is obsolete

                                if (command != null)
                                {
                                    string argumentsText    = (this.ResponseCommandArgumentsText != null) ? this.ResponseCommandArgumentsText : string.Empty;
                                    string commandArguments = await this.ReplaceSpecialIdentifiers(argumentsText, user, arguments, webRequestResult);

                                    command.AddSpecialIdentifiers(this.GetAdditiveSpecialIdentifiers());
                                    await command.Perform(user, commandArguments.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
                                }
                            }
                            else if (this.ResponseAction == WebRequestResponseActionTypeEnum.SpecialIdentifier)
                            {
                                string replacementText = await this.ReplaceStringWithSpecialModifiers(webRequestResult, user, arguments);

                                SpecialIdentifierStringBuilder.AddCustomSpecialIdentifier(this.SpecialIdentifierName, replacementText);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        protected override async Task PerformInternal(UserViewModel user, IEnumerable<string> arguments)
        {
            string v1 = await this.ReplaceStringWithSpecialModifiers(this.Value1, user, arguments);
            string v2 = await this.ReplaceStringWithSpecialModifiers(this.Value2, user, arguments);

            int compareResult = 0;
            if (double.TryParse(v1, out double v1num) && double.TryParse(v2, out double v2num))
            {
                if (v1num < v2num)
                {
                    compareResult = -1;
                }
                else if (v1num > v2num)
                {
                    compareResult = 1;
                }
            }
            else
            {
                compareResult = string.Compare(v1, v2, this.IgnoreCase);
            }

            bool result = false;
            if (compareResult == 0 && (this.ComparisionType == ConditionalComparisionTypeEnum.Equals || this.ComparisionType == ConditionalComparisionTypeEnum.GreaterThanOrEqual ||
                this.ComparisionType == ConditionalComparisionTypeEnum.LessThanOrEqual))
            {
                result = true;
            }
            else if (compareResult < 0 && (this.ComparisionType == ConditionalComparisionTypeEnum.NotEquals || this.ComparisionType == ConditionalComparisionTypeEnum.LessThan ||
                this.ComparisionType == ConditionalComparisionTypeEnum.LessThanOrEqual))
            {
                result = true;
            }
            if (compareResult > 0 && (this.ComparisionType == ConditionalComparisionTypeEnum.NotEquals || this.ComparisionType == ConditionalComparisionTypeEnum.GreaterThan ||
                this.ComparisionType == ConditionalComparisionTypeEnum.GreaterThan))
            {
                result = true;
            }

            if (result)
            {
                CommandBase command = this.GetCommand();
                if (command != null)
                {
                    command.AddSpecialIdentifiers(this.GetAdditiveSpecialIdentifiers());
                    await command.Perform(user, arguments);
                }
            }
        }
Esempio n. 3
0
        protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments)
        {
            if (ChannelSession.Services.TranslationService != null)
            {
                string text = await this.ReplaceStringWithSpecialModifiers(this.Text, user, arguments);

                string translationResult = await ChannelSession.Services.TranslationService.Translate(this.Culture, text, this.AllowProfanity);

                if (string.IsNullOrEmpty(translationResult))
                {
                    translationResult = this.Text;
                }

                if (!string.IsNullOrEmpty(translationResult))
                {
                    if (this.ResponseAction == TranslationResponseActionTypeEnum.Chat)
                    {
                        if (ChannelSession.Chat != null)
                        {
                            await ChannelSession.Chat.SendMessage(await this.ReplaceSpecialIdentifiers(this.ResponseChatText, user, arguments, translationResult));
                        }
                    }
                    else if (this.ResponseAction == TranslationResponseActionTypeEnum.Command)
                    {
                        CommandBase command = ChannelSession.AllCommands.FirstOrDefault(c => c.ID.Equals(this.ResponseCommandID));
                        if (command != null)
                        {
                            string argumentsText    = (this.ResponseCommandArgumentsText != null) ? this.ResponseCommandArgumentsText : string.Empty;
                            string commandArguments = await this.ReplaceSpecialIdentifiers(this.ResponseChatText, user, arguments, translationResult);

                            command.AddSpecialIdentifiers(this.GetAdditiveSpecialIdentifiers());
                            await command.Perform(user, commandArguments.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
                        }
                    }
                    else if (this.ResponseAction == TranslationResponseActionTypeEnum.SpecialIdentifier)
                    {
                        string replacementText = await this.ReplaceStringWithSpecialModifiers(translationResult, user, arguments);

                        SpecialIdentifierStringBuilder.AddCustomSpecialIdentifier(this.SpecialIdentifierName, replacementText);
                    }
                }
            }
        }
Esempio n. 4
0
        protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                using (HttpResponseMessage response = await httpClient.GetAsync(await this.ReplaceStringWithSpecialModifiers(this.Url, user, arguments, encode: true)))
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        string webRequestResult = await response.Content.ReadAsStringAsync();

                        if (!string.IsNullOrEmpty(webRequestResult))
                        {
                            if (this.ResponseAction == WebRequestResponseActionTypeEnum.Chat)
                            {
                                if (ChannelSession.Chat != null)
                                {
                                    await ChannelSession.Chat.SendMessage(await this.ReplaceSpecialIdentifiers(this.ResponseChatText, user, arguments, webRequestResult));
                                }
                            }
                            else if (this.ResponseAction == WebRequestResponseActionTypeEnum.Command)
                            {
                                CommandBase command = ChannelSession.AllCommands.FirstOrDefault(c => c.ID.Equals(this.ResponseCommandID));

#pragma warning disable CS0612 // Type or member is obsolete
                                if (command == null && !string.IsNullOrEmpty(this.ResponseCommandName))
                                {
                                    command = ChannelSession.Settings.ChatCommands.FirstOrDefault(c => c.Name.Equals(this.ResponseCommandName));
                                    if (command != null)
                                    {
                                        this.ResponseCommandID = command.ID;
                                    }
                                }
                                this.ResponseCommandName = null;
#pragma warning restore CS0612 // Type or member is obsolete

                                if (command != null)
                                {
                                    string argumentsText    = (this.ResponseCommandArgumentsText != null) ? this.ResponseCommandArgumentsText : string.Empty;
                                    string commandArguments = await this.ReplaceSpecialIdentifiers(argumentsText, user, arguments, webRequestResult);

                                    command.AddSpecialIdentifiers(this.GetAdditiveSpecialIdentifiers());
                                    await command.Perform(user, commandArguments.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
                                }
                            }
                            else if (this.ResponseAction == WebRequestResponseActionTypeEnum.SpecialIdentifier)
                            {
                                string replacementText = await this.ReplaceStringWithSpecialModifiers(webRequestResult, user, arguments);

                                SpecialIdentifierStringBuilder.AddCustomSpecialIdentifier(this.SpecialIdentifierName, replacementText);
                            }
                            else if (this.ResponseAction == WebRequestResponseActionTypeEnum.JSONToSpecialIdentifiers)
                            {
                                try
                                {
                                    JObject jobj = JObject.Parse(webRequestResult);
                                    if (this.JSONToSpecialIdentifiers != null)
                                    {
                                        foreach (var kvp in this.JSONToSpecialIdentifiers)
                                        {
                                            string[] splits = kvp.Key.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
                                            if (splits.Count() > 0)
                                            {
                                                JToken currentToken = jobj;
                                                for (int i = 0; i < splits.Count(); i++)
                                                {
                                                    if (currentToken[splits[i]] == null)
                                                    {
                                                        currentToken = null;
                                                        break;
                                                    }
                                                    currentToken = currentToken[splits[i]];
                                                }

                                                if (currentToken != null)
                                                {
                                                    string replacementText = await this.ReplaceStringWithSpecialModifiers(currentToken.ToString(), user, arguments);

                                                    SpecialIdentifierStringBuilder.AddCustomSpecialIdentifier(kvp.Value, replacementText);
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MixItUp.Base.Util.Logger.Log(ex);
                                }
                            }
                        }
                    }
                }
            }
        }