Esempio n. 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);
 }
Esempio n. 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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 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);
 }
Esempio n. 6
0
        public MessageController(AWatcherService Watcher, IDBController Controller)
        {
            this.queue = new BlockingQueue<ParsedMessage>();
            this.watcher = Watcher;
            this.controller = Controller;

            this.watcher.RecievedMessage += Watcher_RecievedMessage;
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
 void Watcher_RecievedMessage(object sender, AWatcherService.WatcherServiceEventArgs e)
 {
     Logger.LogMessage(@"Received from " + e.MessageObj.Sender + ": \n" + e.MessageObj.FullMessage, LoggerLevel.DEBUG);
     this.putNextMessage(MessageParser.Parse(e.MessageObj, this.controller));
 }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public void Run(ParsedMessage message, AWatcherService service, t2sDbLibrary.IDBController controller)
        {
            String engineHash = null;

            Task LuaCodeTask = null;
            try
            {
                // Get to a clean state
                loadNewLuaEngine();

                // Register our plugin so we can call C# methods
                engineHash = LuaScriptingEngine.registerPlugin(this, message, service, controller, this.LuaEngine);

                Thread LuacodeThread = null;
                // Run the script
                LuaCodeTask = new Task(() =>
                {
                    LuacodeThread = Thread.CurrentThread;
                    RunLuaCode(this.LuaEngine, this.ScriptFileLoc);
                });
                LuaCodeTask.Start();

                bool finished = true;

                try
                {
                    if (!LuaCodeTask.Wait(LUADefinitions.MaxRunTime))
                    {
                        finished = false;

                        // Sorry Lua Code, gotta die now
                        LuacodeThread.Abort();
                    }
                }
                catch (AggregateException ex)
                {
                    if (ex.InnerExceptions.Count > 0)
                        throw ex.InnerExceptions[0];
                }

                if (!finished)
                    registerFailedRun(message, service, controller,
                        new LuaException("Lua script ran too long. Max runtime is: " + LUADefinitions.MaxRunTime.ToString()));
            }
            catch (LuaException ex)
            {
                registerFailedRun(message, service, controller, ex);
            }
            finally
            {
                if (engineHash != null)
                {
                    if (!LuaScriptingEngine.unregisterPlugin(engineHash))
                        Logger.LogMessage("LUAPlugin.Run: Couldn't unregister plugin! (" + this.PluginDAO.Name + ")", LoggerLevel.SEVERE);
                }
            }
        }
 public MessageControllerOverride(AWatcherService Watcher, IDBController Controller)
     : base(Watcher, Controller)
 {
 }
Esempio n. 15
0
 /// <summary>
 /// Constructs a list of plug-ins and initializes the library
 /// </summary>
 public PluginLibrary(MessageController messageController, AWatcherService Service, IDBController idbController)
 {
     this.messageController = messageController;
     this.service = Service;
     this.idbController = idbController;
 }
Esempio n. 16
0
 public void Run(ParsedMessage message, AWatcherService service, t2sDbLibrary.IDBController controller)
 {
     throw new NotImplementedException();
 }