예제 #1
0
 /// <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);
 }
예제 #2
0
        /// <summary>
        /// Takes in the ParsedMessage and sends a message back to the sender with a message containing the description for the specified plugin
        /// </summary>
        /// <param name="message">Message containing information</param>
        /// <param name="service">Service to send/recieve messages through</param>
        /// <param name="controller">Database to pull from</param>
        public void Run(ParsedMessage message, AWatcherService service, IDBController controller)
        {
            Message msg = new Message();
            StringBuilder fullMsg = new StringBuilder();
            if (message.Arguments.Count <= 0)
            {
                fullMsg.Append("Please specify which plugin you would like information about.");
            }
            else
            {
                try
                {
                    PluginDAO plugin = controller.RetrievePlugin(message.Arguments[0]);
                    if ((controller.GetAllEnabledGroupPlugins(message.Group.GroupID)).Contains(plugin))
                    {
                        fullMsg.Append(plugin.Name);
                        fullMsg.Append(": ");
                        fullMsg.Append(plugin.Description);
                    }
                    else
                    {
                        fullMsg.Append("This plugin is not enabled for this group.");
                    }
                }
                catch (CouldNotFindException)
                {
                    fullMsg.Append("Can not find plugin ");
                    fullMsg.Append(message.Arguments[0]);
                }
            }

            msg.FullMessage = fullMsg.ToString();
            msg.Reciever.Add(message.Sender.PhoneEmail);
            service.SendMessage(msg);
        }
예제 #3
0
        /// <summary>
        /// Takes in the ParsedMessage and makes appropriate calls before responding to user
        /// </summary>
        /// <param name="message">Message containing information</param>
        /// <param name="service">Service to send/recieve messages through</param>
        /// <param name="controller">Database to pull from</param>
        public void Run(ParsedMessage message, AWatcherService service, IDBController controller)
        {
            Message msg = new Message();
            StringBuilder fullMsg = new StringBuilder();

            // Only reply to the user if it is valid.  Else, they can abuse the system
            if (message.Arguments.Count > 0
                // Also make sure they are not trying to bypass us by not going to the verification page
                && !message.Arguments[0].Equals("-1"))
            {
                try
                {
                    UserDAO user = controller.GetUserByVerificationCode(message.Arguments[0]);
                    if (user != null)
                    {
                        // Set their wanted phone email
                        user.PhoneEmail = message.Sender.PhoneEmail;
                        // Update our user
                        controller.UpdateUser(user);
                        // Reset verification to nothing
                        controller.SetVerificationCodeForUser(null, user);
                        fullMsg.Append("You have successfully registered with Text2Share. Thank you!");
                    }
                }
                catch (Exception ex)
                {
                    return;
                }
            }

            msg.FullMessage = fullMsg.ToString();
            msg.Reciever.Add(message.Sender.PhoneEmail);
            service.SendMessage(msg);
        }
예제 #4
0
        /// <summary>
        /// Takes in the ParsedMessage and sends a message back to the sender with a message 
        /// listing the enabled plugins for the group
        /// </summary>
        /// <param name="message">Message in error to be handled</param>
        /// <param name="service">Service to send/recieve messages through</param>
        public void Run(ParsedMessage message, AWatcherService service, IDBController controller)
        {
            Message msg = new Message();
            StringBuilder fullMsg = new StringBuilder();
            bool isModerator = message.Group.Moderators.Contains(message.Sender);
            bool isOwner = message.Group.Owner.Equals(message.Sender);

            // Put the group tag for
            fullMsg.Append(message.Group.GroupTag);
            fullMsg.Append(": \n");

            bool first = true;
            foreach (PluginDAO d in message.Group.EnabledPlugins)
            {
                if (d.Access == PluginAccess.STANDARD ||
                    (d.Access == PluginAccess.MODERATOR && (isModerator || isOwner)))
                {
                    if (!d.Name.Equals("error", StringComparison.OrdinalIgnoreCase))
                    {
                        if (!first)
                            fullMsg.Append(", ");
                        // Make it look pretty
                        fullMsg.Append(System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(d.Name.ToLower()));
                        first = false;
                    }
                }
            }
            msg.FullMessage = fullMsg.ToString();
            msg.Reciever.Add(message.Sender.PhoneEmail);
            service.SendMessage(msg);
        }
예제 #5
0
 /// <summary>
 /// Takes in the ParsedMessage and sends a message back to the sender with a specified detailed message about the error
 /// </summary>
 /// <param name="message">Message in error to be handled</param>
 /// <param name="service">Service to send/recieve messages through</param>
 public void Run(ParsedMessage message, AWatcherService service, IDBController controller)
 {
     Message msg = new Message();
     msg.FullMessage = message.ContentMessage;
     msg.Reciever.Add(message.Sender.PhoneEmail);
     service.SendMessage(msg);
 }
예제 #6
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);
            }
        }
예제 #7
0
        /// <summary>
        /// Takes in the info from the moderator/owner and removes a user from the group
        /// </summary>
        /// <param name="message">Message in error 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();

            if (message.Arguments.Count > 0 && message.Arguments[0].Substring(0, 3).ToUpper().Equals("OFF"))
            {
                controller.UnsuppressUser(message.Sender);
                msgSender.FullMessage = "You have been unsuppressed and can now receive messages. To suppress yourself, please reply SUPPRESS to disable messages.";
            }
            else
            {
                controller.SuppressUser(message.Sender);
                msgSender.FullMessage = "You have been suppressed. If you would like to unsuppress yourself, please reply SUPPRESS OFF to remove.";
            }
            msgSender.Reciever.Add(message.Sender.PhoneEmail);
            service.SendMessage(msgSender);
        }
예제 #8
0
        /// <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();

            if (message.Arguments.Count > 0 && message.Arguments[0].Substring(0, 3).ToUpper().Equals("YES"))
            {
                controller.DeleteUser(message.Sender);
                msgSender.FullMessage = "You have been removed from our system. Thank you for using our services.";
            }
            else
            {
                controller.SuppressUser(message.Sender);
                msgSender.FullMessage = "To remove yourself from Text2Share, please respond with STOP YES. Please keep in mind that this also deletes any groups you own and any plugins you have developed.";
            }
            msgSender.Reciever.Add(message.Sender.PhoneEmail);
            service.SendMessage(msgSender);
        }
예제 #9
0
        /// <summary>
        /// Takes in a message content to send to all users in group (excluding sender) 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 msg = new Message();
            msg.FullMessage = message.Group.GroupTag + ": " + message.ContentMessage;
            Message msgSender = new Message();
            msgSender.Reciever.Add(message.Sender.PhoneEmail);
            List<UserDAO> listPeeps = new List<UserDAO>();

            listPeeps.Add(message.Group.Owner);
            listPeeps.AddRange(message.Group.Users);
            listPeeps.AddRange(message.Group.Moderators);

            foreach(UserDAO u in listPeeps)
            {
                if(!u.Equals(message.Sender)&&!u.IsBanned&&!u.IsSuppressed)
                {
                    msg.Reciever.Add(u.PhoneEmail);
                }
            }
            msgSender.FullMessage = "Message sent successfully.";
            service.SendMessage(msgSender);
            service.SendMessage(msg);
        }
예제 #10
0
        private void registerFailedRun(ParsedMessage message, AWatcherService service, t2sDbLibrary.IDBController controller, Exception ex)
        {
            // Increment the error counter
            controller.IncrementPluginFailedAttemptCount(this.PluginDAO.PluginID);

            // Disable if above threshold
            int count = controller.GetPluginFailedAttemptCount(this.PluginDAO.PluginID);
            Logger.LogMessage(this.PluginDAO.Name + @": " + ex.Message, LoggerLevel.WARNING);
            if (count > LUADefinitions.DisablePluginAboveErrorCount)
            {
                controller.DisableGlobalPlugin(this.PluginDAO.PluginID);
                Logger.LogMessage(this.PluginDAO.Name + @": Plugin has been disabled", LoggerLevel.WARNING);
            }

            StringBuilder sb = new StringBuilder();
            sb.Append("LUAPlugin.cs: ");
            sb.Append(this.PluginDAO.Name);
            sb.Append(" failed (count=");
            sb.Append(count);
            sb.Append("/");
            sb.Append(LUADefinitions.DisablePluginAboveErrorCount);
            sb.Append("): ");
            sb.Append(ex.Message);
            Logger.LogMessage(sb.ToString(), LoggerLevel.WARNING);

            // Message the user saying it failed
            Message failedMsg = new Message(new string[1] { message.Sender.PhoneEmail }, "");
            failedMsg.FullMessage = "Plugin " + this.PluginDAO.Name + " has failed to run. Please try again later.";
            service.SendMessage(failedMsg);
        }
예제 #11
0
        /// <summary>
        /// takes a Message and create a ParsedMessage from it and adds it to the queue
        /// </summary>
        /// <param name="message"></param>
        public static ParsedMessage Parse(Message message, IDBController controller)
        {
            // Fix up the string a little
            message.FullMessage = message.FullMessage.Trim();

            ParsedMessage parsed = new ParsedMessage();
            TryFindSender(parsed, message, controller);

            parsed.Command = FindCommand(message.FullMessage, controller);
            parsed.ContentMessage = FindArguments(message.FullMessage, controller);
            if (!parsed.ContentMessage.Trim().Equals(String.Empty))
            {
                parsed.Arguments.AddRange(parsed.ContentMessage.Split(' '));
            }

            String groupId = FindGroup(message.FullMessage, controller);

            //Strip out any leading, trailing delimiters
            groupId = groupId.TrimStart(new char[] { MessageParser.delimiter });
            groupId = groupId.TrimEnd(new char[] { MessageParser.secondDelimiter });

            TryFindGroup(parsed, groupId, controller);

            // Set our type flag (by importance)
            if (parsed.Command.Equals("stop", StringComparison.OrdinalIgnoreCase)) {
                parsed.Type = ParsedMessage.ContentMessageType.STOP;
            }
            else if (parsed.Sender != null &&
                parsed.Sender.IsBanned)
            {
                parsed.Type = ParsedMessage.ContentMessageType.BAN;
            }
            else if (parsed.Command.Equals("register", StringComparison.OrdinalIgnoreCase))
            {
                // Since they are not in the database,
                // we need to make a temp UserDAO as the sender
                // and populate their phone email for the Register plugin
                parsed.Sender = new UserDAO();
                parsed.Sender.PhoneEmail = message.Sender;
                parsed.Type = ParsedMessage.ContentMessageType.REGISTER;
            }
            else if (parsed.Sender != null &&
                parsed.Sender.IsSuppressed)
            {
                parsed.Type = ParsedMessage.ContentMessageType.SUPPRESS;
            }
            else if (parsed.Sender == null)
            {
                parsed.Type = ParsedMessage.ContentMessageType.NO_SENDER;
            }
            else if (parsed.Command.Equals(String.Empty))
            {
                parsed.Type = ParsedMessage.ContentMessageType.NO_COMMAND;
            }
            else if (parsed.Group == null)
            {
                parsed.Type = ParsedMessage.ContentMessageType.NO_GROUP;
            }
            else
            {
                parsed.Type = ParsedMessage.ContentMessageType.VALID;
            }

            return parsed;
        }
예제 #12
0
 private static void TryFindSender(ParsedMessage parsed, Message message, IDBController controller)
 {
     try
     {
         parsed.Sender = controller.RetrieveUserByPhoneEmail(message.Sender);
     }
     catch (Exception ex)
     {
         if (ex is ArgumentNullException ||
             ex is CouldNotFindException)
         {
             parsed.Sender = null;
         }
         else
         {
             // Not an exception we deal with, throw so we don't hide bugs
             throw;
         }
     }
 }
예제 #13
0
 /// <summary>
 /// Sends a message through this watcher service
 /// </summary>
 /// <param name="message">Message to send</param>
 /// <returns>True is sending successful, false otherwise</returns>
 public abstract bool SendMessage(Message message);
예제 #14
0
 /// <summary>
 /// Sends a message through this watcher service
 /// </summary>
 /// <param name="message">Message to send</param>
 /// <param name="async">Send message asynchronously</param>
 /// <returns>True is sending successful, false otherwise</returns>
 public abstract bool SendMessage(Message message, bool async);
예제 #15
0
        public void TextBlank()
        {
            // Create our test message
            Message msg = new Message(this._user1.PhoneEmail, new string[0], "");

            //Tack on to text
            ParsedMessage pmsg = MessageParser.Parse(msg, this.stubbedController);

            // Assert.AreEqual(command, pmsg.Command, true);
            Assert.AreEqual("", pmsg.Command, true);
            Assert.AreEqual("", pmsg.ContentMessage);
            CollectionAssert.AreEquivalent(new List<string>(), pmsg.Arguments);

            // Check DAO's
            Assert.AreEqual(null, pmsg.Group);
            Assert.AreEqual(this._user1, pmsg.Sender);

            // Check type
            Assert.AreEqual(ParsedMessage.ContentMessageType.NO_COMMAND, pmsg.Type);
        }
예제 #16
0
        public static void __SendMessage(String hash, String toHash, String message)
        {
            if (message == null || message.Equals(String.Empty))
                return;

            LuaScriptingEngine.LUAPluginContainer container = LuaScriptingEngine.getPluginContainerByHash(hash);
            UserDAO toUser = null;
            if (toHash != null)
                toUser = container.hashToUser[toHash];

            if (toUser != null)
            {
                Message msg = new Message(new string[1] { toUser.PhoneEmail }, message.Substring(0, Math.Min(message.Length, LUAAPI.MAX_TEXT_SIZE_8BIT)));
                container.service.SendMessage(msg);
            }
        }