예제 #1
0
        public override string ToString()
        {
            if (!string.IsNullOrEmpty(ChannelSession.Settings.QuotesFormat))
            {
                SpecialIdentifierStringBuilder str = new SpecialIdentifierStringBuilder(ChannelSession.Settings.QuotesFormat);
                str.ReplaceSpecialIdentifier(UserQuoteModel.QuoteNumberSpecialIdentifier, this.ID.ToString());
                str.ReplaceSpecialIdentifier(UserQuoteModel.QuoteTextSpecialIdentifier, this.Quote);
                str.ReplaceSpecialIdentifier(UserQuoteModel.QuoteGameSpecialIdentifier, this.GameName);
                str.ReplaceSpecialIdentifier(UserQuoteModel.QuoteDateTimeSpecialIdentifier, this.DateTime.ToString("d"));
                return(str.ToString());
            }
            else
            {
                StringBuilder result = new StringBuilder();

                result.Append("Quote #" + this.ID + ": ");
                result.Append("\"" + this.Quote + "\"");

                if (!string.IsNullOrEmpty(this.GameName))
                {
                    result.Append(string.Format(" [{0}]", this.GameName));
                }

                if (this.DateTime > DateTimeOffset.MinValue.AddYears(2))
                {
                    result.Append(string.Format(" [{0}]", this.DateTime.ToString("d")));
                }

                return(result.ToString());
            }
        }
예제 #2
0
        private async Task <string> ReplaceSpecialIdentifiers(string text, UserViewModel user, IEnumerable <string> arguments, string webRequestResult)
        {
            SpecialIdentifierStringBuilder siString = new SpecialIdentifierStringBuilder(this.ResponseChatText);
            await siString.ReplaceCommonSpecialModifiers(user, arguments);

            siString.ReplaceSpecialIdentifier(WebRequestAction.ResponseSpecialIdentifier, webRequestResult);
            return(siString.ToString());
        }
예제 #3
0
 protected async Task<string> ReplaceStringWithSpecialModifiers(string str, UserViewModel user, IEnumerable<string> arguments)
 {
     SpecialIdentifierStringBuilder siString = new SpecialIdentifierStringBuilder(str);
     await siString.ReplaceCommonSpecialModifiers(user, arguments);
     foreach (var kvp in this.AdditiveSpecialIdentifiers)
     {
         siString.ReplaceSpecialIdentifier(kvp.Key, kvp.Value);
     }
     return siString.ToString();
 }
예제 #4
0
        protected async Task <string> ReplaceStringWithSpecialModifiers(string str, UserViewModel user, IEnumerable <string> arguments, bool encode = false)
        {
            SpecialIdentifierStringBuilder siString = new SpecialIdentifierStringBuilder(str, this.randomUserSpecialIdentifierGroup, encode);
            await siString.ReplaceCommonSpecialModifiers(user, arguments);

            foreach (var kvp in this.additiveSpecialIdentifiers)
            {
                siString.ReplaceSpecialIdentifier(kvp.Key, kvp.Value);
            }
            return(siString.ToString());
        }
예제 #5
0
        protected async Task <string> ReplaceStringWithSpecialModifiers(string str, CommandParametersModel parameters, bool encode = false)
        {
            SpecialIdentifierStringBuilder siString = new SpecialIdentifierStringBuilder(str, encode);

            foreach (var kvp in this.extraSpecialIdentifiers)
            {
                siString.ReplaceSpecialIdentifier(kvp.Key, kvp.Value);
            }
            await siString.ReplaceCommonSpecialModifiers(parameters);

            return(siString.ToString());
        }
예제 #6
0
        protected async Task <string> ReplaceStringWithSpecialModifiers(string str, UserViewModel user, IEnumerable <string> arguments, Dictionary <string, string> extraSpecialIdentifiers)
        {
            SpecialIdentifierStringBuilder siString = new SpecialIdentifierStringBuilder(str, encode: false);

            if (extraSpecialIdentifiers != null)
            {
                foreach (var kvp in extraSpecialIdentifiers)
                {
                    siString.ReplaceSpecialIdentifier(kvp.Key, kvp.Value);
                }
            }
            await siString.ReplaceCommonSpecialModifiers(user, arguments);

            return(siString.ToString());
        }
예제 #7
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)))
                {
                    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)
                            {
                                ChatCommand command = ChannelSession.Settings.ChatCommands.FirstOrDefault(c => c.Name.Equals(this.ResponseCommandName));
                                if (command != null)
                                {
                                    string argumentsText = (this.ResponseCommandArgumentsText != null) ? this.ResponseCommandArgumentsText : string.Empty;
                                    SpecialIdentifierStringBuilder siString = new SpecialIdentifierStringBuilder(argumentsText);
                                    siString.ReplaceSpecialIdentifier(WebRequestAction.ResponseSpecialIdentifier, webRequestResult);
                                    await command.Perform(user, siString.ToString().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
                                }
                            }
                            else if (this.ResponseAction == WebRequestResponseActionTypeEnum.SpecialIdentifier)
                            {
                                string replacementText = await this.ReplaceStringWithSpecialModifiers(webRequestResult, user, arguments);

                                SpecialIdentifierStringBuilder.AddCustomSpecialIdentifier(this.SpecialIdentifierName, replacementText);
                            }
                        }
                    }
                }
            }
        }