To create new wiki account, please join us on #znc at Libera.Chat and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.

Writing modules

From ZNC
Revision as of 14:06, 17 December 2011 by DarthGandalf (talk | contribs) (Created page with "{{Languages}} === Overview === * Create your own module.cpp file (you can look into the sample module for help) * #include <main.h> and <Modules.h> * Create a new class d...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

  • Create your own module.cpp file (you can look into the sample module for help)
  • #include <main.h> and <Modules.h>
  • Create a new class derived from CModule overriding any Module Hooks 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) (See Compiling modules)
  • Place the .so file into your ~/.znc/modules directory !!!WARNING!!! if you overwrite a .so file while znc has it loaded, it can and probably will 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 CString& sCommand) {
        if (sCommand.Token(0).CaseCmp("HELP") == 0) {
            PutModule("I'd like to help, but I am just an example module");
        } else {
            PutModule("Unknown command, try HELP");
        }
    }
};

MODULEDEFS(CExampleMod, "This is the description")

Output

<zncuser> test
<*example> Unknown command, try HELP
<zncuser> help
<*example> I'd like to help, but I am just an example module