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

Difference between revisions of "Writing modules"

From ZNC
Jump to: navigation, search
(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...")
 
Line 2: Line 2:
 
=== Overview ===
 
=== Overview ===
  
* Create your own module.cpp file (you can look into the [[sample]] module for help)
+
* Look at ZNC API [http://people.znc.in/~psychon/znc/doc here] or directly in ZNC headers
* #include <main.h> and <Modules.h>
+
* Create your own module.cpp file (you can look into the [[sample]] module's source for help)
* Create a new class derived from CModule overriding any [[Module Hooks]] that you need
+
* #include <znc/main.h> and <znc/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
 
* 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]])
 
* 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!'''
 
* 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
 
 
  
 
[[Category:Modules]]
 
[[Category:Modules]]

Revision as of 01:03, 6 October 2012

Overview

  • Look at ZNC API here or directly in ZNC headers
  • Create your own module.cpp file (you can look into the sample module's source for help)
  • #include <znc/main.h> and <znc/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!