private MethodPacket BuildDeleteScenePacket(InteractiveConnectedSceneModel sceneToDelete, InteractiveConnectedSceneModel sceneToReplace) { Validator.ValidateVariable(sceneToDelete, "sceneToDelete"); Validator.ValidateVariable(sceneToReplace, "sceneToReplace"); JObject parameters = new JObject(); parameters.Add("sceneID", sceneToDelete.sceneID); parameters.Add("reassignSceneID", sceneToReplace.sceneID); return(new MethodParamsPacket("deleteScene", parameters)); }
private void AddConnectedControl(InteractiveConnectedSceneModel scene, InteractiveControlModel control) { InteractiveCommand command = this.GetInteractiveCommandForControl(this.Client.InteractiveGame.id, control); if (command != null) { command.UpdateWithLatestControl(control); this.Controls.Add(control.controlID, new InteractiveConnectedControlCommand(scene, control, command)); } }
private MethodPacket BuildDeleteControlsPacket(InteractiveConnectedSceneModel scene, IEnumerable <InteractiveControlModel> controls) { Validator.ValidateVariable(scene, "scene"); Validator.ValidateList(controls, "controls"); JObject parameters = new JObject(); parameters.Add("sceneID", scene.sceneID); parameters.Add("controlIDs", JArray.FromObject(controls.Select(c => c.controlID))); return(new MethodParamsPacket("deleteControls", parameters)); }
public void CreateGetUpdateDeleteGroup() { this.InteractiveWrapper(async(MixerConnection connection, InteractiveClient interactiveClient) => { InteractiveConnectedSceneModel testScene = await this.CreateScene(interactiveClient); this.ClearPackets(); InteractiveGroupModel testGroup = new InteractiveGroupModel() { groupID = GroupID, sceneID = testScene.sceneID }; bool result = await interactiveClient.CreateGroupsWithResponse(new List <InteractiveGroupModel>() { testGroup }); Assert.IsTrue(result); this.ClearPackets(); InteractiveGroupCollectionModel groups = await interactiveClient.GetGroups(); Assert.IsNotNull(groups); Assert.IsNotNull(groups.groups); Assert.IsTrue(groups.groups.Count > 0); testGroup = groups.groups.FirstOrDefault(g => g.groupID.Equals(GroupID)); InteractiveGroupModel defaultGroup = groups.groups.FirstOrDefault(g => g.groupID.Equals("default")); this.ClearPackets(); groups = await interactiveClient.UpdateGroupsWithResponse(new List <InteractiveGroupModel>() { testGroup }); Assert.IsNotNull(groups); Assert.IsNotNull(groups.groups); Assert.IsTrue(groups.groups.Count > 0); testGroup = groups.groups.FirstOrDefault(g => g.groupID.Equals(GroupID)); this.ClearPackets(); result = await interactiveClient.DeleteGroupWithResponse(testGroup, defaultGroup); Assert.IsTrue(result); await this.DeleteScene(interactiveClient, testScene); }); }
private MethodPacket BuildUpdateControlsPacket(InteractiveConnectedSceneModel scene, IEnumerable <InteractiveControlModel> controls) { Validator.ValidateVariable(scene, "scene"); Validator.ValidateList(controls, "controls"); JObject parameters = new JObject(); parameters.Add("sceneID", scene.sceneID); parameters.Add("controls", JArray.FromObject(controls, new JsonSerializer { NullValueHandling = NullValueHandling.Ignore })); return(new MethodParamsPacket("updateControls", parameters)); }
public InteractiveConnectedControlCommand(InteractiveConnectedSceneModel scene, InteractiveControlModel control, InteractiveCommand command) { this.Scene = scene; this.Command = command; if (control is InteractiveConnectedButtonControlModel) { this.Button = (InteractiveConnectedButtonControlModel)control; } else { this.Joystick = (InteractiveConnectedJoystickControlModel)control; } }
protected override async Task GameConnectedInternal() { InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes(); if (sceneGroups != null) { this.scene = sceneGroups.scenes.FirstOrDefault(); if (this.scene != null) { this.drawButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("draw")); } } }
public async Task UpdateControls(InteractiveConnectedSceneModel scene, IEnumerable <InteractiveControlModel> controls) { List <InteractiveControlModel> updatedControls = new List <InteractiveControlModel>(); foreach (InteractiveControlModel control in controls) { if (control is InteractiveConnectedButtonControlModel) { updatedControls.Add(SerializerHelper.Clone <InteractiveConnectedButtonControlModel>(control)); } else if (control is InteractiveConnectedJoystickControlModel) { updatedControls.Add(SerializerHelper.Clone <InteractiveConnectedJoystickControlModel>(control)); } else if (control is InteractiveConnectedTextBoxControlModel) { updatedControls.Add(SerializerHelper.Clone <InteractiveConnectedTextBoxControlModel>(control)); } else if (control is InteractiveConnectedLabelControlModel) { updatedControls.Add(SerializerHelper.Clone <InteractiveConnectedLabelControlModel>(control)); } else if (control is InteractiveButtonControlModel) { updatedControls.Add(SerializerHelper.Clone <InteractiveButtonControlModel>(control)); } else if (control is InteractiveJoystickControlModel) { updatedControls.Add(SerializerHelper.Clone <InteractiveJoystickControlModel>(control)); } else if (control is InteractiveTextBoxControlModel) { updatedControls.Add(SerializerHelper.Clone <InteractiveTextBoxControlModel>(control)); } else if (control is InteractiveLabelControlModel) { updatedControls.Add(SerializerHelper.Clone <InteractiveLabelControlModel>(control)); } else { updatedControls.Add(SerializerHelper.Clone <InteractiveControlModel>(control)); } } foreach (InteractiveControlModel control in updatedControls) { control.position = null; } await this.RunAsync(this.Client.UpdateControls(scene, updatedControls)); }
private async Task <InteractiveConnectedSceneModel> GetScene(InteractiveClient interactiveClient) { this.ClearPackets(); InteractiveConnectedSceneGroupCollectionModel scenes = await interactiveClient.GetScenes(); Assert.IsNotNull(scenes); Assert.IsNotNull(scenes.scenes); Assert.IsTrue(scenes.scenes.Count >= 2); InteractiveConnectedSceneModel testScene = scenes.scenes.FirstOrDefault(s => s.sceneID.Equals(SceneID)); Assert.IsNotNull(testScene); return(testScene); }
private async Task DeleteScene(InteractiveClient interactiveClient, InteractiveConnectedSceneModel scene) { this.ClearPackets(); InteractiveConnectedSceneGroupCollectionModel scenes = await interactiveClient.GetScenes(); Assert.IsNotNull(scenes); Assert.IsNotNull(scenes.scenes); Assert.IsTrue(scenes.scenes.Count >= 2); InteractiveConnectedSceneModel backupScene = scenes.scenes.FirstOrDefault(s => s.sceneID.Equals("default")); bool result = await interactiveClient.DeleteSceneWithResponse(scene, backupScene); Assert.IsTrue(result); }
protected override async Task <bool> GameConnectedInternal() { InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes(); if (sceneGroups != null) { this.scene = sceneGroups.scenes.FirstOrDefault(); if (this.scene != null) { this.sendButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("send")); this.presentButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("present")); if (this.sendButton != null && this.presentButton != null) { return(true); } } } return(false); }
private async Task <InteractiveConnectedSceneModel> CreateScene(InteractiveClient interactiveClient) { this.ClearPackets(); InteractiveConnectedSceneCollectionModel scenes = await interactiveClient.CreateScenesWithResponse(new List <InteractiveConnectedSceneModel>() { new InteractiveConnectedSceneModel() { sceneID = SceneID } }); Assert.IsNotNull(scenes); Assert.IsNotNull(scenes.scenes); Assert.IsTrue(scenes.scenes.Count >= 1); InteractiveConnectedSceneModel testScene = scenes.scenes.FirstOrDefault(s => s.sceneID.Equals(SceneID)); Assert.IsNotNull(testScene); return(await this.GetScene(interactiveClient)); }
public void CreateUpdateDeleteControl() { this.InteractiveWrapper(async(MixerConnection connection, InteractiveClient interactiveClient) => { InteractiveConnectedSceneModel testScene = await this.CreateScene(interactiveClient); this.ClearPackets(); InteractiveControlModel testControl = InteractiveClientUnitTests.CreateTestButton(); List <InteractiveControlModel> controls = new List <InteractiveControlModel>() { testControl, InteractiveClientUnitTests.CreateTestJoystick() }; bool result = await interactiveClient.CreateControlsWithResponse(testScene, controls); Assert.IsTrue(result); testScene = await this.GetScene(interactiveClient); testControl = testScene.buttons.FirstOrDefault(c => c.controlID.Equals(ButtonControlID)); Assert.IsNotNull(testControl); controls = new List <InteractiveControlModel>() { testControl }; InteractiveConnectedControlCollectionModel controlCollection = await interactiveClient.UpdateControlsWithResponse(testScene, controls); Assert.IsNotNull(controlCollection); Assert.IsNotNull(controlCollection.buttons); testScene = await this.GetScene(interactiveClient); testControl = testScene.buttons.FirstOrDefault(c => c.controlID.Equals(ButtonControlID)); Assert.IsNotNull(testControl); result = await interactiveClient.DeleteControlsWithResponse(testScene, controls); Assert.IsTrue(result); await this.DeleteScene(interactiveClient, testScene); }); }
private void AddConnectedControl(InteractiveConnectedSceneModel scene, InteractiveControlModel control) { InteractiveCommand command = this.GetInteractiveCommandForControl(this.Client.InteractiveGame.id, control); if (command != null) { command.UpdateWithLatestControl(control); if (control is InteractiveConnectedButtonControlModel) { this.ControlCommands[control.controlID] = new InteractiveConnectedButtonCommand(scene, (InteractiveConnectedButtonControlModel)control, command); } else if (control is InteractiveConnectedJoystickControlModel) { this.ControlCommands[control.controlID] = new InteractiveConnectedJoystickCommand(scene, (InteractiveConnectedJoystickControlModel)control, command); } else if (control is InteractiveConnectedTextBoxControlModel) { this.ControlCommands[control.controlID] = new InteractiveConnectedTextBoxCommand(scene, (InteractiveConnectedTextBoxControlModel)control, command); } } }
public void CreateGetUpdateDeleteScene() { this.InteractiveWrapper(async(MixerConnection connection, InteractiveClient interactiveClient) => { InteractiveConnectedSceneModel testScene = await this.CreateScene(interactiveClient); this.ClearPackets(); InteractiveConnectedSceneCollectionModel scenes = await interactiveClient.UpdateScenesWithResponse(new List <InteractiveConnectedSceneModel>() { testScene }); Assert.IsNotNull(scenes); Assert.IsNotNull(scenes.scenes); Assert.IsTrue(scenes.scenes.Count >= 1); testScene = scenes.scenes.FirstOrDefault(s => s.sceneID.Equals(SceneID)); await this.DeleteScene(interactiveClient, testScene); }); }
private async void InteractiveClient_OnGiveInput(object sender, InteractiveGiveInputModel e) { this.InteractiveDataTextBlock.Text += "Input Received: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID + Environment.NewLine; if (e.input.eventType.Equals("mousedown")) { this.ProcessVote(sender, e); if (e.transactionID != null) { InteractiveConnectedButtonControlModel button = this.buttons.FirstOrDefault(b => b.controlID.Equals(e.input.controlID)); if (button != null) { InteractiveConnectedSceneModel scene = this.scenes.FirstOrDefault(s => s.buttons.Contains(button)); if (scene != null) { button.cooldown = DateTimeHelper.DateTimeOffsetToUnixTimestamp(DateTimeOffset.Now.AddSeconds(10)); await this.interactiveClient.UpdateControls(scene, new List <InteractiveConnectedButtonControlModel>() { button }); this.InteractiveDataTextBlock.Text += "Sent 10 second cooldown to button: " + e.input.controlID + Environment.NewLine; } } await this.interactiveClient.CaptureSparkTransaction(e.transactionID); this.InteractiveDataTextBlock.Text += "Spark Transaction Captured: " + e.participantID + " - " + e.input.eventType + " - " + e.input.controlID + Environment.NewLine; } } }
/// <summary> /// Deletes and replaced the specified scene. /// </summary> /// <param name="sceneToDelete">The scene to delete</param> /// <param name="sceneToReplace">The scene to replace with</param> /// <returns>The task object representing the asynchronous operation</returns> public async Task DeleteScene(InteractiveConnectedSceneModel sceneToDelete, InteractiveConnectedSceneModel sceneToReplace) { await this.Send(this.BuildDeleteScenePacket(sceneToDelete, sceneToReplace)); }
protected override async Task <bool> GameConnectedInternal() { this.Dispatcher.Invoke(() => { this.MapComboBox.IsEnabled = false; this.MaxTimeTextBox.IsEnabled = false; this.SparkCostTextBox.IsEnabled = false; this.TimerStackPanel.Visibility = Visibility.Hidden; this.DropLocationStackPanel.Visibility = Visibility.Hidden; this.WinnerStackPanel.Visibility = Visibility.Hidden; this.TimerTextBlock.Text = string.Empty; this.DropLocationTextBlock.Text = string.Empty; this.WinnerAvatar.SetSize(80); this.WinnerTextBlock.Text = string.Empty; }); this.SaveSettings(); InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes(); if (sceneGroups != null) { this.scene = sceneGroups.scenes.FirstOrDefault(); if (this.scene != null) { this.positionButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("position")); this.winnerButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("winner")); } } if (this.positionButton == null || this.winnerButton == null) { Logger.Log("Could not get position or winner buttons"); return(false); } if (this.sparkCost > 0) { this.positionButton.cost = this.sparkCost; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { this.positionButton }); await ChannelSession.Interactive.RefreshCachedControls(); } if (this.dropMapType == DropMapTypeEnum.PUBG) { JObject settings = this.GetCustomSettings(); settings[MapSelectionSettingProperty] = this.MapComboBox.SelectedIndex; this.SaveCustomSettings(settings); PUBGMap map = (PUBGMap)this.MapComboBox.SelectedItem; InteractiveConnectedButtonControlModel control = new InteractiveConnectedButtonControlModel() { controlID = this.positionButton.controlID }; control.meta["map"] = map.Map; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); } this.userAvatars.Clear(); this.userPoints.Clear(); if (this.canvas != null) { this.canvas.Children.Clear(); } #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { if (this.scene != null && this.winnerButton != null) { InteractiveConnectedButtonControlModel control = null; for (int i = 0; i < (maxTime + 1); i++) { await Task.Delay(1000); int timeLeft = maxTime - i; this.Dispatcher.Invoke(() => { this.UpdateTimerUI(timeLeft); }); control = new InteractiveConnectedButtonControlModel() { controlID = this.winnerButton.controlID }; control.meta["timeleft"] = timeLeft; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); } if (this.userPoints.Count > 0) { var users = this.userPoints.Keys.ToList(); int index = RandomHelper.GenerateRandomNumber(users.Count); uint winner = users[index]; Point point = this.userPoints[winner]; UserProfileAvatarControl avatar = this.userAvatars[winner]; UserModel user = await ChannelSession.Connection.GetUser(winner); string username = (user != null) ? user.username : "******"; string location = this.ComputeLocation(point); this.Dispatcher.InvokeAsync(async() => { await this.UpdateWinnerUI(winner, username, location); this.canvas.Children.Clear(); this.canvas.Children.Add(avatar); }); control = new InteractiveConnectedButtonControlModel() { controlID = this.winnerButton.controlID }; control.meta["userID"] = winner; control.meta["username"] = username; control.meta["location"] = location; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); await ChannelSession.Chat.SendMessage(string.Format("Winner: @{0}, Drop Location: {1}", username, location)); } } }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(await base.GameConnectedInternal()); }
public InteractiveConnectedButtonCommand(InteractiveConnectedSceneModel scene, InteractiveConnectedButtonControlModel button, InteractiveCommand command) : base(scene, button, command) { }
public InteractiveConnectedButtonCommand(InteractiveConnectedSceneModel scene, InteractiveConnectedButtonControlModel button, InteractiveCommand command) : base(scene, button, command) { this.ButtonCommand.OnCommandStart += ButtonCommand_OnCommandStart; }
private void Client_OnControlUpdate(object sender, InteractiveConnectedSceneModel e) { this.OnControlUpdate(this, e); }
protected override async Task GameConnectedInternal() { this.SaveDropMapSettings(); InteractiveConnectedSceneGroupCollectionModel sceneGroups = await ChannelSession.Interactive.GetScenes(); if (sceneGroups != null) { this.scene = sceneGroups.scenes.FirstOrDefault(); if (this.scene != null) { this.positionButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("position")); this.winnerButton = this.scene.buttons.FirstOrDefault(c => c.controlID.Equals("winner")); } } if (this.positionButton == null || this.winnerButton == null) { throw new InvalidOperationException("Could not get position or winner buttons"); } if (this.sparkCost > 0) { this.positionButton.cost = this.sparkCost; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { this.positionButton }); await ChannelSession.Interactive.RefreshCachedControls(); } this.userAvatars.Clear(); this.userPoints.Clear(); this.canvas.Children.Clear(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(async() => { if (this.scene != null && this.winnerButton != null) { InteractiveConnectedButtonControlModel control = null; for (int i = 0; i < (maxTime + 1); i++) { await Task.Delay(1000); int timeLeft = maxTime - i; this.Dispatcher.Invoke(() => { this.UpdateTimerUI(timeLeft); }); control = new InteractiveConnectedButtonControlModel() { controlID = this.winnerButton.controlID }; control.meta["timeleft"] = timeLeft; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); } if (this.userPoints.Count > 0) { var users = this.userPoints.Keys.ToList(); int index = RandomHelper.GenerateRandomNumber(users.Count); uint winner = users[index]; Point point = this.userPoints[winner]; UserProfileAvatarControl avatar = this.userAvatars[winner]; UserModel user = await ChannelSession.Connection.GetUser(winner); string username = (user != null) ? user.username : "******"; string location = this.ComputeLocation(point); this.Dispatcher.InvokeAsync(async() => { await this.UpdateWinnerUI(winner, username, location); this.canvas.Children.Clear(); this.canvas.Children.Add(avatar); }); control = new InteractiveConnectedButtonControlModel() { controlID = this.winnerButton.controlID }; control.meta["userID"] = winner; control.meta["username"] = username; control.meta["location"] = location; await ChannelSession.Interactive.UpdateControls(this.scene, new List <InteractiveControlModel>() { control }); await ChannelSession.Chat.SendMessage(string.Format("Winner: @{0}, Drop Location: {1}", username, location)); } } }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }
public InteractiveConnectedControlCommand(InteractiveConnectedSceneModel scene, InteractiveControlModel control, InteractiveCommand command) { this.Scene = scene; this.Control = control; this.Command = command; }
public InteractiveConnectedTextBoxCommand(InteractiveConnectedSceneModel scene, InteractiveConnectedTextBoxControlModel textBox, InteractiveCommand command) : base(scene, textBox, command) { }
/// <summary> /// Deletes the specified controls from the specified scene. /// </summary> /// <param name="scene">The scene to delete controls from</param> /// <param name="controls">The controls to delete</param> /// <returns>The task object representing the asynchronous operation</returns> public async Task DeleteControls(InteractiveConnectedSceneModel scene, IEnumerable <InteractiveControlModel> controls) { await this.Send(this.BuildDeleteControlsPacket(scene, controls)); }
/// <summary> /// Deletes and replaced the specified scene. /// </summary> /// <param name="sceneToDelete">The scene to delete</param> /// <param name="sceneToReplace">The scene to replace with</param> /// <returns>Whether the operation succeeded</returns> public async Task <bool> DeleteSceneWithResponse(InteractiveConnectedSceneModel sceneToDelete, InteractiveConnectedSceneModel sceneToReplace) { return(this.VerifyNoErrors(await this.SendAndListen(this.BuildDeleteScenePacket(sceneToDelete, sceneToReplace)))); }
/// <summary> /// Updates the specified controls for the specified scene. /// </summary> /// <param name="scene">The scene to update controls for</param> /// <param name="controls">The controls to update</param> /// <returns>The updated controls</returns> public async Task <InteractiveConnectedControlCollectionModel> UpdateControlsWithResponse(InteractiveConnectedSceneModel scene, IEnumerable <InteractiveControlModel> controls) { return(await this.SendAndListen <InteractiveConnectedControlCollectionModel>(this.BuildUpdateControlsPacket(scene, controls))); }
public InteractiveConnectedJoystickCommand(InteractiveConnectedSceneModel scene, InteractiveConnectedJoystickControlModel joystick, InteractiveCommand command) : base(scene, joystick, command) { }
/// <summary> /// Deletes the specified controls from the specified scene. /// </summary> /// <param name="scene">The scene to delete controls from</param> /// <param name="controls">The controls to delete</param> /// <returns>Whether the operation succeeded</returns> public async Task <bool> DeleteControlsWithResponse(InteractiveConnectedSceneModel scene, IEnumerable <InteractiveControlModel> controls) { return(this.VerifyNoErrors(await this.SendAndListen(this.BuildDeleteControlsPacket(scene, controls)))); }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { if (ChannelSession.Interactive != null) { if (this.InteractiveType == InteractiveActionTypeEnum.Connect) { if (ChannelSession.Interactive.IsConnected()) { await ChannelSession.Interactive.Disconnect(); GlobalEvents.InteractiveDisconnected(); } IEnumerable <InteractiveGameModel> games = await ChannelSession.Interactive.GetAllConnectableGames(); InteractiveGameModel game = games.FirstOrDefault(g => g.id.Equals(this.InteractiveGameID)); if (game != null) { if (await ChannelSession.Interactive.Connect(game)) { GlobalEvents.InteractiveConnected(game); } } } else if (this.InteractiveType == InteractiveActionTypeEnum.Disconnect) { if (ChannelSession.Interactive.IsConnected()) { await ChannelSession.Interactive.Disconnect(); GlobalEvents.InteractiveDisconnected(); } } else if (ChannelSession.Interactive.IsConnected()) { if (!user.HasPermissionsTo(this.RoleRequirement)) { if (ChannelSession.Chat != null) { await ChannelSession.Chat.Whisper(user.UserName, "You do not permission to perform this action."); } return; } await ChannelSession.Interactive.AddGroup(this.GroupName, (!string.IsNullOrEmpty(this.SceneID))?this.SceneID : InteractiveUserGroupViewModel.DefaultName); if (this.InteractiveType == InteractiveActionTypeEnum.MoveGroupToScene) { await ChannelSession.Interactive.UpdateGroup(this.GroupName, this.SceneID); } else if (this.InteractiveType == InteractiveActionTypeEnum.MoveUserToGroup || this.InteractiveType == InteractiveActionTypeEnum.MoveUserToScene) { if (!string.IsNullOrEmpty(this.OptionalUserName)) { string optionalUserName = await this.ReplaceStringWithSpecialModifiers(this.OptionalUserName, user, arguments); UserViewModel optionalUser = await ChannelSession.ActiveUsers.GetUserByUsername(optionalUserName); if (optionalUser != null) { await ChannelSession.Interactive.AddUserToGroup(optionalUser, this.GroupName); } } else { await ChannelSession.Interactive.AddUserToGroup(user, this.GroupName); } } if (this.InteractiveType == InteractiveActionTypeEnum.MoveAllUsersToGroup || this.InteractiveType == InteractiveActionTypeEnum.MoveAllUsersToScene) { foreach (UserViewModel chatUser in await ChannelSession.ActiveUsers.GetAllUsers()) { await ChannelSession.Interactive.AddUserToGroup(chatUser, this.GroupName); } IEnumerable <InteractiveParticipantModel> participants = ChannelSession.Interactive.Participants.Values; foreach (InteractiveParticipantModel participant in participants) { participant.groupID = this.GroupName; } await ChannelSession.Interactive.UpdateParticipants(participants); } else if (this.InteractiveType == InteractiveActionTypeEnum.CooldownButton || this.InteractiveType == InteractiveActionTypeEnum.CooldownGroup || this.InteractiveType == InteractiveActionTypeEnum.CooldownScene) { InteractiveConnectedSceneModel scene = null; List <InteractiveConnectedButtonControlModel> buttons = new List <InteractiveConnectedButtonControlModel>(); if (this.InteractiveType == InteractiveActionTypeEnum.CooldownButton) { if (ChannelSession.Interactive.ControlCommands.ContainsKey(this.CooldownID) && ChannelSession.Interactive.ControlCommands[this.CooldownID] is InteractiveConnectedButtonCommand) { InteractiveConnectedButtonCommand command = (InteractiveConnectedButtonCommand)ChannelSession.Interactive.ControlCommands[this.CooldownID]; scene = command.Scene; buttons.Add(command.Button); } } if (this.InteractiveType == InteractiveActionTypeEnum.CooldownGroup) { var allButtons = ChannelSession.Interactive.ControlCommands.Values.Where(c => c is InteractiveConnectedButtonCommand).Select(c => (InteractiveConnectedButtonCommand)c); allButtons = allButtons.Where(c => this.CooldownID.Equals(c.ButtonCommand.CooldownGroupName)); if (allButtons.Count() > 0) { scene = allButtons.FirstOrDefault().Scene; buttons.AddRange(allButtons.Select(c => c.Button)); } } if (this.InteractiveType == InteractiveActionTypeEnum.CooldownScene) { var allButtons = ChannelSession.Interactive.ControlCommands.Values.Where(c => c is InteractiveConnectedButtonCommand).Select(c => (InteractiveConnectedButtonCommand)c); allButtons = allButtons.Where(c => this.CooldownID.Equals(c.ButtonCommand.SceneID)); if (allButtons.Count() > 0) { scene = allButtons.FirstOrDefault().Scene; buttons.AddRange(allButtons.Select(c => c.Button)); } } if (buttons.Count > 0) { long timestamp = DateTimeHelper.DateTimeOffsetToUnixTimestamp(DateTimeOffset.Now.AddSeconds(this.CooldownAmount)); foreach (InteractiveConnectedButtonControlModel button in buttons) { button.SetCooldownTimestamp(timestamp); } await ChannelSession.Interactive.UpdateControls(scene, buttons); } } else if (this.InteractiveType == InteractiveActionTypeEnum.UpdateControl || this.InteractiveType == InteractiveActionTypeEnum.SetCustomMetadata || this.InteractiveType == InteractiveActionTypeEnum.EnableDisableControl) { InteractiveConnectedSceneModel scene = null; InteractiveControlModel control = null; foreach (InteractiveConnectedSceneModel s in ChannelSession.Interactive.Scenes) { foreach (InteractiveControlModel c in s.allControls) { if (c.controlID.Equals(this.ControlID)) { scene = s; control = c; break; } } if (control != null) { break; } } if (scene != null && control != null) { if (this.InteractiveType == InteractiveActionTypeEnum.UpdateControl) { string replacementValue = await this.ReplaceStringWithSpecialModifiers(this.UpdateValue, user, arguments); int.TryParse(replacementValue, out int replacementNumberValue); if (control is InteractiveButtonControlModel) { InteractiveButtonControlModel button = (InteractiveButtonControlModel)control; switch (this.UpdateControlType) { case InteractiveActionUpdateControlTypeEnum.Text: button.text = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.TextSize: button.textSize = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.TextColor: button.textColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.Tooltip: button.tooltip = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.SparkCost: button.cost = replacementNumberValue; break; case InteractiveActionUpdateControlTypeEnum.AccentColor: button.accentColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.FocusColor: button.focusColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.BorderColor: button.borderColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.BackgroundColor: button.backgroundColor = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.BackgroundImage: button.backgroundImage = replacementValue; break; } } else if (control is InteractiveLabelControlModel) { InteractiveLabelControlModel label = (InteractiveLabelControlModel)control; switch (this.UpdateControlType) { case InteractiveActionUpdateControlTypeEnum.Text: label.text = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.TextSize: label.textSize = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.TextColor: label.textColor = replacementValue; break; } } else if (control is InteractiveTextBoxControlModel) { InteractiveTextBoxControlModel textbox = (InteractiveTextBoxControlModel)control; switch (this.UpdateControlType) { case InteractiveActionUpdateControlTypeEnum.Text: textbox.submitText = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.Tooltip: textbox.placeholder = replacementValue; break; case InteractiveActionUpdateControlTypeEnum.SparkCost: textbox.cost = replacementNumberValue; break; } } } else if (this.InteractiveType == InteractiveActionTypeEnum.SetCustomMetadata) { control.meta["userID"] = user.ID; foreach (var kvp in this.CustomMetadata) { string value = await this.ReplaceStringWithSpecialModifiers(kvp.Value, user, arguments); if (bool.TryParse(value, out bool boolValue)) { control.meta[kvp.Key] = boolValue; } else if (int.TryParse(value, out int intValue)) { control.meta[kvp.Key] = intValue; } else if (double.TryParse(value, out double doubleValue)) { control.meta[kvp.Key] = doubleValue; } else { control.meta[kvp.Key] = value; } } } else if (this.InteractiveType == InteractiveActionTypeEnum.EnableDisableControl) { control.disabled = !this.EnableDisableControl; } await ChannelSession.Interactive.UpdateControls(scene, new List <InteractiveControlModel>() { control }); } } } } }