IRC功能困境
[编辑] 抱歉标题被关闭。我正在思考我遇到的另一个问题,并且不小心将两者交叉了。
大家好,我目前正在用 Python 编写 IRC 机器人骨架。
在提出问题之前,为了解释一些事情,我正在编写一个带有插件系统的 IRC 机器人,该机器人将接收信号(即,当收到消息时,会看到有人加入频道,...),并且为了调用插件中包含的这些函数,我将使用辅助方法,即如果我们看到一条消息,则调用 sawMessage
。 sawMessage
将使用 PluginManager
类等来定位哪些插件想要处理消息。我已经考虑好了整个系统。
我还为每个 IRC 操作提供了一个函数,即“doJoin”、“doPart”等,以便插件可以调用这些函数,而无需将套接字连接直接暴露给插件。 -- 这些函数是否应该自动调用适当的 sawMessage
、sawJoin
等?或者应该由插件在调用 doMessage
后调用 sawMessage
?我问的原因是因为如果 doMessage
调用 sawMessage
,并且 sawMessage
处理调用 doMessage
的内容,它可以在展开堆栈之前最终会递归很多次。
让插件负责调用 sawMessage
来通知其他插件的缺点是,插件可以选择不通知其他插件,而且如果插件确实调用了 sawMessage
函数,递归问题可能会再次出现。
我不知道如何解决这个问题。让doMessage
自动调用sawMessage
来通知其他插件似乎是一个很好的做法,但是如果插件总是存在由于递归而导致堆栈溢出的可能性设计不正确(即不响应其自己的消息),但如果插件无论如何都必须调用 sawMessage
,则存在同样的问题。
对此有什么想法/意见吗?我知道这不是一个直接的问题/答案,但我无法决定如何处理这个问题。通常,如果我只是编写一个小机器人供自己使用,我不会关心可能的递归问题。然而,我写这篇文章的目的是为了分发(我希望它成为下一个巨大的机器人,就像所有其他 IRC 机器人开发人员一样:D),并且我希望它能够正确制作。
谢谢!
[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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您需要在 发布/订阅 和 责任链。不幸的是我在这方面没有太多经验。恰好读到了相关的 最近的文章。
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.