iRbot – Creation Guide

I have recently taken an interest in having a bot for my group that will be able to respond to commands in the chat similar to the various IRC bots that you find.

I have searched and found the Steam-Chat-Bot software that is available on GitHub and found it to be fairly difficult at first to implement. I did however reach out to Efreak on steam and was assisted without any problems. +Rep to Efreak for the great and friendly assistance.

After I have managed to get the bot up and running I decided to re-fork the bot source from Efreak and implement the changes that got the bot working in a new branch and to completely re-setup the bot from the updated branch.

A word of warning the blog post will explain the setups I have followed to get the iRbot up and running, this does not mean it will work exactly for you the way it worked for me. I do not accept any responsibility for anything that may break from you following this guide. You are welcome to ask for help and I will do my best to assist where I can, I however am not the creator of the source and will not be able to assist with every technical issue that may arise and I advise you to look at the source of the code and try to understand before asking for assistance. Remember Google.com is your friend.

iRbot Specifics:

OS used: Ubuntu
Computer Setup: Google Cloud Compute Engine

Assumptions:

You have a computer already setup for this (out of scope for this article)
You know how to fix your own computer if something breaks (out of scope for this article)
You have account is part of the sudo users on your system (out of scope for this article)
You are able to have a fair idea of what the code is doing (out of scope for this article)
You have an unrestricted steam account (your bot account should have purchased at least $5 worth of games, even if it was gifts to someone else)

 

Environment Installation

After the Google Cloud Compute node was deployed and I have access to the console through SSH I have performed the following commands.

Please note that this is a fresh deploy with no additional software installed except what is already part of the image from Google.

First I installed the Node Version Manager script that will help me run multiple versions of Node on my system in order to be able to test compatibility with a “new” version of node before publishing my application on it. You can read more here.
curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash
It is good to exit your terminal and re-login for the environment to refresh or you can use the below command
source ~/.profile

Next I ran the below command to ensure that my system is ready for running nvm commands, if you get errors with this command you might need to run sudo apt-get install git
nvm ls-remote

After I ensured that everything is installed and working accordingly I went ahead and installed the latest version of node “v6.2.2” at the time of writing this.
nvm install 6.2.2

Upon completion of the node installation I confirmed my node version and the location it is installed with the below command
node --version && which node

In order to make sure that the installed node version will be available to other users and not just for myself I ran the following command. This command copies my version of node to the /usr/local folder and makes it available to other users as well.
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

In order to ensure that node is now available to everyone I switched my command to the root user (as this is the only other user on my system) and ensured that it is using the correct path for node with the below command
sudo -s
which node
exit

Now that I know that the Node Version Manager and the actual Node application is installed I was able to start with installing my Node related packages.
The first package I installed was the Production process Manager for Node packages called PM2.
This runs the node apps for me and makes running multiple node apps easy from the terminal, it can also start all my node apps again after a system reboot / startup allowing me to never worry if my app will start again after a reboot for any reason. Install pm2 with the following command.
The -g option makes pm2 install globally and makes it available to the command line directly
npm install pm2 -g

Then we made PM2 start at boot with the following command
pm2 startup ubuntu
Which gave us another command to run similar to this
sudo su -c "env PATH=$PATH:/usr/local/bin pm2 startup ubuntu -u irmandos --hp /home/irmandos"
And then we test that PM2 is running with this command
pm2 status

 

iRbot Installation

Now that we have our node environment setup with the required additional tools and thingies I started setting up iRbot.

Because I have forked Efreak on GitHub it was easy for me to create a new branch and create most of my config on GitHub before pulling the config down on my VPS (I do advise you to do the same, but to each his own)
Because everything is already on GitHub I created my bot directory, changed to that directory and installed my branch from GitHub with the following commands

mkdir ~/chatbot && cd ~/chatbot
npm install git://github.com/irmandos/node-steam-chat-bot#botconfig

If you want to enable the module in the bot that allows for learning X is Y you will have to install sqlite3 with the following command

npm install sqlite3

With our branch installed from GitHub I copied the “irbot.js” and “common.js” files located in node_modules/steam-chat-bot/ folder to the root of our bot

cp node_modules/steam-chat-bot/irbot.js irbot.js && cp node_modules/steam-chat-bot/common.js common.js

You can proceed with configuring you’re bot in the irbot.js and common.js files and run it using the below command until you are happy to proceed
Please make sure you replace my Steam Group ID with your own Group ID and don’t spam my Group. Make the bot YOUR OWN.
node irbot.js

Once I was happy with how my bot is working and tested it with the command above I made sure I was in the proper folder and added my bot the PM2 for running it 24/7 with the command below
cd ~/chatbot && pm2 start irbot.js

I checked that everything is working properly with the PM2 and that the bot is not in a restart loop (happened a few times) and the save the PM2 process list for automatically starting our bot on a server restart.
pm2 status
pm2 save

Leave a Reply