This is a Pokemon Showdown bot written in JavaScript for Node, based on Pokemon Showdown Bot.
This bot is based on commands and features, which are explained below. This is intended to ease bot configuration and customization, separating commands in multiple files, multiple features in different folders and merging functions in Global Objects like Bot, CommandParser or Settings.
Pokémon Showdown Bot requires node.js to run. Install the last stable version if you do not have it.
The first step is cloning this repo, install Git if you have not it and use the following command on shell console:
$ git clone --branch=master git://github.com/Ecuacion/Pokemon-Showdown-Node-Bot.git Pokemon-Showdown-Node-Bot
You can also download a Zip of this repo and decompress it.
Then open a shell console, use cd
to reach the directory of the bot and install dependencies:
$ npm install --production
If you want to use Gulp
test, install all dependencies with npm install
Now, to start the bot use node index.js
To configure your bot, copy config-example.js
to config.js
and edit that file. You can specify bot login credentials among other things. If you don't specify credentials, the bot will log in a random username started by 'Bot'. Read the Configuration Guide for more information
If you know all about Git you don't need to read this. This is just for people who want to make changes in their bots, but still want to keep them updated regarding this repo.
First, fork this repo. You can do it with the button Fork
Second, clone your repo in your computer, you can do it with GitHub desktop Client for Windows or Mac or with a shell console:
$ git clone <your own fork> <My-Bot-Example-Folder>
Third, create a remote to get the updates (first use cd
to reach the directory of your bot):
$ git remote add upstream https://github.com/Ecuacion/Pokemon-Showdown-Node-Bot.git
Now, you can make changes, and commit them.
When you want to update, you can follow these steps:
- Open a shell console and use
cd
to reach the directory of your bot - If you have uncommited changes use
git add --all
andgit commit -m "Your commit message"
- Use
git fetch upstream
to update your base version of Pokemon-Showdown-Node-Bot - Use
git checkout master
an thengit merge remotes/upstream/master
- If you get conflicts, solve them and use
git commit -a
- Once merged, your bot is updated
Once copied config.js
from config-example.js
you can edit config options to customize the bot.
Connection Details
Config.server
: Server url, for example main server url issim.smogon.com
Config.port
: Connection port, Pokemon Showdown default port is8000
Config.serverid
: Server id, main server id isshowdown
for exampleConfig.autoReconnectDelay
: If connection gets closed, how much time it is waiting before reconnectConfig.connectionTimeout
: If connection hang up, the time to check for reconnect
Crashguard
Config.crashguard
: If true, write errors to console instead of crashing
Login Details
Config.nick
: Bot Nickname, if you don't specify a nickname, it will log in a random nicknameConfig.pass
: Password, if neededConfig.autoReloginDelay
: If it can't login because of server issues, how much time it is waiting before relogin
Rooms
Config.rooms
: Array of rooms to join after login. You can specify a string value:all
for joining all rooms,official
for official rooms andpublic
for not official roomsConfig.privateRooms
: Specify which rooms are privateConfig.initCmds
: Array of commands to send after login
Auth Config
Config.exceptions
: Specify rank exceptions. Useuserid: true
for full permissionsConfig.ranks
: Array of user groups ordered from lowest to highest auth
Commands Config
Config.commandTokens
: Array of valid command characters. A command character, for example,.
means.command
usageConfig.defaultPermission
: Default permision set forthis.can
in commands permissionsConfig.permissionExceptions
: Exceptions for commands permissions
Language Config
Config.language
: Set default language
Console Config
Config.debug
: Specify which console messages are shown
Bot commands are in the folder commands
separated in different files. A command file has the following structure:
Settings.addPermissions(['permission1', 'permission2', 'permission3']); //Add command permission for 'can' method (optional)
exports.commands = {
altcommand1: 'command1', //commands can be references to other commands
command1: function (arg, by, room, cmd) { //command are functions
//do stuff
},
command2: function (arg, by, room, cmd) {
//do stuff
}
};
Commands have 4 arguments:
- arg: Command argument when you use for example
command [argument]
- by: User who executed the command
- room: Room where the command has been executed
- cmd: Original command before refrerences. For example if you use
altcommand1
, cmd isaltcommand1
but the function correspond tocommand1
Also, command have a context:
this.arg
- Argumentthis.by
- Argumentthis.room
- Argumentthis.cmd
- Argumentthis.handler
- Command function namethis.cmdToken
- Command character used. Example:.say hi
means this.cmdToken =.
this.roomType
- Can be 'chat', 'battle' or 'pm'this.botName
- Bot usernamethis.reply (pm)
- Replies in the same room (chat or pm)this.pmReply (text)
- Replies by pmthis.restrictReply (text, permission)
- Replies by chat if user has permission, by pm otherwisethis.say (room, text)
- Say something to other roomthis.isRanked (rank)
- True if ranked equal or above, false if notthis.isRoomRanked (room, rank)
- True if ranked equal or above (in specified room), false if notthis.botRanked (rank)
- True if the bot has this rank or above, false if notthis.isExcepted
- True if the user is excepted, false if notthis.can (permission)
- True if user has permission, false if notthis.canSet (permission, rank)
- Checks if the user has permission to useset
commandthis.hasRank (user, rank, room)
- Similar toisRoomRanked
but more generalthis.getRoom (room)
- Get a room object or null (if the bot is not in that room)this.getRoomUsers (room)
- Get an array of users who are in a room or null (if the bot is not in that room)this.getUser (user, room)
- Get an user object or null (if the user or the bot are not in that room)this.trad (textId)
- Returns a text from the corresponding languages filethis.parse (cmd)
- Parse a message (to call other commands)
Bot features are complex modules hat fulfill secondary functions, located in the folder features
. Each feature is a folder that must have an index.js
main file. That file will be required of bot start and should have the following minimum structure:
exports.id = 'featureid';
exports.desc = 'Simple Feature description';
exports.init = function () {
//init function
};
exports.parse = function (room, message, isIntro, spl) {
//data parse
};
Features must have and unique id and two essential functions:
- init - Is called on connection to server, to delete residual data or start/restart feature timeouts.
- parse - It will receive all server messages, already separated in lines, each parse call is a new line received.
- Ecuacion (Owner)
Contributors:
- Irraquated (Languages and bug fixes)
- panpawn (YouTube feature, fixes)
Part of this code is imported from other developments, so credits to:
- Quinella, Morfent and TalkTakesTime developers of Pokemon-Showdown-Bot
- Guangcong Luo and other contributors of Pokemon Showdown