internal static bool ResubmitApprovedMessage(MessageItem messageItem, TransportMailItem transportMailItem, string approverAddress) { DateTime utcNow = DateTime.UtcNow; HeaderList headerList = (transportMailItem.RootPart != null) ? transportMailItem.RootPart.Headers : null; if (!ModerationHelper.RestoreOriginalMessage(messageItem, transportMailItem, TraceHelper.ModeratedTransportTracer, TraceHelper.MessageProbeActivityId)) { return(false); } transportMailItem.RootPart.Headers.RemoveAll("X-MS-Exchange-Organization-Approval-Approved"); TextHeader textHeader = (TextHeader)Header.Create("X-MS-Exchange-Organization-Approval-Approved"); textHeader.Value = (string)transportMailItem.Recipients[0].Email; foreach (MailRecipient mailRecipient in transportMailItem.Recipients) { if (mailRecipient.Status == Status.Ready) { textHeader.Value = (string)mailRecipient.Email; break; } } transportMailItem.RootPart.Headers.AppendChild(textHeader); if (transportMailItem.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-Moderation-SavedArrivalTime") == null) { Header header = transportMailItem.RootPart.Headers.FindFirst("X-MS-Exchange-Organization-OriginalArrivalTime"); string value = null; if (header != null) { value = header.Value; } if (!string.IsNullOrEmpty(value)) { transportMailItem.RootPart.Headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-Moderation-SavedArrivalTime", value)); } } TextHeader textHeader2 = (TextHeader)Header.Create("X-Moderation-Data"); ExDateTime?valueAsNullable = messageItem.GetValueAsNullable <ExDateTime>(MessageItemSchema.ApprovalDecisionTime); if (valueAsNullable != null) { textHeader2.Value = valueAsNullable.ToString(); transportMailItem.RootPart.Headers.AppendChild(textHeader2); } if (headerList != null) { Header[] array = headerList.FindAll(HeaderId.Received); foreach (Header header2 in array) { Header header3 = Header.Create(HeaderId.Received); header2.CopyTo(header3); transportMailItem.RootPart.Headers.PrependChild(header3); } } transportMailItem.RootPart.Headers.RemoveAll("X-MS-Exchange-Organization-OriginalArrivalTime"); transportMailItem.RootPart.Headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-OriginalArrivalTime", Util.FormatOrganizationalMessageArrivalTime(utcNow))); transportMailItem.UpdateDirectionalityAndScopeHeaders(); transportMailItem.UpdateCachedHeaders(); MessageTrackingLog.TrackReceiveForApprovalRelease(transportMailItem, approverAddress, messageItem.InternetMessageId); return(true); }
public async Task <string> ShouldBeModerated() { if (this.IsWhisper) { return(string.Empty); } return(await ModerationHelper.ShouldBeModerated(this.User, this.Message, this.ContainsLink)); }
static async Task Main(string[] args) { Console.WriteLine("Running analysis"); var client = new HttpClient(); var moderationHelper = new ModerationHelper(client, key, region); var result = await moderationHelper.ModerateText("Hello World"); Console.WriteLine(result.ToString()); Console.ReadKey(); }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments, Dictionary <string, string> extraSpecialIdentifiers, CancellationToken token) { if (this.UseChatModeration && arguments.Count() > 0) { if (!string.IsNullOrEmpty(await ModerationHelper.ShouldBeModerated(user, arguments.ElementAt(0)))) { return; } } await base.PerformInternal(user, arguments, extraSpecialIdentifiers, token); }
public async Task <string> ShouldBeModerated() { if (this.IsWhisper) { return(string.Empty); } if ((this.IsSkill || this.IsChatSkill) && string.IsNullOrEmpty(this.Message)) { return(string.Empty); } return(await ModerationHelper.ShouldBeModerated(this.User, this.Message, this.ContainsLink)); }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments, CancellationToken token) { if (this.UseChatModeration && arguments.Count() > 0) { string moderationReason = await ModerationHelper.ShouldBeModerated(user, arguments.ElementAt(0)); if (!string.IsNullOrEmpty(moderationReason)) { await ModerationHelper.SendModerationWhisper(user, moderationReason); return; } } await base.PerformInternal(user, arguments, token); }
public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); string requestBody = new StreamReader(req.Body).ReadToEnd(); dynamic data = JsonConvert.DeserializeObject(requestBody); var textToModerate = (string)data?.textToModerate; var moderationHelper = new ModerationHelper(Client, "<your content moderation api key>", "<moderation service region>"); ModerationResult result = await moderationHelper.ModerateText(textToModerate); return(data != null ? (ActionResult) new OkObjectResult(result.ToString()) : new BadRequestObjectResult("Please pass a string to evaluate")); }
protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments) { if (ChannelSession.Services.TranslationService != null) { string text = await this.ReplaceStringWithSpecialModifiers(this.Text, user, arguments); string translationResult = await ChannelSession.Services.TranslationService.Translate(this.Culture, text, this.AllowProfanity); if (string.IsNullOrEmpty(translationResult)) { translationResult = this.Text; } if (!string.IsNullOrEmpty(translationResult)) { if (string.IsNullOrEmpty(await ModerationHelper.ShouldBeModerated(user, translationResult))) { if (this.ResponseAction == TranslationResponseActionTypeEnum.Chat) { if (ChannelSession.Chat != null) { await ChannelSession.Chat.SendMessage(await this.ReplaceSpecialIdentifiers(this.ResponseChatText, user, arguments, translationResult)); } } else if (this.ResponseAction == TranslationResponseActionTypeEnum.Command) { CommandBase command = ChannelSession.AllEnabledCommands.FirstOrDefault(c => c.ID.Equals(this.ResponseCommandID)); if (command != null) { string argumentsText = (this.ResponseCommandArgumentsText != null) ? this.ResponseCommandArgumentsText : string.Empty; string commandArguments = await this.ReplaceSpecialIdentifiers(this.ResponseChatText, user, arguments, translationResult); await command.Perform(user, commandArguments.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries), this.GetExtraSpecialIdentifiers()); } } else if (this.ResponseAction == TranslationResponseActionTypeEnum.SpecialIdentifier) { string replacementText = await this.ReplaceStringWithSpecialModifiers(translationResult, user, arguments); SpecialIdentifierStringBuilder.AddCustomSpecialIdentifier(this.SpecialIdentifierName, replacementText); } } } } }
public void OnDemotedMessageHandler(StoreDriverEventSource source, StoreDriverSubmissionEventArgs args) { if (SubmissionConfiguration.Instance.App.EnableUnparkedMessageRestoring) { MailItem mailItem = args.MailItem; StoreDriverSubmissionEventArgsImpl storeDriverSubmissionEventArgsImpl = (StoreDriverSubmissionEventArgsImpl)args; MessageItem item = storeDriverSubmissionEventArgsImpl.SubmissionItem.Item; StoreSession session = storeDriverSubmissionEventArgsImpl.SubmissionItem.Session; if (ObjectClass.IsParkedMeetingMessage(storeDriverSubmissionEventArgsImpl.SubmissionItem.MessageClass)) { DateTime utcNow = DateTime.UtcNow; TransportMailItem transportMailItem = ((TransportMailItemWrapper)mailItem).TransportMailItem; ModerationHelper.RestoreOriginalMessage(item, transportMailItem, TraceHelper.ParkedItemSubmitterAgentTracer, TraceHelper.MessageProbeActivityId); transportMailItem.RootPart.Headers.RemoveAll("X-MS-Exchange-Organization-OriginalArrivalTime"); transportMailItem.RootPart.Headers.AppendChild(new AsciiTextHeader("X-MS-Exchange-Organization-OriginalArrivalTime", Util.FormatOrganizationalMessageArrivalTime(utcNow))); transportMailItem.ExtendedProperties.Clear(); transportMailItem.UpdateDirectionalityAndScopeHeaders(); transportMailItem.UpdateCachedHeaders(); } } }
private bool TryParkThisMessage(StoreDriverDeliveryEventArgsImpl args, MeetingSeriesMessageOrderingAgent.SeriesHeadersData headersData) { Guid networkMessageId = args.MailItemDeliver.MbxTransportMailItem.NetworkMessageId; this.AddUnparkedHeader(args.MailItem.Message.MimeDocument.RootPart.Headers, networkMessageId); bool encapsulationSucceeded = true; string text; bool encapsulationSucceeded2; using (EmailMessage emailMessage = ModerationHelper.EncapsulateOriginalMessage(args.MailItemDeliver.MbxTransportMailItem, new List <MailRecipient> { args.MailRecipient }, args.MailRecipient.Email.ToString(), args.MailRecipient.Email.ToString(), MeetingSeriesMessageOrderingAgent.tracer, delegate(Exception param0) { encapsulationSucceeded = false; }, out text)) { if (encapsulationSucceeded) { MailboxSession mailboxSession = args.MailboxSession; using (ParkedMeetingMessage parkedMeetingMessage = ParkedMeetingMessage.Create(mailboxSession)) { if (parkedMeetingMessage != null) { string internetMessageId = args.MailItemDeliver.MbxTransportMailItem.InternetMessageId; ItemConversion.ConvertAnyMimeToItem(parkedMeetingMessage, emailMessage.MimeDocument, new InboundConversionOptions(args.ADRecipientCache)); parkedMeetingMessage.ParkedCorrelationId = ParkedMeetingMessage.GetCorrelationId(headersData.SeriesId, headersData.SeriesSequenceNumber); parkedMeetingMessage[StoreObjectSchema.ItemClass] = "IPM.Parked.MeetingMessage"; parkedMeetingMessage.CleanGlobalObjectId = headersData.InstanceGoid; parkedMeetingMessage.OriginalMessageId = internetMessageId; int retentionPeriod = MeetingSeriesMessageOrderingAgent.GetRetentionPeriod(args.MailboxOwner); PolicyTagHelper.SetRetentionProperties(parkedMeetingMessage, ExDateTime.UtcNow.AddDays((double)retentionPeriod), retentionPeriod); parkedMeetingMessage.Save(SaveMode.NoConflictResolution); } } } encapsulationSucceeded2 = encapsulationSucceeded; } return(encapsulationSucceeded2); }
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 Task <ChatMessageViewModel> AddMessage(ChatMessageEventModel messageEvent) { UserViewModel user = await this.AddUser(messageEvent); if (user != null && !this.userEntranceCommands.Contains(user.ID)) { this.userEntranceCommands.Add(user.ID); if (user.Data.EntranceCommand != null) { await user.Data.EntranceCommand.Perform(user); } } ChatMessageViewModel message = new ChatMessageViewModel(messageEvent, user); if (this.Messages.ContainsKey(message.ID)) { return(null); } this.Messages[message.ID] = message; if (this.DisableChat && !message.ID.Equals(Guid.Empty)) { await this.DeleteMessage(message.ID); return(message); } string moderationReason = await message.ShouldBeModerated(); if (!string.IsNullOrEmpty(moderationReason)) { await this.DeleteMessage(message.ID); await ModerationHelper.SendModerationWhisper(user, moderationReason); return(message); } if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatTaggedSoundFilePath) && message.IsUserTagged) { await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatTaggedSoundFilePath, 100); } if (!string.IsNullOrEmpty(ChannelSession.Settings.NotificationChatWhisperSoundFilePath) && message.IsWhisper) { await ChannelSession.Services.AudioService.Play(ChannelSession.Settings.NotificationChatWhisperSoundFilePath, 100); } if (!await this.CheckMessageForCommandAndRun(message)) { if (message.IsWhisper && ChannelSession.Settings.TrackWhispererNumber && !message.IsStreamerOrBot()) { await this.whisperNumberLock.WaitAsync(); if (!whisperMap.ContainsKey(message.User.ID)) { whisperMap[message.User.ID] = whisperMap.Count + 1; } message.User.WhispererNumber = whisperMap[message.User.ID]; this.whisperNumberLock.Release(); 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); } }