Skip to content

Create your own commands

Steven James Core edited this page Aug 11, 2014 · 1 revision

Welcome to the sjBot wiki!

This wiki is here to help you if you wish to fork this repo and add your own commands to the bot.

This tutorial assumes that you already know how to use Python 3 and are somewhat familiar with the socket system used by the IRC.

Command list

First of all, you will need to add something to the command list. This is easy, its at the bottom of the commands.py file.

Note: There can be as many aliases as you want. Just don't get them mixed up with other commands!

"command name": {"ali": ["alias 1", "alias 2"], "run": _commands.functionName, "owner": 0, "help": "This is where you put the info for the help. &botcmdcommandName [optional param]" Now, lets break this down.

Command name: Is the name of the command, it can be anything you wish.

Alias 1,2-x: These are the aliases, they are what the bot looks for to run a command. Add as many as you want.

Function Name: This refers to the name of the defined function you make in the _commands class.

Owner: If this is 0, any user can use it. If it is 1 only someone with owner privileges can use it.

help: This is just the info that gets called when you use help [command name]. The string &botcmd will be replaced with the bot command symbol that is used to activate commands.

Example: "hug": {"ali": ["hug"], "run": _commands.hug, "owner": 0, "help": "This command will make the bot hug a user. &botcmdhug [user]." }

The command itself

Now, the first thing you want to do, is define the command in the _commands class. Make sure its the same as the Function Name from the command list.

Once you have done that, you will want to have 2 params for the function. So it should look something like this.

def commandName(self, params ):

self is just because its in a class, and you may need to use some of the self.variables params is the parameters for the command, ~command [param 1] [param 2]. sjBot splits them into a list, so you just use params[0] for the first param, param[1] for the second, etc etc.

The return data from the command should either be a simple string, or a list. If its a list, sjBot will parse over it and send each iteration on a new line in the IRC. Useful for multi-line things.

example: return "this will be one line" return ["This is line 1", "This is line 2"]

Self.Variables

This is a list of usable variables and command within self that gets passed to every command.

self.botCmd The command symbol for the bot, its not likely you will need to use this.

self.irc Gives you access to the irc.py commands and variables. This is an extremely useful variable.

self.user The name of the IRC user who called the current command.

self.host The host of the IRC user who called the current command.

self.channel The channel the command was called from.

self.more More search info given from the last Google or AHK search command.

self.ownerList A list of owners that have full control over the bot.

self.onNoCommand The command to call if there is no command found, just the botCmd.

Clone this wiki locally