A bot for Pokemon Showdown using code from both boTTT and Art2D2, as well as some of my own code. Everything goes to their respective owners^-^
Note: If you don't know what these are, then skip this part for now
League API: npm install leagueapi
bit.ly API: npm install node-bitlyapi
osu! API: npm install osu-api
request API: npm install request
Create an account for your bot on PS, pick a username, and register it with a password of your choice.
Download all of these files and put them somewhere on your computer in a folder, preferrable named after your bot.
To run your bot, you must first download a program called node.js.
Once it is downloaded, find Node.js command prompt
and run it.
In the terminal window that opens up, type npm install
and press Enter.
First off, you should copy the code in config-example.js
into a new file named config.js
.
Here are a list of things to look over:
exports.server
should be'sim.smogon.com'
if you plan on connecting to the main PS serverexports.port
should be8000
for main PS serverexports.serverid
should be'showdown'
exports.nick
is the username of your bot's account- Example:
'MashiBot'
- Example:
exports.pass
is the password that you gave to your bot's account- Example:
'MashiBotPassword'
- Example:
exports.rooms
is the names of the rooms that you want the bot to join- Exmaple:
'tech', 'moba', 'thp'
- Exmaple:
exports.privaterooms
is the names of private rooms that you want the bot to joinexports.commandcharacter
is what character you want your bot to use for commands- Example:
'#'
- Example:
exports.defaultrank
is the lowest rank users that are able to use your bot- Example:
' '
(would allow any user to use the bot's commands)
- Example:
exports.excepts
is the users that can use any command of your bot, no matter their rank- Example:
'mashirochan'
- Example:
exports.whitelist
is the users that cannot be banned by your bot- Example:
'leinfiniti', 'aikachan', 'yoshinokun'
- Example:
exports.botguide
is the link to a guide for your bot (I recommend using Pastebin)- Example:
'http://pastebin.com/QGrSXCQ3'
- Example:
exports.fork
is the link to your bot's GitHub page- Example:
'https://github.com/mashirochan/MashiBot'
- Example:
exports.avatarNumber
is the number of the avatar that you want your bot to have- Example:
'155'
- Example:
The package.json
lists information about the bot. Some things to change are:
"name"
is the name of your bot"url"
is the link to your bot's GitHub repository"name"
the second name is your username
To run your bot, run the program Node.js command prompt
. Next, find the file path to your bot's folder. For example, mine is saved on my desktop so the file path is "C:\Users\Mashiro\Desktop\MashiBot\Pokemon-Showdown-Bot-master".
In the terminal window type cd [your file path]
, and then press Enter.
Next, type node main.js
and press Enter again to start your bot. You should see things start to pop up, confirming connection to the server and also the joining of the rooms that it was assigned to join.
The standard syntax for a command function is as follows:
[function name]: function(arg, by, room, con) { [function code] },
arg
is what is input by a user after the command name- Example: For '#test hi',
arg
would be 'hi'
- Example: For '#test hi',
by
is the user that said the command- Example: If I said '#test',
by
would be '+Mashiro-chan'
- Example: If I said '#test',
room
is the room that the command was used in- Example: If I was in the Tech & Code room,
room
would be 'techcode'
- Example: If I was in the Tech & Code room,
con
is the connection of the bot
The standard syntax for outputting words and data is as follows:
this.say(con, room, '[text you want to output]');
- To restrict a command to only users of a certain rank, use the
hasRank
function:
if (!this.hasRank(by, '#~')) return false;
This is saying that if the user that uses the command does not have a rank of # or ~, then return false
, ending the function.
- Another way to check if a user can use a command is the
canUse
function:
if (!this.canUse('[function name]', room, by)) return false;
There is a command called set
which sets the required ranks for commands. What canUse
does is takes the user's rank and checks the settings.json
file to see if the user has at least the rank that was set with the set
command. So for example if the command test
was set to @ with set
, and the user had a rank of +, canUse
would return false
, ending the function.
say: function(arg, by, room, con) {
if (!this.canUse('say', room, by)) return false;
this.say(con, room, arg);
},
Let's say it's a nice, warm summer day and a user is sitting in their basement on PS, chatting in the Tech & Code room, under the username MashiIsCool3327. Their rank is ~, and the set
command was used to set say
to #. If they were to type "#say Hello" in the chat, the function would first call the canUse
function. by
, aka the user, has a rank of ~, which is higher than #, in the room
, aka 'techcode', so the function returns true
. Since !true
is false
, the function does not return false
and continues. Remember how I told you how to output stuff up above? Well the function uses this.say
to output the arg
, aka 'Hello', in the room
, aka 'techcode'. Spooky!
##Useful Functions There are several functions that make your life as a programmer much, much easier. Some are defined in the bot's code, but most of them are pre-defined functions that are commonly used in JavaScript.
toId
is a function that takes in a string
parameter and puts it in all lowercase, as well as removes all spaces and anything that isn't a number or letter.
toId(arg)
arg
is the string that you want to pass into thetoId
function.- Input: String
- Output: String with no symbols, spaces, and all lowercase
var a = toId('+Mashiro-chan');
console.log(a);
mashirochan
[string].indexOf('[search term]', [index])
string
is the string variable that you want to search throughsearch term
is a string that you want to search for in the string variableindex
is the index in the string variable that you want to start searching at- Input: String, Search term
- Output: Index of where the Search term first occurs in the String
- Note: If the search term is not in the string variable, then the function will return -1
var a = 'Hello, my name is bob.';
console.log(a.indexOf('o'));
4
console.log(a.indexOf('o', 6));
19
[string].split('split term');
string
is the string variable that you want to search throughsplit term
is a string that you want to split the string variable by- Input: String, Split term
- Output: An array, each term being the parts of the string in between the Split term
- Note: If the split term is not in the string variable, then the function will return an error
var a = 'Ninetales, Squirtle, Pichu';
a.split(', ');
console.log(a[0]);
Ninetales
console.log(a[1]);
Squirtle
console.log(a[2]);
Pichu