private async Task <ChatMessageViewModel> AddMessage(ChatMessageEventModel messageEvent) { UserViewModel user = await ChannelSession.ActiveUsers.AddOrUpdateUser(messageEvent.GetUser()); if (user == null) { user = new UserViewModel(messageEvent); } else { await user.RefreshDetails(); } user.UpdateLastActivity(); ChatMessageViewModel message = new ChatMessageViewModel(messageEvent, user); Util.Logger.LogDiagnostic(string.Format("Message Received - {0}", message.ToString())); if (!message.IsWhisper && !this.userEntranceCommands.Contains(user.ID)) { this.userEntranceCommands.Add(user.ID); if (user.Data.EntranceCommand != null) { await user.Data.EntranceCommand.Perform(user); } } if (this.Messages.ContainsKey(message.ID)) { return(null); } this.Messages[message.ID] = message; if (this.DisableChat && !message.ID.Equals(Guid.Empty)) { Util.Logger.LogDiagnostic(string.Format("Deleting Message As Chat Disabled - {0}", message.Message)); await this.DeleteMessage(message); return(message); } if (!ModerationHelper.MeetsChatInteractiveParticipationRequirement(user) || !ModerationHelper.MeetsChatEmoteSkillsOnlyParticipationRequirement(user, message)) { Util.Logger.LogDiagnostic(string.Format("Deleting Message As User does not meet requirement - {0} - {1}", ChannelSession.Settings.ModerationChatInteractiveParticipation, message.Message)); await this.DeleteMessage(message); await ModerationHelper.SendChatInteractiveParticipationWhisper(user, isChat : true); return(message); } string moderationReason = await message.ShouldBeModerated(); if (!string.IsNullOrEmpty(moderationReason)) { Util.Logger.LogDiagnostic(string.Format("Message Should Be Moderated - {0}", message.ToString())); bool shouldBeModerated = true; PermissionsCommandBase command = this.CheckMessageForCommand(message); if (command != null && string.IsNullOrEmpty(await ModerationHelper.ShouldBeFilteredWordModerated(user, message.Message))) { shouldBeModerated = false; } if (shouldBeModerated) { Util.Logger.LogDiagnostic(string.Format("Moderation Being Performed - {0}", message.ToString())); message.ModerationReason = moderationReason; await this.DeleteMessage(message); return(message); } } if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatWhisperSoundFilePath) && message.IsWhisper) { await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatWhisperSoundFilePath, 100); } else if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatTaggedSoundFilePath) && message.IsUserTagged) { await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatTaggedSoundFilePath, 100); } else if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatMessageSoundFilePath)) { await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatMessageSoundFilePath, 100); } GlobalEvents.ChatMessageReceived(message); if (!await this.CheckMessageForCommandAndRun(message)) { if (message.IsWhisper && ChannelSession.Settings.TrackWhispererNumber && !message.IsStreamerOrBot()) { await this.whisperNumberLock.WaitAndRelease(() => { if (!whisperMap.ContainsKey(message.User.ID)) { whisperMap[message.User.ID] = whisperMap.Count + 1; } message.User.WhispererNumber = whisperMap[message.User.ID]; return(Task.FromResult(0)); }); await ChannelSession.Chat.Whisper(message.User.UserName, $"You are whisperer #{message.User.WhispererNumber}.", false); } } return(message); }
private async void Client_OnGiveInput(object sender, InteractiveGiveInputModel e) { try { if (e != null && e.input != null) { InteractiveControlModel control = this.Controls[e.input.controlID]; InteractiveConnectedControlCommand connectedControl = null; if (this.ControlCommands.ContainsKey(e.input.controlID)) { connectedControl = this.ControlCommands[e.input.controlID]; if (!connectedControl.DoesInputMatchCommand(e)) { return; } if (!connectedControl.Command.IsEnabled) { return; } } UserViewModel user = null; if (!string.IsNullOrEmpty(e.participantID)) { user = await ChannelSession.ActiveUsers.GetUserByParticipantID(e.participantID); if (user == null) { InteractiveParticipantModel participant = null; if (this.Participants.TryGetValue(e.participantID, out participant)) { user = new UserViewModel(participant); } else { IEnumerable <InteractiveParticipantModel> recentParticipants = await this.GetRecentParticipants(); participant = recentParticipants.FirstOrDefault(p => p.sessionID.Equals(e.participantID)); if (participant != null) { user = await ChannelSession.ActiveUsers.AddOrUpdateUser(participant); } } } } if (user == null) { user = new UserViewModel(0, "Unknown User"); user.InteractiveIDs[e.participantID] = new InteractiveParticipantModel() { sessionID = e.participantID, anonymous = true }; } else { await user.RefreshDetails(); } user.UpdateLastActivity(); if (ChannelSession.Settings.PreventUnknownInteractiveUsers && user.IsAnonymous) { return; } if (user.IsInInteractiveTimeout) { return; } if (!ModerationHelper.MeetsChatInteractiveParticipationRequirement(user)) { await ModerationHelper.SendChatInteractiveParticipationWhisper(user, isInteractive : true); return; } if (!this.Controls.ContainsKey(e.input.controlID)) { return; } if (connectedControl != null) { int sparkCost = 0; await this.giveInputLock.WaitAndRelease(async() => { if (await connectedControl.CheckAllRequirements(user)) { if (!string.IsNullOrEmpty(e.transactionID) && !user.Data.IsSparkExempt) { Util.Logger.LogDiagnostic("Sending Spark Transaction Capture - " + e.transactionID); await this.CaptureSparkTransaction(e.transactionID); if (control is InteractiveButtonControlModel) { sparkCost = ((InteractiveButtonControlModel)control).cost.GetValueOrDefault(); } else if (control is InteractiveTextBoxControlModel) { sparkCost = ((InteractiveTextBoxControlModel)control).cost.GetValueOrDefault(); } } List <string> arguments = new List <string>(); if (connectedControl is InteractiveConnectedJoystickCommand) { arguments.Add(e.input.x.ToString()); arguments.Add(e.input.y.ToString()); } else if (connectedControl is InteractiveConnectedTextBoxCommand) { arguments.Add(e.input.value); } await connectedControl.Perform(user, arguments); } }); if (sparkCost > 0) { GlobalEvents.SparkUseOccurred(new Tuple <UserViewModel, int>(user, sparkCost)); } } this.OnGiveInput(this, e); this.OnInteractiveControlUsed(this, new InteractiveInputEvent(user, e, connectedControl)); } } catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); } }