/// <summary>
 /// Takes in the info from the moderator/owner and removes a user from the group
 /// </summary>
 /// <param name="message">Message to be handled</param>
 /// <param name="service">Service to send/recieve messages through</param>
 public void Run(ParsedMessage message, AWatcherService service, IDBController controller)
 {
     Message msgSender = new Message();
     msgSender.Reciever.Add(message.Sender.PhoneEmail);
     Message msgRemovedUser = new Message();
     try
     {
         UserDAO userToBeRemoved = controller.RetrieveUserByUserName(message.ContentMessage);
         if (userToBeRemoved == null || !message.Group.Users.Contains(userToBeRemoved))
         {
             msgSender.FullMessage = "Failed to remove " + message.Arguments[0] + " from the group "
                 + message.Group.GroupID + ". Please check user/group and try again.";
         }
         else
         {
             msgRemovedUser.Reciever.Add(userToBeRemoved.PhoneEmail);
             controller.RemoveMemberFromGroup(message.Group.GroupID, userToBeRemoved.UserID);
             msgSender.FullMessage = "Successfully removed " + message.ContentMessage + " from the group "
                 + message.Group.Name + ".";
             msgRemovedUser.FullMessage = "You have been removed from group " + message.Group.Name + ".";
             service.SendMessage(msgRemovedUser);
         }
     }
     catch (Exception)
     {
         msgSender.FullMessage = "Failed to remove " + message.ContentMessage + " from the group "
             + message.Group.GroupID + ". Please check user/group and try again.";
     }
     msgSender.Reciever.Add(message.Sender.PhoneEmail);
     service.SendMessage(msgSender);
 }
Beispiel #2
0
        /// <summary>
        /// Takes in a message content to send to a specified user and replies to sender with confirmation
        /// </summary>
        /// <param name="message">Message to be handled</param>
        /// <param name="service">Service to send/recieve messages through</param>
        public void Run(ParsedMessage message, AWatcherService service, IDBController controller)
        {
            Message msgReceiver = new Message();
            String msgToSend = "";
            for (int i = 1; i < message.Arguments.Count; i++)
            {
                msgToSend += message.Arguments[i];
            }
            msgReceiver.FullMessage = msgToSend;

            Message msgSender = new Message();
            msgSender.Reciever.Add(message.Sender.PhoneEmail);

            UserDAO receiver = null;
            try
            {
                receiver = controller.RetrieveUserByUserName(message.Arguments[0]);
            }
            catch (CouldNotFindException)
            {
                msgSender.FullMessage = "Not a valid user. Please check their username and retry.";
                service.SendMessage(msgSender);
            }

            List<UserDAO> listPeeps = new List<UserDAO>();
            listPeeps.AddRange(message.Group.Users);
            listPeeps.AddRange(message.Group.Moderators);
            listPeeps.Add(message.Group.Owner);

            if (!listPeeps.Contains(receiver) || receiver == null || receiver.IsBanned)
            {
                msgSender.FullMessage = "Not a valid user. Please check their username and retry.";
                service.SendMessage(msgSender);
            }
            else if(receiver.IsSuppressed)
            {
                msgSender.FullMessage = "User has suppressed messages.";
                service.SendMessage(msgSender);
            }
            else
            {
                msgReceiver.Reciever.Add(receiver.PhoneEmail);
                bool sent = service.SendMessage(msgReceiver);
                if (sent)
                {
                    msgSender.FullMessage = "Message sent successfully.";
                }
                else
                {
                    msgSender.FullMessage = "Message was unable to send to user.";
                }
                service.SendMessage(msgSender);
            }
        }