Difference between revisions of "How to write Ackis Modules in D"

From Makers Local 256
Jump to: navigation, search
(Ackis Core: correct comments)
m (Ackis D IRC Client: fix more confusion)
Line 46: Line 46:
  
 
Reference the comments in this file for setting it up.
 
Reference the comments in this file for setting it up.
This section of the configuration file can currently be ignored, it is for future development:
+
This section of the configuration file allows channels to subscribe to events received from the core:
  
   subscribe match="LinkSyn: .*"/>
+
   <subscribe match="LinkSyn: .*"/>
  
 
Save your configuration file and compile  
 
Save your configuration file and compile  

Revision as of 11:23, 27 January 2010

Description

This page is meant as a how to guide for the beginner Ackis Module Programmer in the D programming language. The intention is to write this from a beginner level. No claims are made that this is the only way to approach writing an Ackis Module.

Setup

  • Have a flavor of linux running
  • Install build-essential, libmpfr-dev, and libgmp3-dev (required to build gdc)
  • Install gdc 4.3.1 via the instructions on goshawk's gdc page.
  • Install dsss (a D program requiring GDC to be built)
  • Install svn

About each development component

  • D is a programming language very similar to C++.
  • GDC is a front end D interface for GCC. This will translate the D syntax into something the GCC compiler can understand.
  • DSSS is a simple way to build your files. It will read through all of your 'import' lines in your code so that all you'll need to do is type "dsss build" in the same directory as your D program, and it will output your compiled program
  • svn is a source control system. svn makes it easy to retrieve the libraries that others have written that you'll need in order to compile an ackis module.

Retrieving Dependent Libraries

  • svn
    • In order for a D Ackis Module to compile, you're going to need some dependent libraries. The folders containing these libraries should be in the same directory as your D program's source code. You can retrieve these directories utilizing svn

Setting Up Ackis

Ackis Core

You will need to retrieve the ackis_core and client_dirc code from opticron's repository the same way you retrieved the supporting code for developing a module.

In the source code will be included a file: 'ackis.conf.sample'
Make a copy of this file and rename it to 'ackis.conf'
In the ackis.conf file there will be this line:

 <listener port="16668" address="127.0.0.1"/>

This line is telling the Ackis Core to watch a module and restart it as necessary, but this feature is still under development. It should not be relied upon and is not necessary for the functioning of the core.

 <module location="mod_sample" name="sample" desc="Sample Module"/>

It may be helpful to build in debug mode in order to watch the interactions between the core and the components

 dsss build -debug=2

Ackis D IRC Client

Make a copy of 'dirc.conf.sample' and rename it to 'dirc.conf'

Reference the comments in this file for setting it up. This section of the configuration file allows channels to subscribe to events received from the core:

 <subscribe match="LinkSyn: .*"/>

Save your configuration file and compile

 dsss build

It may be helpful to compile in debug mode in order to watch and confirm the interactions between the components:

 dsss build -debug=2 -debug=libackis

Development

Here is an example piece of code:

 // Hello World Module
 module mod_helloWorld;
 
 import libackis.ackiscomponent;
 
 int main (char[][]argc) {
 	AckisComponent ackis = new AckisComponent("mod_helloWorld");
 	ackis.register("^helloWorld.*",&helloWorld);
 	ackis.regHelp("helloWorld","Have bot say hi to you.");
 	
 	ackis.runProtocol();
 	return 0;
 }
 
 void helloWorld(AckisComponent ackis,char[]respid,char[]data,char[]type) {
   ackis.sendResponse(respid,"Hello World!");
 }

Breakdown of Code

 	ackis.register("^helloWorld.*",&helloWorld);
 	ackis.regHelp("helloWorld","Have bot say hi to you.");

The ".register" line is registering a callback. This is telling Ackis what function in your module to call when it sees a command (like '!helloWorld') in the channel.

The ".regHelp" is registering a specific help function built into Ackis, so that when the user types '!help helloWorld" Ackis will reply with your custom help message. In this example, the reply from Ackis would be "Have bot say hi to you."

       ackis.runProtocol();

The above line gives control to the ackisComponent class. Internally, this class is running a loop that does not exit unless the connection is lost, at which point the module exits. At the moment, this means that if connection to Ackis is lost, the running module will exit. Brainstorming is in process for a reconnection capability for future versions of the ackisComponent class. Omegix 16:20, 25 January 2010 (CST)