Beispiel #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!");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Load all the plugins BEFORE loading the settings file. We need to be able to enumerate the extra types when loading the XML.
        /// </summary>
        public static void loadPlugins()
        {
            //load all plugins by looking for all objects derived from the abstract class.
            Assembly currAssembly = Assembly.GetExecutingAssembly();

            foreach (Type type in currAssembly.GetTypes())
            {
                if (type.IsClass && !type.IsAbstract
                    //is this a subclass of the module template
                    && type.IsSubclassOf(typeof(Modules.RobotoModuleTemplate))
                    //is our plugin filter disabled?
                    && (Roboto.pluginFilter.Count == 0
                        //or is this plugin listed?
                        || Roboto.pluginFilter.Contains(type.Name))
                    )
                {
                    Roboto.log.log("Registering plugin " + type.Name, logging.loglevel.low);

                    if (pluginExists(type))
                    {
                        //TODO - this is going to be looking for the template, not the datatemplate!
                        //Console.WriteLine("Registering plugin " + type.Name);
                    }
                    else
                    {
                        Modules.RobotoModuleTemplate plugin = (Modules.RobotoModuleTemplate)Activator.CreateInstance(type);
                        Roboto.log.log("Added " + plugin.GetType().ToString(), logging.loglevel.low);
                        plugins.Add(plugin);
                        plugin.init();
                    }
                }
            }
        }
Beispiel #3
0
        public static void getQuietTimes(long chatID, out TimeSpan startQuietHours, out TimeSpan endQuietHours)
        {
            chat c = Roboto.Settings.getChat(chatID);
            mod_standard_chatdata chatData = c.getPluginData <mod_standard_chatdata>();

            if (chatData == null)
            {
                //create the chat data. Get the plugin instance (we are in a static method).
                RobotoModuleTemplate plugin = settings.getPlugin(typeof(mod_standard));
                plugin.initChatData(c);
                chatData = c.getPluginData <mod_standard_chatdata>();
            }

            startQuietHours = chatData.quietHoursStartTime;
            endQuietHours   = chatData.quietHoursEndTime;
        }
Beispiel #4
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)
            {
                if (er == null)
                {
                    Roboto.log.log("Expected reply found, but er not available.", logging.loglevel.critical);
                    return(true);
                }
                if (pluginToCall == null)
                {
                    Roboto.log.log("Expected reply plugin found, but not available.", logging.loglevel.critical);
                    return(true);
                }

                //now send it to the plugin (remove first, so any checks can be done)
                expectedReplies.Remove(er);

                try
                {
                    bool pluginProcessed = pluginToCall.replyReceived(er, m);

                    if (pluginProcessed)
                    {
                        //reset our chat timer
                        chat c = getChat(er.chatID);
                        if (c != null)
                        {
                            c.resetLastUpdateTime();
                        }
                        else
                        {
                            Roboto.log.log("Chat not found for update.", logging.loglevel.critical);
                        }
                    }
                    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);
                }

                //Do any follow up er actions.
                expectedReplyBackgroundProcessing();
            }
            return(processed);
        }