IRC功能困境

发布于 2024-11-11 19:56:56 字数 1138 浏览 5 评论 0原文

[编辑] 抱歉标题被关闭。我正在思考我遇到的另一个问题,并且不小心将两者交叉了。

大家好,我目前正在用 Python 编写 IRC 机器人骨架。

在提出问题之前,为了解释一些事情,我正在编写一个带有插件系统的 IRC 机器人,该机器人将接收信号(即,当收到消息时,会看到有人加入频道,...),并且为了调用插件中包含的这些函数,我将使用辅助方法,即如果我们看到一条消息,则调用 sawMessagesawMessage 将使用 PluginManager 类等来定位哪些插件想要处理消息。我已经考虑好了整个系统。

我还为每个 IRC 操作提供了一个函数,即“doJoin”、“doPart”等,以便插件可以调用这些函数,而无需将套接字连接直接暴露给插件。 -- 这些函数是否应该自动调用适当的 sawMessagesawJoin 等?或者应该由插件在调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

去了角落 2024-11-18 19:56:56

听起来您需要在 发布/订阅责任链。不幸的是我在这方面没有太多经验。恰好读到了相关的 最近的文章

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文