[EDIT] Sorry about the title being off. I was thinking of a different problem I was having, and accidentally crossed the two.
Hi everyone, I'm writing my IRC bot skeleton in Python currently.
To explain a couple things before I ask my question, I am writing a IRC bot complete with a plug-in system that will receive signals (i.e. when a message is received, a person was seen joining a channel, ...), and to call these functions contained in the plug-in, I will be using a helper method, i.e. if we saw a message, call sawMessage
. sawMessage
will locate which plug-ins want to handle messages, using a PluginManager
class, etc. I have the whole system thought out.
I also have a function for each IRC action, i.e. "doJoin", "doPart", etc. so that plug-ins can call these without me exposing my socket connection to the plug-ins directly. -- Should these functions automatically call the appropriate sawMessage
, sawJoin
, etc. ? Or should it be up to the plug-in to call sawMessage
after calling doMessage
? The reason I am asking is because if doMessage
calls sawMessage
, and sawMessage
processes something that calls doMessage
, it can end up recursing a lot before unwinding the stack.
The drawbacks of making the plug-in responsible for calling sawMessage
to notify the other plug-ins is that the plug-in would have a choice of NOT notifying the other plug-ins, and also that if the plug-in DOES call the sawMessage
function, the recursion issue could pop right back up.
I'm not sure how to resolve this. It seems like good practice to make doMessage
automatically call sawMessage
to notify other plug-ins, but there is always the possibility of a stack overflow due to recursion if the plug-in is not designed properly (i.e. not to respond to it's own messages), but if the plug-in has to call sawMessage
anyway, the same issue is there.
Got any thoughts/opinions on this? I know it's not a straight-out question/answer, but I can't decide what to do with this. Ordinarily, if I was just writing a small bot for my own usage, I wouldn't care about a possible recursion problem. However, I am writing this for the purpose of distribution (I want this to be the next HUGE bot, just like every other IRC bot developer :D ) and I want it made properly.
Thanks!
It sounds like you need to decide between or read up more on Publish/subscribe and Chain of Responsibility. Unfortunately I don't have much experience in this area. Just happened to read a related article recently.