tyler bot documentation

Beware this documentation isn't yet complete. Use only as a guide.
Index
  1. Modules
    1. Overview
    2. Python Modules
    3. Perl Modules
  2. Hooking API (trod)
    1. addhook()
    2. clearhooks()
    3. dohooks()
    4. registerhook()
    5. Table of hookable functions
  3. Global utilities (tutil)
    1. ircsend()
    2. ircmsg()
    3. ircmultimsg()
    4. ircaction()
    5. ircnotice()
    6. ircjoin()
    7. ircpart()
    8. ircquit()
    9. ircwho()
    10. ircnick()
    11. irckick()
    12. irckill()
    13. ircmode()
    14. ircop()
    15. ircban()
    16. irctopic()
    17. ircaway()
    18. ircoper()
    19. ircinvite()
    20. ctcpsend()
    21. ctcpmsg()
    22. ctcpversion()
    23. ctcpping()
    24. ctcpuserinfo()
    25. ctcpclientinfo()
    26. ctcptime()
    27. ctcpfinger()
    28. tylercodestats()
  4. Help Routines (thelp)
    1. hashelp()
    2. addhelp()
    3. removehelp()
    4. clearhelp()
    5. gethelp()
    6. helpcnt()
  5. tyler API / defination (tyler)
    1. class defination
    2. attributes
    3. operations
  6. Perl Module Scripting
    1. Limitations

Modules

So the question is, how can developers write modules for tyler? In this document I hope to provide enough resources so developers can easily write their own modules.

Overview

Python modules

Most of tylers modules are python modules. They are wrote in python and natively take advantage of the framework tyler provides. The minimal requirement for a module is simply, python code which does anything that doesn't require user-input from anything except an IRC network. You don't *have* to import anything and you aren't restricted in what you can do.

As part of development of Python modules for tyler, it's recommended you set the python __author__ global variable. This will allow the .author command of tyler to return author information about the module. This is strongly recommended for making a uniform program.

Lets look at an example

import tutil, trod
def helloworld_load(args, env):
	# lets... quit in our "hello" world <3
	tutil.ircquit(args["sck"], "Good bye cruel world")
trod.addhook("helloworld", "load", helloworld_load)

As soon as this module is loaded, the tyler bot will immidiately quit the IRC network with the reason "Good bye cruel world". Not only does this demonstrate how you write a very simple module using tutil and trod (documented below), but it also illustrates how you should make sure you know what the module you're loading actually does!

Lets see an even simpler example

import sys
sys.system("echo hello everyone on this system! | wall")

This module demonstrates functionality that doesn't even use the IRC bot at all - except to of course load it. It simply executes a shell command on the local machine. It broadcasts a message to all connected terminatals on the local machine saying "hello everyone on this system!". Should note that this is a GNU style command, and probably wont work on most machines, but as a demonstration I hope it conveys precise what you could potentially do with tyler modules.

Perl modules

See Perl Module Scripting

Hooking API (module: trod)

to use the hooking API, you must first import the trod module
import trod

addhook()

to hook a hootable event, you must call addhook() which resides within the trod module.
trod.addhook(str modulename, str hookevent, function hookhandler)
def myhookhandler(args, env):
in the hookhandler 2 arguements must be outlined, the first arguement will contain event-specific arguements, this is also in the list of hookable events below and is of type dict. the other arguement named 'env' is a reference to the calling tyler instance. to see what entities you may access through this see the section on tyler API

clearhooks()

trod.clearhooks(str modulename)
if for some reason you deside you want to clear all the hooks you have made, you can call clearhooks(). clearhooks() takes one argument which MUST be the name of your module.

dohooks()

if for some reason you deside you want to make your module trigger events manually you may use dohooks.
trod.dohooks(str eventname, dict args, tyler env)
warning: this may cause unexpected behaviour between modules if you do not supply args in an acceptable manner. make sure you are aware how the other modules loaded in tyler behave before calling this function.

registerhook()

trod.registerhook(str modulename, str eventname)
This function may be used to register your own hook events (which you must trigger - see dohooks for how to trigger them). An example of registering your own events and then trigging them
import trod
def endofroutine(args, env):
	print "You are at the end of the example"
trod.registerhook("example", "endofexample")
trod.addhook("example", "endofexample", endofroutine)
trod.dohooks("endofexample", [], None)
Should output:
You are at the end of the example

Table of hookable functions

This table shows all the currently hookable events, along with what arguments are supplied. The naming conversations explained next are used throughout this list.

Naming conventions

sck - a socket descriptor assocated with the event
source - a dict object that has 3 elements. source contains an element named "nick", "user", and "host" which corespond to each section of an IRC source string. However, if the source is a server, these 3 elements will not exist, instead a key named "server" will. If you are hooking anything which uses source you should always check if source.has_key("server") to determine the type of message
tberror - a traceback error string tbvalue - a traceback error value tbtype - a traceback error type target - may be a nick or a channel name
message - a data string with the assocated event
chan - a channel name
reason - a part, kick or quit reason string
server - a server name
victim - the nickname of a user in a kick or kill event
modestring - the entire mode string of a mode event. example modestring may be "+obmv kay *!*@*.com tyler"
topic - a new or existing topic string
newnick - only used in the nick even, the new nick of a source
args - used only in the docmd event, is a list of all the tokens seperated by " " after the command character
cmd - is a string that is equal to args[0] of the above named args event argument. This string represents the "command" that is being executed. Only available in the docmds hook
module - the module that has just loaded (or is being unloaded) returnpath - the entity to send commands 'to' that leads to the source of the hook trigger. that is to say, if the hook was triggered by a channel action, this is the channel, if it was triggered by a PM to the bot, this is that user

Universal arguement

Unlike most of the above, there is one arguement that is always provided, this is called caller, and identifies the hook the routine is being called from, allowing hook-handler routines to implement several hooks in one code block.

Hookable Event Event args
error (when an error in a module is found)
  • tberror
  • tbvalue
  • tbtype
load (called only when dynamic loading is used)
  • sck
  • module
unload (called only when dynamic unloading is used)
  • sck
  • module
ctcp
  • sck
  • source
  • ctcpcmd
  • responce
docmd
  • sck
  • source
  • target
  • message
  • cmd
  • args
  • returnpath
domsg
  • sck
  • source
  • target
  • message
  • returnpath
notice
  • sck
  • source
  • target
  • message
  • returnpath
privmsg
  • sck
  • source
  • target
  • message
  • returnpath
who
  • sck
  • source
  • chan
  • server
join
  • sck
  • source
  • chan
quit
  • sck
  • source
  • reason
part
  • sck
  • source
  • chan
  • reason
invite
  • sck
  • chan
kick
  • sck
  • source
  • chan
  • victim
  • reason
nick
  • sck
  • source
  • newnick
topic
  • sck
  • source
  • chan
  • topic
mode
  • sck
  • source
  • target
  • modestring
doaddmember
  • chan
  • nick
doremmember
  • chan
  • nick

Global utilities (module: tutil)

There is a core module you can import to use various prewrote utilities (we actually would rather you used these since hooks may be added to some of these routines, allowing other modules to work properly). This module is called tutil

import tutil

ircsend()

tutil.ircsend(sck, data)
This is a raw interface to the IRC protocol. You simply send down you IRC protocol line (without the ending new line) Example usage:
tutil.ircsend(validsocket, "NOTICE kay :it's redundant now to send notice's using ircsend() as you can now use ircnotice()")

ircmsg()

tutil.ircmsg(sck, target, message)
This is a routine which sends out an IRC PRIVMSG command to the target, and in effect a message to them. Example usage:
tutil.ircmsg(validsck, "#nullnetwork", "howdy")

ircmultimsg()

tutil.ircmultimsg(sck, target, message)
This is a routine which sends out an IRC PRIVMSG command to the target, and in effect a message to them. The difference between ircmsg() and ircmultimsg() is ircmultimsg() accepts messages which contain new line characters in it. Example usage:
tutil.ircmultimsg(validsck, "#nullnetwork", """< brennanOS> heres a conversation starter: Programming in C all day makes me wish I was coding Java instead
< brennanOS> discuss
< orbitz> coding in java makes me wish i was coding in erlang
< AtnNn> you guys code in java?
-!- AtnNn [n=welcome@dsl-*-*.aei.ca] has left ##c []""")

ircaction()

tutil.ircaction(sck, target, action)
This routine sends an IRC "action" to target. An IRC action on most IRC clients is equivilent to doing /me does something. Example usage:
tutil.ircaction(validsck, "#nullnetwork", "dances with a drunk penguin")

ircnotice()

tutil.ircnotice(sck, target, message)
This is a routine which sends out an IRC NOTICE command to the target, and in effect a message to them. Example usage:
tutil.ircnotice(validsck, "kay", "You have mail")

ircjoin()

tutil.ircjoin(sck, chan)
This will cause tyler to join chan on socket, sck Example usage:
tutil.ircsend(validsocket, "#tyler")

ircpart()

tutil.ircpart(sck, chan, reason)
Make tyler leave chan, Example usage:
tutil.ircpart(validsocket, "#tyler", "tyler 2.0 development channel")

ircquit()

tutil.ircquit(sck, reason)
Make tyler send a QUIT to the server, thus disconnecting him Example usage:
tutil.ircquit(validsocket, "Shutting down")

ircnick()

tutil.ircnick(sck, newnick)
Change the nickname of tyler Example usage:
tutil.ircnick(validsocket, "Jack") # we all know tyler has multiple personalities!

irckick()

tutil.irckick(sck, chan, nick, reason)
Kick nick out of chan with the reason, reason. Example usage:
tutil.irckick(validsocket, "#tyler", "b14ck", "You SUCK!") # we all know tyler has multiple personalities!

irckill()

tutil.irckill(sck, nick, reason)
Kill a user off the IRCd (note: this is reserved for those with an O:Line on the IRCd, and who have "Oper'd up") Example usage:
tutil.irckill(validsocket, "victim", "You are not welcome here") # we all know tyler has multiple personalities!

ircmode()

tutil.ircmode(sck, target, modestring)
Send a mode command to target Example usage:
tutil.ircmode(validsocket, "#tyler", "+cm-o kay")

ircop()

tutil.ircop(sck, chan, [nicklist])
Op the nicks in nicklist in the channel, chan. Example usage:
tutil.ircop(validsocket, "#tyler", ["kay", "linkd", "will"])

ircban()

tutil.ircban(sck, channel, [banmasks])
Set bans on the the banmasks in channel Example usage:
tutil.ircban(validsocket, "#tyler", ["*@*.aol.com", "bannednick!*@*", "*!spam@*"])

irctopic()

tutil.irctopic(sck, chan, topic)
Set the topic of a chan Example usage:
tutil.irctopic(validsocket, "#tyler", "tyler 2.0 development channel")

ircwho()

tutil.ircwho(sck, target)
Send a who command to target, normally a channel. Example usage:
tutil.ircwho(validsocket, "#tyler")
#or
tutil.ircwho(validsocket, "kay")

ircoper()

tutil.ircoper(sck, user, opass)
Attempt to oper up (gain server-wide privledges) for the bot. Example usage:
tutil.ircoper(validsocket, "god", "stupidpass")

ircinvite()

tutil.ircinvite(sck, who, where)
Invite who to where. Example usage:
tutil.ircinvite(validsocket, "#tyler", "AtnNn")

ircaway()

ctcpsend()

ctcpmsg()

ctcpversion()

ctcpping()

ctcpuserinfo()

ctcpclientinfo()

ctcptime()

ctcpfinger()

tylercodestats()

tutil.tylercodestats()
This routine returns a dictionary of statistics about python code in the current working directory (which unless something is foobared, should be tylers directory, and thus tylers code Layout for the return dict:
ret["nfiles"] # the number of files
ret["nlines"] # the total number of lines
ret["nbytes"] # total number of bytes

Help Routines (module thelp)

This module contains routines that control the user-help system of the bot.

import thelp

hashelp()

thelp.hashelp(module, cmd)
This function will return the help data for the first match of cmd within module. None otherwise.
Layout for the return dict:
ret["cmd"] # the command name
ret["module"] # the module name
ret["syntax"] # the syntax summary
ret["description"] # the description of the command
ret["canviewfunc"] # a reference to a function that will calculate if the source address is authorised to see the command
Canviewfunc prototype:
def canviewfunc(source)
Example usage:
thelp.hashelp("somemodule", "somecommadname")

addhelp()

thelp.addhelp(module, cmd, syntax, cmddescription, canviewfunc = helpcanalwaysview):
This will register a modules command with the help database. Returns True if added. Returns False if there is already help for that command (use removehelp() to remove) Example usage:
thelp.addhelp("mockmodule", "tease", "tease <required nick>[,optional nick list]", "This command will tease \x1Frequired nick\x0F and all others in \x1Foption nick list \x0F")

removehelp()

thelp.removehelp(module, cmd):
This removes a cmd from the help. If cmd is '' then it behaves exactly like clearhelp and removes all the help for module.

clearhelp()

thelp.clearhelp(module):
This removes all help for module.

gethelp()

thelp.gethelp(sck, targetsource, cmd, module):
Sends targetsource all the help about cmd he is permitted. If cmd is "" then all the help is sent to targetsource. Example usage:
thelp.gethelp(validsck, {"nick": "kay", "user": "kay", "host": "localhost"}, None, "tyler")
This will request all the builtin ('tyler') help only - no module help will be provided.

helpcnt()

thelp.helpcnt()
Returns the number of commands current registered with the help system Example usage:
print thelp.helpcnt()

tyler class documentation (module: tyler)

Warning: Developers should never try to import this module.

This is the documentation for the absolute core of tyler.

Class Diagram

Tyler
-
+chanmembers
+networkchan
+networkpass
+botnick
+botuser
+botnspass
+decloakonjoin
+cmdprefix
+opts
+runtime
+invitejoin
+kickrejoin
+version
-
+sendauth
+addmember
+changenick
+remmember
+destroymember
+addchan
+remchan
+abouttyler
+whereisUser
+getuptimestr
+dohooks
+doctcp
+docmd
+domsg
+doline
+recvloop
+dumpVisible

Attributes

Operations

Perl Module Scripting

You heard right! You can write tyler modules in Perl! The methodology for this is slightly different than writing tyler modules in python. For instance, with the Perl tyler-modules, you have no need to "Hook" functions and events, instead, you simply create a subroutine handler for that event. tmodperl hooks all the trod events and then searchs for a perl subroutine to handle it.

Due to this, the name of your subroutines are important. To create a hook handler, you must use the following naming convention:

sub MyModuleName_EventToHook {}

Where MyModuleName MUST be the name of your perl module and EventToHook is the event name you want to handle. A list of the hookable events is given above. Arguements are given to the subroutine in the same fashion as the python modules,

So lets say we wanted to add a hook to all docmd events. This is our example routine in our test.pl module:

sub test_docmd {
	# get the args
	my @args = shift;
	my $env = shift;
	print "THE COMMAND WAS: " . $args[0]{"cmd"} . "\n";
	0;
}

You'll have to forgive the horrible Perl, I'm by no means a qualified Perl coder

Limitations

Unfortunately at time of writing, tmodperl has no way to unload/load or reload perl modules on the fly, unlike the python modules which are loading dynamically when needed. This means that the hook event unload does not exist for perl modules. In addition the parameters supplied to the load hook are difference, in that not only does it provide the modulename of the perl tyler-module, but it also provides references to various core tyler modules. See below for full breakdown of args.

Hook Event: load.
Called: when the perl tyler-module is loaded into tmodperl