A way to communicate with modules #94

Open
opened 2026-10-05 03:58:37 +02:00 by adam · 5 comments
Owner

Right now if a module wants to tell you something, it has many ways to do that:

  1. CUtils::PrintMessage() can be used when ZNC is starting, so that we have a console where the message will be.
  2. PutModule() can be used if user is connected to ZNC via IRC.
  3. WebSock.GetSession()->AddError() for the case of web request.

It would make sense to have 1 special way for modules to give messages to user. And the system will show the message to the user in one of those 3 ways, depending on the current situation and how user did the request to the module (in case if the message is a reply to such request).

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Right now if a module wants to tell you something, it has many ways to do that: 1. CUtils::PrintMessage() can be used when ZNC is starting, so that we have a console where the message will be. 2. PutModule() can be used if user is connected to ZNC via IRC. 3. WebSock.GetSession()->AddError() for the case of web request. It would make sense to have 1 special way for modules to give messages to user. And the system will show the message to the user in one of those 3 ways, depending on the current situation and how user did the request to the module (in case if the message is a reply to such request). ## <bountysource-plugin> Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/670-a-way-to-communicate-with-modules?utm_campaign=plugin&utm_content=tracker%2F1759&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1759&utm_medium=issues&utm_source=github). </bountysource-plugin> <!-- github-sync-id:4007688 -->
Author
Owner

This method should also allow modules to take the response. This would allow znc-xmpp to speak to modules and get the response back to the correct location.

This method should also allow modules to take the response. This would allow znc-xmpp to speak to modules and get the response back to the correct location. <!-- github-comment-id:4999990 -->
Author
Owner

I forgot about the 4rd way - to assign a string to a special parameter in OnLoad() hook, and actually this string is shown to user in all those cases, in webadmin when user failed to load a module, in *status, in console.
But it works only when the module is loading, and it can't have several messages, like WebSock and CUtils do. And it can't distinguish error messages from success ones, like WebSock and CUtils do.

I forgot about the 4rd way - to assign a string to a special parameter in OnLoad() hook, and actually this string is shown to user in all those cases, in webadmin when user failed to load a module, in *status, in console. But it works only when the module is loading, and it can't have several messages, like WebSock and CUtils do. And it can't distinguish error messages from success ones, like WebSock and CUtils do. <!-- github-comment-id:5000068 -->
Author
Owner

OnLoad() can distinguish errors - either the module failed to load or it succeeded

anyway: WebSocks require special code anyway, so that special code can handle AddError(), too. I think no module uses CUtils::PrintMessage() and I don't think any module should. That leaves us with PutModule() for most normal (IRC) stuff, I guess.

OnLoad() can distinguish errors - either the module failed to load or it succeeded anyway: WebSocks require special code anyway, so that special code can handle AddError(), too. I think no module uses CUtils::PrintMessage() and I don't think any module should. That leaves us with PutModule() for most normal (IRC) stuff, I guess. <!-- github-comment-id:5002516 -->
Author
Owner
$ grep CUtils::Print *
autoaway.cpp:                   CUtils::PrintError("[" + GetModName() + ".so] Failed to Decrypt Messages");
saslauth.cpp:                           CUtils::PrintError("Ignoring invalid SASL pwcheck method: " + *it);
savebuff.cpp:                   CUtils::PrintError("[" + GetModName() + ".so] Failed to Decrypt [" + pChan->GetName() + "]");
``` $ grep CUtils::Print * autoaway.cpp: CUtils::PrintError("[" + GetModName() + ".so] Failed to Decrypt Messages"); saslauth.cpp: CUtils::PrintError("Ignoring invalid SASL pwcheck method: " + *it); savebuff.cpp: CUtils::PrintError("[" + GetModName() + ".so] Failed to Decrypt [" + pChan->GetName() + "]"); ``` <!-- github-comment-id:5005695 -->
Author
Owner

An OnModMsg(mod, msg) would be helpful if invoked when any module calls PutModule. The hook would able to process what is put by a module similar to how OnPrivMsg works.

I currently have the watch module setup and would like to be able to do something like the following so I could send the watch notices to a push module and receive them on my mobile device:

# push
OnModMsg(self, mod, msg):
    if mod.GetName() == "Watch":
        self.send_notification(msg)

The hook should be implemented in such a way that it need only be called from the module receiving the data and not explicitly sent from module sending the data.

An `OnModMsg(mod, msg)` would be helpful if invoked when any module calls `PutModule`. The hook would able to process what is put by a module similar to how `OnPrivMsg` works. I currently have the [watch](http://wiki.znc.in/Watch) module setup and would like to be able to do something like the following so I could send the watch notices to a push module and receive them on my mobile device: ``` # push OnModMsg(self, mod, msg): if mod.GetName() == "Watch": self.send_notification(msg) ``` The hook should be implemented in such a way that it need only be called from the module receiving the data and not explicitly sent from module sending the data. <!-- github-comment-id:229170463 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/znc#94