Exemplo n.º 1
0
        /// <summary>
        /// Handle a failed outbound message that a plugin expects a reply for.
        /// </summary>
        /// <param name="er"></param>
        public void parseFailedReply(ExpectedReply er)
        {
            expectedReplies.Remove(er);
            Modules.RobotoModuleTemplate pluginToCall = null;

            foreach (Modules.RobotoModuleTemplate plugin in settings.plugins)
            {
                if (er.pluginType == plugin.GetType().ToString())
                {
                    //stash these for calling outside of the "foreach" loop. This is so we can be sure it is called ONCE only, and so that we can remove
                    //the expected reply before calling the method, so any post-processing works smoother.
                    pluginToCall = plugin;
                }
            }
            //now send it to the plugin (remove first, so any checks can be done)
            if (pluginToCall == null)
            {
                Roboto.log.log("Expected Reply wasnt on the stack - probably sent in immediate-mode! Couldnt remove it", logging.loglevel.normal);
            }
            else
            {
                bool pluginProcessed = pluginToCall.replyReceived(er, null, true);

                if (!pluginProcessed)
                {
                    Roboto.log.log("Plugin " + pluginToCall.GetType().ToString() + " didnt process the message it expected a reply to!", logging.loglevel.high);
                    throw new InvalidProgramException("Plugin didnt process the message it expected a reply to!");
                }
            }
        }
Exemplo n.º 2
0
        public bool parseExpectedReplies(message m)
        {
            //are we expecteing this?
            bool processed = false;

            Modules.RobotoModuleTemplate pluginToCall = null;
            ExpectedReply er = null;

            try
            {
                foreach (ExpectedReply e in expectedReplies)
                {
                    //we are looking for direct messages from the user where c_id = m_id, OR reply messages where m_id = reply_id
                    //could trigger twice if we f****d something up - dont think this is an issue but checking processed flag for safety
                    if (!processed && e.isSent() && m.userID == e.userID)
                    {
                        if (m.chatID == e.userID || m.replyMessageID == e.outboundMessageID)
                        {
                            //find the plugin, send the expectedreply to it
                            foreach (Modules.RobotoModuleTemplate plugin in settings.plugins)
                            {
                                if (e.isOfType(plugin.GetType()))
                                {
                                    //stash these for calling outside of the "foreach" loop. This is so we can be sure it is called ONCE only, and so that we can remove
                                    //the expected reply before calling the method, so any post-processing works smoother.
                                    pluginToCall = plugin;
                                    er           = e;
                                }
                            }
                            processed = true;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Roboto.log.log("Error matching incoming message to plugin - " + e.ToString(), logging.loglevel.critical);
            }


            if (processed)
            {
                expectedReplies.Remove(er);
                //now send it to the plugin (remove first, so any checks can be done)
                try
                {
                    bool pluginProcessed = pluginToCall.replyReceived(er, m);

                    if (pluginProcessed)
                    {
                        //reset our chat timer
                        chat c = getChat(er.chatID);
                        c.resetLastUpdateTime();
                    }
                    else
                    {
                        throw new InvalidProgramException("Plugin didnt process the message it expected a reply to!");
                    }
                }
                catch (Exception e)
                {
                    Roboto.log.log("Error calling plugin " + pluginToCall.GetType().ToString() + " with expected reply. " + e.ToString(), logging.loglevel.critical);
                }

                /*/are there any more messages for the user? If so, find & send
                 * ExpectedReply messageToSend = null;
                 * foreach (ExpectedReply e in expectedReplies)
                 * {
                 *  if (e.userID == m.userID)
                 *  {
                 *      if (messageToSend == null || e.timeLogged < messageToSend.timeLogged)
                 *      {
                 *          messageToSend = e;
                 *      }
                 *
                 *  }
                 * }
                 *
                 * //send it
                 * //note that the plugin might send an urgent message during this processing that may have jumped the queue (using trySendImmediate param)
                 * if ( !userHasOutstandingMessages(m.userID) && messageToSend != null)
                 * {
                 *  messageToSend.sendMessage();
                 *  //make sure we are in a safe state. This will make sure if we sent a message-only, that the next message(s) are processed.
                 *  expectedReplyHousekeeping();
                 * }
                 */
                expectedReplyHousekeeping();
            }
            return(processed);
        }