[Home]
-
[Project Page]
Overview
- Create your own module.cpp file
- #include <main.h> and <Modules.h>
- Create a new class derived from CModule overriding any ModuleHooks that you need
- Be sure to add the macro call MODULEDEFS(CYourClass) at the END of the file
- Compile your module into a shared object (.so file)
- The easy way to compile is to use the znc-buildmod script as long as your module is a single .cpp file
- alternative is to manually compile using znc-config to ensure that you are using the same flags and libs that the znc engine was compiled with
- g++ `znc-config --cflags` `znc-config --include` `znc-config --libs` -shared -o example.so example.cpp
- Place the .so file into your ~/.znc/modules directory. You can load it with /msg *status loadmod foo. If you overwrite a .so file while znc has it loaded it can crash znc, /msg *status unloadmod foo first!
Code
#include <main.h>
#include <Modules.h>
class CExampleMod : public CModule {
public:
MODCONSTRUCTOR(CExampleMod) {}
virtual ~CExampleMod() {}
virtual void OnModCommand(const string& sCommand) {
if (strcasecmp(sCommand.c_str(), "HELP") == 0) {
PutModule("I'd like to help, but I am just an example");
} else {
PutModule("Unknown command, try HELP");
}
}
};
MODULEDEFS(CExampleMod)
Output
<zncuser> test
<*example> Unknown command, try HELP
<zncuser> help
<*example> I'd like to help, but I am just an example