public async Task Redeem() { RedemptionStoreProductModel product = this.Product; UserViewModel user = this.User; if (product != null && user != null) { CommandModelBase command = product.Command; if (command == null) { command = ChannelSession.Settings.GetCommand(ChannelSession.Settings.RedemptionStoreDefaultRedemptionCommandID); } if (command != null) { Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>(); specialIdentifiers[RedemptionStoreProductModel.ProductNameSpecialIdentifier] = product.Name; await command.Perform(new CommandParametersModel(user, specialIdentifiers : specialIdentifiers)); } if (this.State == RedemptionStorePurchaseRedemptionState.ManualRedeemNeeded) { this.State = RedemptionStorePurchaseRedemptionState.ManualRedeemPerformed; } else { this.State = RedemptionStorePurchaseRedemptionState.AutoRedeemed; } } GlobalEvents.RedemptionStorePurchasesUpdated(); }
private async Task RunCommand(CommandModelBase command) { if (command != null) { await command.Perform(); } }
private static async void InputService_HotKeyPressed(object sender, HotKey hotKey) { if (ChannelSession.Settings.HotKeys.ContainsKey(hotKey.ToString())) { HotKeyConfiguration hotKeyConfiguration = ChannelSession.Settings.HotKeys[hotKey.ToString()]; CommandModelBase command = ChannelSession.Settings.GetCommand(hotKeyConfiguration.CommandID); if (command != null) { await command.Perform(); } } }
private async Task RunChatCommand(ChatMessageViewModel message, CommandModelBase command, IEnumerable <string> arguments) { Logger.Log(LogLevel.Debug, string.Format("Command Found For Message - {0} - {1} - {2}", message.ID, message, command)); await command.Perform(new CommandParametersModel(message.User, message.Platform, arguments)); SettingsRequirementModel settings = command.Requirements.Settings; if (settings != null) { if (settings != null && settings.ShouldChatMessageBeDeletedWhenRun) { await this.DeleteMessage(message); } } }
protected override async Task PerformInternal(CommandParametersModel parameters) { CommandModelBase command = this.Command; if (this.ActionType == CommandActionTypeEnum.RunCommand) { if (command != null) { List <string> newArguments = new List <string>(); if (!string.IsNullOrEmpty(this.Arguments)) { string processedMessage = await this.ReplaceStringWithSpecialModifiers(this.Arguments, parameters); newArguments = processedMessage.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList(); } else { newArguments = parameters.Arguments; } CommandParametersModel copyParameters = parameters.Duplicate(); copyParameters.Arguments = newArguments; copyParameters.WaitForCommandToFinish = copyParameters.DontLockCommand = this.WaitForCommandToFinish; await command.Perform(copyParameters); } } else if (this.ActionType == CommandActionTypeEnum.DisableCommand || this.ActionType == CommandActionTypeEnum.EnableCommand) { if (command != null) { command.IsEnabled = (this.ActionType == CommandActionTypeEnum.EnableCommand) ? true : false; ChannelSession.Services.Chat.RebuildCommandTriggers(); } } else if (this.ActionType == CommandActionTypeEnum.DisableCommandGroup || this.ActionType == CommandActionTypeEnum.EnableCommandGroup) { IEnumerable <CommandModelBase> commands = this.CommandGroup; if (commands != null) { foreach (CommandModelBase cmd in commands) { cmd.IsEnabled = (this.ActionType == CommandActionTypeEnum.EnableCommandGroup) ? true : false; ChannelSession.Settings.Commands.ManualValueChanged(cmd.ID); } ChannelSession.Services.Chat.RebuildCommandTriggers(); } } }
public void AddAmount(UserDataModel user, int amount) { if (!user.IsCurrencyRankExempt && amount > 0) { int currentLevel = this.GetLevel(user); this.SetAmount(user, this.GetAmount(user) + amount); int newLevel = this.GetLevel(user); if (newLevel > currentLevel) { for (int level = (currentLevel + 1); level <= newLevel; level++) { Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>() { { this.UserLevelSpecialIdentifier, level.ToString() } }; CommandModelBase command = null; if (this.CustomLevelUpCommands.ContainsKey(level)) { command = ChannelSession.Settings.GetCommand(this.CustomLevelUpCommands[level]); } if (command == null && this.DefaultLevelUpCommand != null && this.DefaultLevelUpCommand.IsEnabled) { command = this.DefaultLevelUpCommand; } if (command != null) { UserViewModel userViewModel = ChannelSession.Services.User.GetUserByID(user.ID); if (userViewModel == null) { userViewModel = new UserViewModel(user); } #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed command.Perform(new CommandParametersModel(userViewModel, specialIdentifiers: specialIdentifiers)); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } } } } }
public Command Run(Guid commandID, [FromBody] IEnumerable <string> arguments) { CommandModelBase selectedCommand = FindCommand(commandID, out string category); if (selectedCommand == null) { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new ObjectContent <Error>(new Error { Message = $"Unable to find command: {commandID.ToString()}." }, new JsonMediaTypeFormatter(), "application/json"), ReasonPhrase = "Command ID not found" }; throw new HttpResponseException(resp); } #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed selectedCommand.Perform(new CommandParametersModel(null, arguments)); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(CommandFromCommandBase(selectedCommand, category)); }
private async void ContextMenuChatCommand_Click(object sender, RoutedEventArgs e) { if (this.ChatList.SelectedItem != null && this.ChatList.SelectedItem is ChatMessageViewModel) { ChatMessageViewModel message = (ChatMessageViewModel)this.ChatList.SelectedItem; if (message.User != null) { if (e.Source is MenuItem) { MenuItem menuItem = (MenuItem)e.Source; if (menuItem.DataContext != null && menuItem.DataContext is CommandModelBase) { CommandModelBase command = (CommandModelBase)menuItem.DataContext; await command.Perform(new CommandParametersModel(platform : message.Platform, arguments : new List <string>() { message.User.Username }) { TargetUser = message.User }); } } } } }
public async Task PerformShopCommand(UserViewModel user, IEnumerable <string> arguments = null, StreamingPlatformTypeEnum platform = StreamingPlatformTypeEnum.None) { try { if (ChannelSession.Services.Chat != null && ChannelSession.Settings.Currency.ContainsKey(this.ShopCurrencyID)) { CurrencyModel currency = ChannelSession.Settings.Currency[this.ShopCurrencyID]; if (arguments != null && arguments.Count() > 0) { string arg1 = arguments.ElementAt(0); if (arguments.Count() == 1 && arg1.Equals("list", StringComparison.InvariantCultureIgnoreCase)) { if (this.shopListCooldown > DateTimeOffset.Now) { int totalSeconds = (int)Math.Ceiling((this.shopListCooldown - DateTimeOffset.Now).TotalSeconds); await ChannelSession.Services.Chat.SendMessage(string.Format(MixItUp.Base.Resources.CooldownRequirementOnCooldown, totalSeconds)); return; } this.shopListCooldown = DateTimeOffset.Now.AddSeconds(10); List <string> items = new List <string>(); foreach (InventoryItemModel item in this.Items.Values) { if (item.HasBuyAmount || item.HasSellAmount) { items.Add(item.Name); } } await ChannelSession.Services.Chat.SendMessage("Items Available to Buy/Sell: " + string.Join(", ", items)); return; } else if (arguments.Count() >= 2 && (arg1.Equals("buy", StringComparison.InvariantCultureIgnoreCase) || arg1.Equals("sell", StringComparison.InvariantCultureIgnoreCase))) { int amount = 1; IEnumerable <string> itemArgs = arguments.Skip(1); InventoryItemModel item = this.GetItem(string.Join(" ", itemArgs)); if (item == null && itemArgs.Count() > 1) { itemArgs = itemArgs.Take(itemArgs.Count() - 1); item = this.GetItem(string.Join(" ", itemArgs)); if (item != null) { if (!int.TryParse(arguments.Last(), out amount) || amount <= 0) { await ChannelSession.Services.Chat.SendMessage("A valid amount greater than 0 must be specified"); return; } } } if (item == null) { await ChannelSession.Services.Chat.SendMessage("The item you specified does not exist"); return; } int totalcost = 0; CommandModelBase command = null; if (arg1.Equals("buy", StringComparison.InvariantCultureIgnoreCase)) { if (item.HasBuyAmount) { int itemMaxAmount = (item.HasMaxAmount) ? item.MaxAmount : this.DefaultMaxAmount; if ((this.GetAmount(user.Data, item) + amount) <= itemMaxAmount) { totalcost = item.BuyAmount * amount; if (currency.HasAmount(user.Data, totalcost)) { currency.SubtractAmount(user.Data, totalcost); this.AddAmount(user.Data, item, amount); command = this.ItemsBoughtCommand; } else { await ChannelSession.Services.Chat.SendMessage(string.Format("You do not have the required {0} {1} to purchase this item", totalcost, currency.Name)); } } else { await ChannelSession.Services.Chat.SendMessage(string.Format("You can only have {0} {1} in total", itemMaxAmount, item.Name)); } } else { await ChannelSession.Services.Chat.SendMessage("This item is not available for buying"); } } else if (arg1.Equals("sell", StringComparison.InvariantCultureIgnoreCase)) { if (item.HasSellAmount) { totalcost = item.SellAmount * amount; if (this.HasAmount(user.Data, item, amount)) { this.SubtractAmount(user.Data, item, amount); currency.AddAmount(user.Data, totalcost); command = this.ItemsSoldCommand; } else { await ChannelSession.Services.Chat.SendMessage(string.Format("You do not have the required {0} {1} to sell", amount, item.Name)); } } else { await ChannelSession.Services.Chat.SendMessage("This item is not available for selling"); } } else { await ChannelSession.Services.Chat.SendMessage("You must specify either \"buy\" & \"sell\""); } if (command != null) { Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>(); specialIdentifiers["itemtotal"] = amount.ToString(); specialIdentifiers["itemname"] = item.Name; specialIdentifiers["itemcost"] = totalcost.ToString(); specialIdentifiers["currencyname"] = currency.Name; await command.Perform(new CommandParametersModel(user, arguments : arguments, specialIdentifiers : specialIdentifiers)); } return; } else { InventoryItemModel item = this.GetItem(string.Join(" ", arguments)); if (item != null) { if (item.HasBuyAmount || item.HasSellAmount) { StringBuilder itemInfo = new StringBuilder(); itemInfo.Append(item.Name + ": "); if (item.HasBuyAmount) { itemInfo.Append(string.Format("Buy = {0} {1}", item.BuyAmount, currency.Name)); } if (item.HasBuyAmount && item.HasSellAmount) { itemInfo.Append(string.Format(", ")); } if (item.HasSellAmount) { itemInfo.Append(string.Format("Sell = {0} {1}", item.SellAmount, currency.Name)); } await ChannelSession.Services.Chat.SendMessage(itemInfo.ToString()); } else { await ChannelSession.Services.Chat.SendMessage("This item is not available to buy/sell"); } } else { await ChannelSession.Services.Chat.SendMessage("The item you specified does not exist"); } return; } } StringBuilder storeHelp = new StringBuilder(); storeHelp.Append("USAGE: " + this.ShopCommand + " list = Lists all the items available for buying/selling ** "); storeHelp.Append(this.ShopCommand + " <ITEM NAME> = Lists the buying/selling price for the item ** "); storeHelp.Append(this.ShopCommand + " buy <ITEM NAME> [AMOUNT] = Buys 1 or the amount specified of the item ** "); storeHelp.Append(this.ShopCommand + " sell <ITEM NAME> [AMOUNT] = Sells 1 or the amount specified of the item"); await ChannelSession.Services.Chat.SendMessage(storeHelp.ToString()); } } catch (Exception ex) { Logger.Log(ex); } }
public override async Task <bool> InitializeConnection(RemoteConnectionAuthenticationTokenModel connection) { if (!this.IsConnected) { if (!await this.ValidateConnection(connection)) { return(false); } this.AuthenticationToken = connection; this.ListenForRequestProfiles(async(clientID) => { try { RemoteConnectionModel clientConnection = ChannelSession.Settings.RemoteClientConnections.FirstOrDefault(c => c.ID.Equals(clientID)); if (clientConnection != null) { await this.SendProfiles(ChannelSession.Settings.RemoteProfiles.Where(p => !p.IsStreamer || clientConnection.IsStreamer)); ChannelSession.Services.Telemetry.TrackRemoteSendProfiles(connection.ID); } } catch (Exception ex) { Logger.Log(ex); } }); this.ListenForRequestBoard(async(clientID, profileID, boardID) => { try { RemoteConnectionModel clientConnection = ChannelSession.Settings.RemoteClientConnections.FirstOrDefault(c => c.ID.Equals(clientID)); if (clientConnection != null) { if (ChannelSession.Settings.RemoteProfileBoards.ContainsKey(profileID) && ChannelSession.Settings.RemoteProfileBoards[profileID].Boards.ContainsKey(boardID)) { await this.SendBoard(ChannelSession.Settings.RemoteProfileBoards[profileID].Boards[boardID]); ChannelSession.Services.Telemetry.TrackRemoteSendBoard(connection.ID, profileID, boardID); } else { await this.SendBoard(null); } } } catch (Exception ex) { Logger.Log(ex); } }); this.ListenForSendCommand(async(clientID, commandID) => { try { RemoteConnectionModel clientConnection = ChannelSession.Settings.RemoteClientConnections.FirstOrDefault(c => c.ID.Equals(clientID)); if (clientConnection != null) { CommandModelBase command = ChannelSession.Settings.GetCommand(commandID); if (command != null) { await command.Perform(); } } } catch (Exception ex) { Logger.Log(ex); } }); await this.Connect(); await this.Authenticate(connection.ID, ChannelSession.Services.Secrets.GetSecret("RemoteHostSecret"), connection.AccessToken); await Task.Delay(3000); if (this.IsConnected) { ChannelSession.Services.Telemetry.TrackRemoteAuthentication(connection.ID); } return(this.IsConnected); } return(true); }
public static async Task Purchase(UserViewModel user, IEnumerable <string> arguments) { if (arguments.Count() == 0) { List <string> items = new List <string>(); foreach (RedemptionStoreProductModel product in ChannelSession.Settings.RedemptionStoreProducts.Values.ToList()) { if (product.IsInfinite || product.CurrentAmount > 0) { items.Add(product.Name); } } await ChannelSession.Services.Chat.SendMessage("Products Available to Purchase: " + string.Join(", ", items), platform : user.Platform); } else { string name = string.Join(" ", arguments); RedemptionStoreProductModel product = ChannelSession.Settings.RedemptionStoreProducts.Values.ToList().FirstOrDefault(p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); if (product == null) { if (ChannelSession.Services.Chat != null) { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.NoRedemptionStoreProductWithThatName); } return; } if (!product.IsInfinite) { if (product.CurrentAmount <= 0) { if (ChannelSession.Services.Chat != null) { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.NoMoreRedemptionStoreProducts); } return; } ThresholdRequirementModel threshold = product.Requirements.Threshold; if (threshold != null && threshold.IsEnabled && threshold.Amount > product.CurrentAmount) { if (ChannelSession.Services.Chat != null) { await ChannelSession.Services.Chat.SendMessage(MixItUp.Base.Resources.NotEnoughRedemptionStoreProducts); } return; } } Result result = await product.Requirements.Validate(new CommandParametersModel(user, arguments)); if (result.Success) { await product.Requirements.Perform(new CommandParametersModel(user, arguments)); foreach (CommandParametersModel u in product.Requirements.GetPerformingUsers(new CommandParametersModel(user, arguments))) { if (!product.IsInfinite) { product.CurrentAmount--; } RedemptionStorePurchaseModel purchase = new RedemptionStorePurchaseModel(product, u.User); ChannelSession.Settings.RedemptionStorePurchases.Add(purchase); if (product.AutoRedeem) { await purchase.Redeem(); } else { purchase.State = RedemptionStorePurchaseRedemptionState.ManualRedeemNeeded; u.SpecialIdentifiers[RedemptionStoreProductModel.ProductNameSpecialIdentifier] = product.Name; CommandModelBase command = ChannelSession.Settings.GetCommand(ChannelSession.Settings.RedemptionStoreManualRedeemNeededCommandID); if (command != null) { await command.Perform(u); } GlobalEvents.RedemptionStorePurchasesUpdated(); } } } } }