public async Task Save() { if (this.inventory == null) { this.inventory = new InventoryModel(); ChannelSession.Settings.Inventory[this.inventory.ID] = this.inventory; } this.inventory.Name = this.Name; this.inventory.DefaultMaxAmount = this.DefaultItemMaxAmount; this.inventory.SpecialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(this.inventory.Name); this.inventory.Items = new Dictionary <Guid, InventoryItemModel>(this.Items.ToDictionary(i => i.ID, i => i)); this.inventory.ShopEnabled = this.ShopEnabled; this.inventory.ShopCommand = this.ShopCommandText; if (this.SelectedShopCurrency != null) { this.inventory.ShopCurrencyID = this.SelectedShopCurrency.ID; } this.inventory.ItemsBoughtCommand = this.ShopBuyCommand; this.inventory.ItemsSoldCommand = this.ShopSellCommand; this.inventory.TradeEnabled = this.TradeEnabled; this.inventory.TradeCommand = this.TradeCommandText; this.inventory.ItemsTradedCommand = this.TradeCommand; await ChannelSession.SaveSettings(); }
public StreamPassModel(StreamPassModel copy) : this() { this.Name = copy.Name + " COPY"; this.SpecialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(this.Name, maxLength: 15); this.Permission = copy.Permission; this.MaxLevel = copy.MaxLevel; this.PointsForLevelUp = copy.PointsForLevelUp; this.SubMultiplier = copy.SubMultiplier; this.StartDate = copy.StartDate; this.EndDate = copy.EndDate; this.ViewingRateAmount = copy.ViewingRateAmount; this.ViewingRateMinutes = copy.ViewingRateMinutes; this.MinimumActiveRate = copy.MinimumActiveRate; this.FollowBonus = copy.FollowBonus; this.HostBonus = copy.HostBonus; this.SubscribeBonus = copy.SubscribeBonus; this.DonationBonus = copy.DonationBonus; this.BitsBonus = copy.BitsBonus; this.DefaultLevelUpCommandID = this.DuplicateCommand(copy.DefaultLevelUpCommandID); this.CustomLevelUpCommands.Clear(); foreach (var kvp in copy.CustomLevelUpCommands) { this.CustomLevelUpCommands[kvp.Key] = this.DuplicateCommand(kvp.Value); } }
public override ActionBase GetAction() { string si = this.CounterNameTextBox.Text; if (!string.IsNullOrEmpty(si)) { si = si.Replace("$", ""); if (SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(si)) { if (!ChannelSession.Settings.Counters.ContainsKey(si)) { ChannelSession.Settings.Counters[si] = new CounterModel(si); } ChannelSession.Settings.Counters[si].SaveToFile = this.SaveToFileToggleButton.IsChecked.GetValueOrDefault(); ChannelSession.Settings.Counters[si].ResetOnLoad = this.ResetOnLoadToggleButton.IsChecked.GetValueOrDefault(); if (this.CounterActionTypeComboBox.SelectedIndex == 0) { return(new CounterAction(si, this.CounterAmountTextBox.Text, false)); } else if (this.CounterActionTypeComboBox.SelectedIndex == 1) { return(new CounterAction(si, this.CounterAmountTextBox.Text, true)); } else if (this.CounterActionTypeComboBox.SelectedIndex == 2) { return(new CounterAction(si)); } } } return(null); }
public override Task <Result> Validate() { if (string.IsNullOrEmpty(this.FilePath)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.FileActionMissingFilePath))); } if (this.ShowSaveToFileGrid) { if (this.ShowLineToWrite) { if (string.IsNullOrEmpty(this.LineIndex)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.FileActionMissingLineToWrite))); } } } else if (this.ShowReadFromFileGrid) { if (string.IsNullOrEmpty(this.TransferText) || !SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(this.TransferText)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.FileActionInvalidSpecialIdentifier))); } if (this.ShowLineToRead) { if (string.IsNullOrEmpty(this.LineIndex)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.FileActionMissingLineToRead))); } } } return(Task.FromResult(new Result())); }
public override Task <Result> Validate() { if (string.IsNullOrEmpty(this.RequestURL)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.WebRequestActionMissingURL))); } if (this.ShowJSONGrid) { HashSet <string> parameters = new HashSet <string>(); foreach (WebRequestActionJSONToSpecialIdentifierViewModel jsonParameter in this.JSONParameters) { if (string.IsNullOrEmpty(jsonParameter.JSONParameterName) || string.IsNullOrEmpty(jsonParameter.SpecialIdentifierName)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.WebRequestActionMissingJSONParameter))); } jsonParameter.SpecialIdentifierName = jsonParameter.SpecialIdentifierName.Replace("$", ""); if (!SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(jsonParameter.SpecialIdentifierName)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.WebRequestActionInvalidJSONSpecialIdentifier))); } if (parameters.Contains(jsonParameter.JSONParameterName)) { return(Task.FromResult(new Result(MixItUp.Base.Resources.WebRequestActionDuplicateJSONParameter))); } parameters.Add(jsonParameter.JSONParameterName); } } return(Task.FromResult(new Result())); }
protected async Task <string> ReplaceStringWithSpecialModifiers(string str, CommandParametersModel parameters) { SpecialIdentifierStringBuilder siString = new SpecialIdentifierStringBuilder(str, encode: false); await siString.ReplaceCommonSpecialModifiers(parameters); return(siString.ToString()); }
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()); } }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { string replacementText = await this.ReplaceStringWithSpecialModifiers(this.SpecialIdentifierReplacement, user, arguments); if (this.SpecialIdentifierShouldProcessMath) { try { // Process Math CalculationEngine engine = new CalculationEngine(); engine.AddFunction("random", Random); engine.AddFunction("randomrange", RandomRange); double result = engine.Calculate(replacementText); replacementText = result.ToString(); } catch (Exception ex) { // Calculation failed, log and set to 0 Logger.Log(ex, false, false); replacementText = "0"; } } if (this.MakeGloballyUsable) { SpecialIdentifierStringBuilder.AddCustomSpecialIdentifier(this.SpecialIdentifierName, replacementText); } else { this.extraSpecialIdentifiers[this.SpecialIdentifierName] = replacementText; } }
public override ActionBase GetAction() { if (!string.IsNullOrEmpty(this.FilePathTextBox.Text)) { FileActionTypeEnum fileType = EnumHelper.GetEnumValueFromString <FileActionTypeEnum>((string)this.FileActionTypeComboBox.SelectedItem); if (fileType == FileActionTypeEnum.SaveToFile || fileType == FileActionTypeEnum.AppendToFile) { string transferText = this.SaveToFileTextTextBox.Text; if (string.IsNullOrEmpty(transferText)) { transferText = string.Empty; } return(new FileAction(fileType, transferText: this.SaveToFileTextTextBox.Text, filePath: this.FilePathTextBox.Text)); } else if (fileType == FileActionTypeEnum.ReadFromFile || fileType == FileActionTypeEnum.ReadSpecificLineFromFile || fileType == FileActionTypeEnum.ReadRandomLineFromFile || fileType == FileActionTypeEnum.RemoveSpecificLineFromFile || fileType == FileActionTypeEnum.RemoveRandomLineFromFile) { if (SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(this.SpecialIdentifierNameTextBox.Text)) { FileAction action = new FileAction(fileType, transferText: this.SpecialIdentifierNameTextBox.Text, filePath: this.FilePathTextBox.Text); if (fileType == FileActionTypeEnum.ReadSpecificLineFromFile || fileType == FileActionTypeEnum.RemoveSpecificLineFromFile) { if (string.IsNullOrEmpty(this.SpecificLineTextBox.Text)) { return(null); } action.LineIndexToRead = this.SpecificLineTextBox.Text; } return(action); } } } return(null); }
private async void SendChatMessageButton_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(this.ChatMessageTextBox.Text)) { string message = this.ChatMessageTextBox.Text; if (message.Contains(SpecialIdentifierStringBuilder.SpecialIdentifierHeader)) { SpecialIdentifierStringBuilder spReplacement = new SpecialIdentifierStringBuilder(message, Guid.NewGuid()); await spReplacement.ReplaceCommonSpecialModifiers(await ChannelSession.GetCurrentUser()); message = spReplacement.ToString(); } if (messageHistory.Contains(message)) { // Remove so we can move to the end messageHistory.Remove(message); } messageHistory.Add(message); activeMessageHistory = messageHistory.Count; this.ChatMessageTextBox.Text = string.Empty; if (ChatAction.WhisperRegex.IsMatch(message)) { Match whisperRegexMatch = ChatAction.WhisperRegex.Match(message); message = message.Substring(whisperRegexMatch.Value.Length); Match usernNameMatch = ChatAction.UserNameTagRegex.Match(whisperRegexMatch.Value); string username = usernNameMatch.Value; username = username.Trim(); username = username.Replace("@", ""); await this.Window.RunAsyncOperation(async() => { ChatMessageEventModel response = await ChannelSession.Chat.WhisperWithResponse(username, message, ShouldSendAsStreamer()); if (response != null) { await this.AddMessage(ChatMessageViewModel.CreateChatMessageViewModel(response)); } }); } else if (ChatAction.ClearRegex.IsMatch(message)) { await ChannelSession.Chat.ClearMessages(); } else { await this.Window.RunAsyncOperation((Func <Task>)(async() => { await ChannelSession.Chat.SendMessage(message, ShouldSendAsStreamer()); })); } this.ChatMessageTextBox.Focus(); } }
public override ActionBase GetAction() { if (this.TranslationLanguageComboBox.SelectedIndex >= 0 && !string.IsNullOrEmpty(this.TranslationTextTextBox.Text)) { CultureInfo culture = (CultureInfo)this.TranslationLanguageComboBox.SelectedItem; TranslationResponseActionTypeEnum responseType = EnumHelper.GetEnumValueFromString <TranslationResponseActionTypeEnum>((string)this.ResponseActionComboBox.SelectedItem); if (responseType == TranslationResponseActionTypeEnum.Chat) { if (!string.IsNullOrEmpty(this.ChatResponseTextBox.Text)) { return(TranslationAction.CreateForChat(culture, this.TranslationTextTextBox.Text, this.AllowProfanityCheckBox.IsChecked.GetValueOrDefault(), this.ChatResponseTextBox.Text)); } } else if (responseType == TranslationResponseActionTypeEnum.Command) { if (this.CommandResponseComboBox.SelectedIndex >= 0) { return(TranslationAction.CreateForCommand(culture, this.TranslationTextTextBox.Text, this.AllowProfanityCheckBox.IsChecked.GetValueOrDefault(), (CommandBase)this.CommandResponseComboBox.SelectedItem, this.CommandResponseArgumentsTextBox.Text)); } } else if (responseType == TranslationResponseActionTypeEnum.SpecialIdentifier) { if (SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(this.SpecialIdentifierResponseTextBox.Text)) { return(TranslationAction.CreateForSpecialIdentifier(culture, this.TranslationTextTextBox.Text, this.AllowProfanityCheckBox.IsChecked.GetValueOrDefault(), this.SpecialIdentifierResponseTextBox.Text)); } } } return(null); }
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; }
protected override async Task PerformInternal(CommandParametersModel parameters) { string replacementText = await this.ReplaceStringWithSpecialModifiers(this.ReplacementText, parameters); replacementText = await this.ProcessStringFunction(replacementText, "removespaces", (text) => { return(Task.FromResult(text.Replace(" ", string.Empty))); }); replacementText = await this.ProcessStringFunction(replacementText, "removecommas", (text) => { return(Task.FromResult(text.Replace(",", string.Empty))); }); replacementText = await this.ProcessStringFunction(replacementText, "tolower", (text) => { return(Task.FromResult(text.ToLower())); }); replacementText = await this.ProcessStringFunction(replacementText, "toupper", (text) => { return(Task.FromResult(text.ToUpper())); }); replacementText = await this.ProcessStringFunction(replacementText, "length", (text) => { return(Task.FromResult(text.Length.ToString())); }); if (this.ShouldProcessMath) { replacementText = MathHelper.ProcessMathEquation(replacementText).ToString(); } if (this.MakeGloballyUsable) { SpecialIdentifierStringBuilder.AddGlobalSpecialIdentifier(this.SpecialIdentifierName, replacementText); } else { parameters.SpecialIdentifiers[this.SpecialIdentifierName] = replacementText; } }
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()); }
public override ActionBase GetAction() { if (SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(this.SpecialIdentifierNameTextBox.Text) && !string.IsNullOrEmpty(this.SpecialIdentifierReplacementTextBox.Text)) { return(new SpecialIdentifierAction(this.SpecialIdentifierNameTextBox.Text, this.SpecialIdentifierReplacementTextBox.Text, this.SpecialIdentifierShouldProcessMathCheckBox.IsChecked ?? false)); } return(null); }
public override ActionBase GetAction() { if (SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(this.SpecialIdentifierNameTextBox.Text) && !string.IsNullOrEmpty(this.SpecialIdentifierReplacementTextBox.Text)) { return(new SpecialIdentifierAction(this.SpecialIdentifierNameTextBox.Text, this.SpecialIdentifierReplacementTextBox.Text, this.MakeGloballyUsableCheckBox.IsChecked.GetValueOrDefault(), this.SpecialIdentifierShouldProcessMathCheckBox.IsChecked.GetValueOrDefault())); } return(null); }
public ScorpBotTimerModel(Dictionary <string, object> data) { this.Name = (string)data["Name2"]; this.Text = (string)data["Response"]; this.Text = SpecialIdentifierStringBuilder.ConvertScorpBotText(this.Text); this.Enabled = (((int)data["Enabled"]) == 1); }
public ScorpBotTimer(DbDataReader reader) { this.Name = (string)reader["Name2"]; this.Text = (string)reader["Response"]; this.Text = SpecialIdentifierStringBuilder.ConvertScorpBotText(this.Text); this.Enabled = (((int)reader["Enabled"]) == 1); }
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(); }
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); } } } } } }
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()); }
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()); }
public Task Perform(UserViewModel user, IEnumerable <string> arguments = null) { if (this.IsEnabled) { if (arguments == null) { arguments = new List <string>(); } try { if (this.StoreID != Guid.Empty) { if (!CommandBase.commandUses.ContainsKey(this.StoreID)) { CommandBase.commandUses[this.StoreID] = 0; } CommandBase.commandUses[this.StoreID]++; } } catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); } this.currentCancellationTokenSource = new CancellationTokenSource(); this.currentTaskRun = Task.Run(async() => { try { if (!this.Unlocked && !ChannelSession.Settings.UnlockAllCommands) { await this.AsyncSemaphore.WaitAsync(); } await SpecialIdentifierStringBuilder.AssignRandomUserSpecialIdentifierGroup(this.ID); foreach (ActionBase action in this.Actions) { action.AssignRandomUserSpecialIdentifierGroup(this.ID); } await this.PerformInternal(user, arguments, this.currentCancellationTokenSource.Token); } catch (TaskCanceledException) { } catch (Exception ex) { Util.Logger.Log(ex); } finally { if (!this.Unlocked && !ChannelSession.Settings.UnlockAllCommands) { this.AsyncSemaphore.Release(); } } }, this.currentCancellationTokenSource.Token); } return(Task.FromResult(0)); }
public ScorpBotCommand(string command, string text) { this.Command = command; this.Command = this.Command.ToLower(); this.Command = this.Command.Replace("!", ""); this.Text = text; this.Text = SpecialIdentifierStringBuilder.ConvertScorpBotText(this.Text); this.Permission = UserRole.User; this.Enabled = true; }
public async Task Save() { if (this.Currency == null) { this.Currency = new CurrencyModel(); ChannelSession.Settings.Currency[this.Currency.ID] = this.Currency; } this.Currency.Name = this.Name; this.Currency.IsPrimary = this.IsPrimary; this.Currency.MaxAmount = (this.MaxAmount != 0 && this.MaxAmount != int.MaxValue) ? this.MaxAmount : int.MaxValue; this.Currency.AcquireAmount = this.OnlineRateAmount; this.Currency.AcquireInterval = this.OnlineRateInterval; this.Currency.OfflineAcquireAmount = this.OfflineRateAmount; this.Currency.OfflineAcquireInterval = this.OfflineRateInterval; this.Currency.SpecialTracking = CurrencySpecialTrackingEnum.None; if (this.OnlineRate == CurrencyAcquireRateTypeEnum.Bits) { this.Currency.SpecialTracking = CurrencySpecialTrackingEnum.Bits; } this.Currency.RegularBonus = this.RegularBonus; this.Currency.SubscriberBonus = this.SubscriberBonus; this.Currency.ModeratorBonus = this.ModeratorBonus; this.Currency.OnFollowBonus = this.OnFollowBonus; this.Currency.OnHostBonus = this.OnHostBonus; this.Currency.OnSubscribeBonus = this.OnSubscribeBonus; this.Currency.MinimumActiveRate = this.MinimumActiveRate; this.Currency.ResetInterval = this.AutomaticResetRate; this.Currency.ResetStartCadence = this.AutomaticResetStartTime; this.Currency.SpecialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(this.Currency.Name); if (this.IsRank) { this.Currency.Ranks = this.Ranks.ToList(); this.Currency.RankChangedCommand = this.RankChangedCommand; this.Currency.RankDownCommand = this.RankDownCommand; } else { this.Currency.Ranks.Clear(); this.Currency.RankChangedCommand = null; this.Currency.RankDownCommand = null; } await ChannelSession.SaveSettings(); }
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()); }
private void CurrencyNameTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { if (!string.IsNullOrEmpty(this.CurrencyNameTextBox.Text)) { this.specialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(this.CurrencyNameTextBox.Text); this.UserAmountSpecialIdentifierTextBlock.Text = string.Format("$user{0}", this.specialIdentifier); this.UserRankSpecialIdentifierTextBlock.Text = string.Format("$user{0}rank", this.specialIdentifier); } else { this.specialIdentifier = null; this.UserAmountSpecialIdentifierTextBlock.Text = ""; this.UserRankSpecialIdentifierTextBlock.Text = ""; } }
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); }
public override ActionBase GetAction() { if (SpecialIdentifierStringBuilder.IsValidSpecialIdentifier(this.CounterNameTextBox.Text)) { if (this.CounterActionTypeComboBox.SelectedIndex == 0) { return(new CounterAction(this.CounterNameTextBox.Text, this.CounterAmountTextBox.Text, this.SaveToFileToggleButton.IsChecked.GetValueOrDefault(), this.ResetOnLoadToggleButton.IsChecked.GetValueOrDefault())); } else if (this.CounterActionTypeComboBox.SelectedIndex == 1) { return(new CounterAction(this.CounterNameTextBox.Text, this.SaveToFileToggleButton.IsChecked.GetValueOrDefault(), this.ResetOnLoadToggleButton.IsChecked.GetValueOrDefault())); } } return(null); }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { string replacementText = await this.ReplaceStringWithSpecialModifiers(this.SpecialIdentifierReplacement, user, arguments); if (this.SpecialIdentifierShouldProcessMath) { try { replacementText = replacementText.Replace("random(", "customrandom("); // Process Math CalculationEngine engine = new CalculationEngine(new System.Globalization.CultureInfo("en-US")); engine.AddFunction("customrandom", Random); engine.AddFunction("randomrange", RandomRange); double result = engine.Calculate(replacementText); replacementText = result.ToString(); } catch (Exception ex) { // Calculation failed, log and set to 0 Logger.Log(ex); replacementText = "0"; } } else { replacementText = await this.ProcessStringFunction(replacementText, "removespaces", (text) => { return(Task.FromResult(text.Replace(" ", string.Empty))); }); replacementText = await this.ProcessStringFunction(replacementText, "removecommas", (text) => { return(Task.FromResult(text.Replace(",", string.Empty))); }); replacementText = await this.ProcessStringFunction(replacementText, "tolower", (text) => { return(Task.FromResult(text.ToLower())); }); replacementText = await this.ProcessStringFunction(replacementText, "toupper", (text) => { return(Task.FromResult(text.ToUpper())); }); replacementText = await this.ProcessStringFunction(replacementText, "urlencode", (text) => { return(Task.FromResult(HttpUtility.UrlEncode(text))); }); } if (this.MakeGloballyUsable) { SpecialIdentifierStringBuilder.AddCustomSpecialIdentifier(this.SpecialIdentifierName, replacementText); } else { this.extraSpecialIdentifiers[this.SpecialIdentifierName] = replacementText; } }