public void ChairWithSeveralWhitespacesTest() { const string prefix = "#chair"; string args = $" {user1} {user2} "; const MeetingAction action = MeetingAction.Chair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); // Owner is chair by default. ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should be a successful parse. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(1, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // New chair should show up in list. Assert.AreEqual(3, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); Assert.IsTrue(uut.Chairs.Contains(user2)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); }
public void OwnerCantUnchairThemselfTest() { // Ensure owner can unchair chair. { const string prefix = "#unchair"; const string args = owner; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should have correct error message and added to list. Assert.AreEqual(ParseMessageResult.CanNotDoThisToOwner, result); Assert.AreEqual(1, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // Should still be a chair Assert.AreEqual(1, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } }
/// <summary> /// Adds a normal message to the meeting notes, /// and returns the message that was added. /// </summary> private IMeetingMessage AddMessage( string message, string user, ParseMessageResult expectedResult = ParseMessageResult.Success, DateTime?timestamp = null ) { const string prefix = ""; string args = message; const MeetingAction action = MeetingAction.Unknown; const CommandRestriction restrict = CommandRestriction.Unknown; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, user, timestamp ?? this.testTime); Assert.AreEqual(expectedResult, result); return(msg); }
private ParseMessageResult HandleBan(IMeetingMessage msg) { ParseMessageResult result = ParseMessageResult.Success; Action <string> action = delegate(string user) { if (this.chairs.Contains(user)) { result = ParseMessageResult.CanNotDoThisToChair; } else { if (this.bannedUsers.Contains(user) == false) { this.bannedUsers.Add(user); } PurgeUser(user); } }; DoUserSplitAction(msg.CommandArgs, action); return(result); }
private ParseMessageResult HandlePurge(IMeetingMessage msg) { Action <string> action = delegate(string user) { PurgeUser(user); }; DoUserSplitAction(msg.CommandArgs, action); // Not really much that can go wrong here... return(ParseMessageResult.Success); }
public void PurgeUserTest() { // Add some messages AddAndCheckMessage( "Hello World 1", 1, user1 ); AddAndCheckMessage( "Hello World 2", 2, user1 ); // Purge the user. { const string prefix = "#purge"; const string args = user1; const MeetingAction action = MeetingAction.Purge; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should be a successful parse. Assert.AreEqual(ParseMessageResult.Success, result); // Only 1 message should remain; the purge one. Assert.AreEqual(1, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); EnsureDefaultLists(); } // User should still be able to chat though. Should be 2 messages now // (new message + purge message). AddAndCheckMessage( "Hello World 2", 2, user1 ); }
private ParseMessageResult HandleChair(IMeetingMessage msg) { Action <string> action = delegate(string user) { if (this.chairs.Contains(user) == false) { this.chairs.Add(user); } }; DoUserSplitAction(msg.CommandArgs, action); // Not really much that can go wrong here... return(ParseMessageResult.Success); }
private ParseMessageResult HandleVoice(IMeetingMessage msg) { Action <string> action = delegate(string user) { if (this.silencedUsers.Contains(user)) { this.silencedUsers.Remove(user); } }; DoUserSplitAction(msg.CommandArgs, action); // Not really much that can go wrong here... return(ParseMessageResult.Success); }
/// <summary> /// Adds a normal message to the meeting notes, /// and checks it to make sure it got added correctly. /// </summary> private void AddAndCheckMessage( string message, int expectedNumberOfMessages, string user, DateTime?timestamp = null ) { IMeetingMessage msg = AddMessage( message, user, ParseMessageResult.Success, timestamp ); // Should be a successful parse. Assert.AreEqual(expectedNumberOfMessages, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), user); }
private ParseMessageResult?TryCheckRestriction(IMeetingMessage msg, string user) { if (msg.Restriction == CommandRestriction.ChairsOnly) { if (this.chairs.Contains(user) == false) { return(ParseMessageResult.ChairOnlyCommand); } } else if (msg.Restriction == CommandRestriction.ChairsAndBotAdmins) { if ((this.chairs.Contains(user) == false) && (this.botAdmins.Contains(user) == false)) { return(ParseMessageResult.ChairBotAdminOnlyMessage); } } return(null); }
private void CompareNotes( IMeetingMessage msg, IReadOnlyMeetingNote note, string userName = user1, DateTime?time = null, MeetingAction?expectedMeetingAction = null ) { Assert.AreEqual(expectedMeetingAction ?? msg.MeetingAction, note.MeetingAction); Assert.AreEqual(userName, note.UserName); Assert.AreEqual(time ?? this.testTime, note.TimeStamp); // Unknown should be just the args, everything else is prefix then args. if (msg.MeetingAction == MeetingAction.Unknown) { Assert.AreEqual(msg.CommandArgs, note.Message); } else { Assert.AreEqual($"{msg.CommandPrefix} {msg.CommandArgs}", note.Message); } }
internal static void DeleteRelatedMessage(this IEventInternal entity, string messageId, DeleteItemFlags flags, IXSOFactory xsoFactory, IdConverter idConverter, IStoreSession session, bool markAsReadBeforeDelete) { StoreObjectId storeObjectId = idConverter.ToStoreObjectId(messageId); using (IMeetingMessage meetingMessage = xsoFactory.BindToMeetingMessage(session, storeObjectId)) { if (meetingMessage == null || meetingMessage.GlobalObjectId == null || meetingMessage.GlobalObjectId.ToString() != entity.GlobalObjectId) { throw new InvalidRequestException(CalendaringStrings.ErrorMeetingMessageNotFoundOrCantBeUsed); } if (markAsReadBeforeDelete) { meetingMessage.OpenAsReadWrite(); meetingMessage.IsRead = true; meetingMessage.Save(SaveMode.NoConflictResolutionForceSave); } } session.Delete(flags, new StoreId[] { storeObjectId }); }
public void NormalUserCantSilenceWithChairOnlySettingTest() { const string prefix = "#silence"; const string args = user2; const MeetingAction action = MeetingAction.Silence; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage silenceMsg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(silenceMsg, user1, this.testTime); Assert.AreEqual(ParseMessageResult.ChairOnlyCommand, result); EnsureDefaultLists(); Assert.AreEqual(1, uut.MeetingNotes.Count); CompareNotes(silenceMsg, uut.MeetingNotes.Last(), user1, expectedMeetingAction: MeetingAction.Unknown); }
public void HelpTest() { const string prefix = "#help"; const string args = "#link"; const MeetingAction action = MeetingAction.Help; const CommandRestriction restrict = CommandRestriction.Anyone; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); Assert.AreEqual(ParseMessageResult.Success, result); EnsureDefaultLists(); // Should be nothing in the meeting notes, helps are not added. Assert.AreEqual(0, uut.MeetingNotes.Count); }
// ---------------- Test Helpers ---------------- private IMeetingMessage AddChairMessage( string userToChair, string userThatChairs, ParseMessageResult expectedResult = ParseMessageResult.Success ) { const string prefix = "#chair"; string args = userToChair; const MeetingAction action = MeetingAction.Chair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, userThatChairs, this.testTime); Assert.AreEqual(expectedResult, result); return(msg); }
public void BotAdminSilenceTest() { const string prefix = "#silence"; const string args = user1; const MeetingAction action = MeetingAction.Silence; const CommandRestriction restrict = CommandRestriction.ChairsAndBotAdmins; IMeetingMessage silenceMsg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(silenceMsg, adminName, this.testTime); Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(1, uut.SilencedUsers.Count); Assert.IsTrue(uut.SilencedUsers.Contains(user1)); Assert.AreEqual(1, uut.MeetingNotes.Count); CompareNotes(silenceMsg, uut.MeetingNotes.Last(), adminName); }
private ParseMessageResult HandleUnChair(IMeetingMessage msg) { ParseMessageResult result = ParseMessageResult.Success; Action <string> action = delegate(string user) { if (this.chairs.Contains(user)) { if (user != this.MeetingInfo.Owner) { this.chairs.Remove(user); } else { // Override our result if we attempt to do this to an owner. result = ParseMessageResult.CanNotDoThisToOwner; } } }; DoUserSplitAction(msg.CommandArgs, action); return(result); }
public void ChairUnchair1PersonTest() { // Chair 1 user. { const string prefix = "#chair"; const string args = user1; const MeetingAction action = MeetingAction.Chair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); // Owner is chair by default. ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should be a successful parse. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(1, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // New chair should show up in list. Assert.AreEqual(2, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } // Ensure chair can not unchair owner. { const string prefix = "#unchair"; const string args = owner; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, user1, this.testTime); // Should have correct error message and added to list. Assert.AreEqual(ParseMessageResult.CanNotDoThisToOwner, result); Assert.AreEqual(2, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), user1); // Chair list should not be modified. Assert.AreEqual(2, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } // Ensure nonchair can not unchair chair { const string prefix = "#unchair"; const string args = user1; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, user2, this.testTime); // Should have correct error message and added to list. Assert.AreEqual(ParseMessageResult.ChairOnlyCommand, result); Assert.AreEqual(3, uut.MeetingNotes.Count); // Invalid permission, meeting message becomes standard message so it // doesn't show up in the log as something special. IReadOnlyMeetingNote note = uut.MeetingNotes.Last(); Assert.AreEqual(MeetingAction.Unknown, note.MeetingAction); Assert.AreEqual($"{msg.CommandPrefix} {msg.CommandArgs}", note.Message); Assert.AreEqual(user2, note.UserName); // Chair list should not be modified. Assert.AreEqual(2, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } // Ensure owner can unchair chair. { const string prefix = "#unchair"; const string args = user1; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should have correct error message and added to list. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(4, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // User should no longer be a chair. Assert.AreEqual(1, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } }
public void ChairUnchairSameUserTest() { // Chair 1 user. { const string prefix = "#chair"; const string args = user1; const MeetingAction action = MeetingAction.Chair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); // Owner is chair by default. ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should be a successful parse. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(1, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // New chair should show up in list. Assert.AreEqual(2, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } // Chair 1 user again! { const string prefix = "#chair"; const string args = user1; const MeetingAction action = MeetingAction.Chair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); // Owner is chair by default. ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should be a successful parse. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(2, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // New chair should show up in list, but only once! Assert.AreEqual(2, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } { const string prefix = "#unchair"; const string args = user1; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should have correct error message and added to list. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(3, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // User should no longer be a chair. Assert.AreEqual(1, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } { const string prefix = "#unchair"; const string args = user1; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should have correct error message and added to list. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(4, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // User should no longer be a chair. Assert.AreEqual(1, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } }
public void ChairCanUnchairThemSelfTest() { // Chair 1 user. { const string prefix = "#chair"; const string args = user1; const MeetingAction action = MeetingAction.Chair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); // Owner is chair by default. ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); // Should be a successful parse. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(1, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); // New chair should show up in list. Assert.AreEqual(2, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); Assert.IsTrue(uut.Chairs.Contains(user1)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } // Unchair themself. { const string prefix = "#unchair"; const string args = user1; const MeetingAction action = MeetingAction.Unchair; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); // Owner is chair by default. ParseMessageResult result = this.uut.ParseMessage(msg, user1, this.testTime); // Should be a successful parse. Assert.AreEqual(ParseMessageResult.Success, result); Assert.AreEqual(2, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), user1); // No longer should appear in list. Assert.AreEqual(1, uut.Chairs.Count()); Assert.IsTrue(uut.Chairs.Contains(owner)); // Other lists should be empty Assert.AreEqual(0, uut.SilencedUsers.Count); Assert.AreEqual(0, uut.BannedUsers.Count); } }
public void SilenceVoiceTest() { // Make a standard message from a user AddAndCheckMessage( "Hello, world", 1, user1 ); void CheckLists() { Assert.AreEqual(0, this.uut.BannedUsers.Count); Assert.AreEqual(1, this.uut.Chairs.Count); Assert.IsTrue(this.uut.Chairs.Contains(owner)); } // User said something dumb, silence him! IMeetingMessage silenceMsg; { const string prefix = "#silence"; const string args = user1; const MeetingAction action = MeetingAction.Silence; const CommandRestriction restrict = CommandRestriction.ChairsOnly; silenceMsg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(silenceMsg, owner, this.testTime); Assert.AreEqual(ParseMessageResult.Success, result); CheckLists(); Assert.AreEqual(1, uut.SilencedUsers.Count); Assert.IsTrue(uut.SilencedUsers.Contains(user1)); // 2 Messages: the first message and the silence. Assert.AreEqual(2, uut.MeetingNotes.Count); CompareNotes(silenceMsg, uut.MeetingNotes.Last(), owner); } // Silence user message should not be added to the logs. { AddMessage( "Can you hear me?", user1, ParseMessageResult.UserIsSilenced ); CheckLists(); Assert.AreEqual(1, uut.SilencedUsers.Count); Assert.IsTrue(uut.SilencedUsers.Contains(user1)); // Most recent message should be the silence. Assert.AreEqual(2, uut.MeetingNotes.Count); CompareNotes(silenceMsg, uut.MeetingNotes.Last(), owner); } // Unsilence the user. { const string prefix = "#voice"; const string args = user1; const MeetingAction action = MeetingAction.Voice; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, owner, this.testTime); Assert.AreEqual(ParseMessageResult.Success, result); CheckLists(); Assert.AreEqual(0, uut.SilencedUsers.Count); // 3 Messages: now including the voice message. Assert.AreEqual(3, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), owner); } // User should now be able to chat. AddAndCheckMessage( "Hello, world, again!", 4, user1 ); }
public void CanNotSilenceOwnerOrChairTest() { // Make user1 a chair. AddChairMessage(user1, owner); // Sanity check Assert.IsTrue(this.uut.Chairs.Contains(user1)); void CheckLists() { Assert.AreEqual(0, this.uut.BannedUsers.Count); Assert.AreEqual(0, this.uut.SilencedUsers.Count); Assert.AreEqual(2, this.uut.Chairs.Count); Assert.IsTrue(this.uut.Chairs.Contains(owner)); Assert.IsTrue(this.uut.Chairs.Contains(user1)); } // Make sure we can not silence an owner. { const string prefix = "#silence"; const string args = owner; const MeetingAction action = MeetingAction.Silence; const CommandRestriction restrict = CommandRestriction.ChairsOnly; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, user1, this.testTime); // Error message is the generic "Can not do this to chair", even if we try // to silence the owner. It just makes things easier that way. Assert.AreEqual(ParseMessageResult.CanNotDoThisToChair, result); CheckLists(); // 2 Messages: the first chair and the failed silence attempt. Assert.AreEqual(2, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), user1); } // Make sure a not-chair can not silence a chair. { const string prefix = "#silence"; const string args = user1; const MeetingAction action = MeetingAction.Silence; const CommandRestriction restrict = CommandRestriction.Anyone; IMeetingMessage msg = MakeMessage( prefix, args, action, restrict ); ParseMessageResult result = this.uut.ParseMessage(msg, user2, this.testTime); Assert.AreEqual(ParseMessageResult.CanNotDoThisToChair, result); CheckLists(); // 3 Messages: the first chair and the failed silence attempt. Assert.AreEqual(3, uut.MeetingNotes.Count); CompareNotes(msg, uut.MeetingNotes.Last(), user2); } // Make sure chair and owner can still chat AddAndCheckMessage( "Owner Check", 4, owner ); AddAndCheckMessage( "Chair Check", 5, user1 ); }
// ---------------- Functions ---------------- /// <summary> /// Parses the message and updates the meeting notes as needed. /// </summary> /// <param name="msg">The message received.</param> /// <param name="user">Who send the message?</param> /// <param name="timestamp"> /// The timestamp the message was sent. /// Set to null for <see cref="DateTime.UtcNow"/> /// </param> public ParseMessageResult ParseMessage(IMeetingMessage msg, string user, DateTime?timestamp = null) { user = user.ToLower(); // Do not add to the meeting notes if the user who sent the message // is banned or silenced. if (this.bannedUsers.Contains(user) || this.silencedUsers.Contains(user)) { return(ParseMessageResult.UserIsSilenced); } else if (msg.MeetingAction == MeetingAction.Help) { // No need to add help messages to the meeting notes. return(ParseMessageResult.Success); } MeetingNote note = new MeetingNote { MeetingAction = msg.MeetingAction, TimeStamp = timestamp ?? DateTime.UtcNow, UserName = user }; // If our action is unknown, so just a standard message, // there is no command prefix, the our message becomes the command args. if (msg.MeetingAction == MeetingAction.Unknown) { note.Message = msg.CommandArgs; } // Otherwise, our full message is both the command prefix and the full arguments. else { note.Message = $"{msg.CommandPrefix} {msg.CommandArgs}"; } this.meetingNotes.Add(note); ParseMessageResult?restrictionResult = this.TryCheckRestriction(msg, user); if (restrictionResult != null) { // If a user does not have permission, // the message they sent simply becomes a standard message, // and will not be highlighted in the meeting notes. // // ... My opinion is that it should show up in the meeting notes // because I think it is important to show intent of all meeting goers. A chair can purge // a user if they feel like they are being annoying. note.MeetingAction = MeetingAction.Unknown; // Stop here and return if there is a restriction. return(restrictionResult.Value); } // If there is no restriction, proceed with the parsing. ParseMessageResult result; switch (msg.MeetingAction) { case MeetingAction.Chair: result = HandleChair(msg); break; case MeetingAction.Unchair: result = HandleUnChair(msg); break; case MeetingAction.Purge: result = HandlePurge(msg); break; case MeetingAction.Voice: result = HandleVoice(msg); break; case MeetingAction.Silence: result = HandleSilence(msg); break; case MeetingAction.Banish: result = HandleBan(msg); break; default: // All other comamnds to not need special handling, // return success. result = ParseMessageResult.Success; break; } // If we made it this far, success! return(result); }