# steam-parentbot

> A module that provides a simple base class for a Steam bot that can be easliy overwritten and customized.

Latest version **3.0.1** (published 2016-10-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install steam-parentbot
pnpm add steam-parentbot
yarn add steam-parentbot
bun add steam-parentbot
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2016-10-06 |
| First published | 2015-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 8 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Kyle Smith |
| Maintainers | dragonbanshee |

## Links

- npm: https://www.npmjs.com/package/steam-parentbot
- Repository: https://github.com/dragonbanshee/node-steam-parentbot
- Homepage: https://github.com/dragonbanshee/node-steam-parentbot#readme
- Issues: https://github.com/dragonbanshee/node-steam-parentbot/issues
- npm.io page: https://npm.io/package/steam-parentbot

## Dependencies (8)

- [steam](https://npm.io/package/steam.md) ^1.4.0
- [winston](https://npm.io/package/winston.md) ^2.2.0
- [steam-totp](https://npm.io/package/steam-totp.md) ^1.4.0
- [steam-trade](https://npm.io/package/steam-trade.md) ^0.2.6
- [steam-weblogon](https://npm.io/package/steam-weblogon.md) ^0.0.5
- [steamcommunity](https://npm.io/package/steamcommunity.md) ^3.27.1
- [steam-tradeoffers](https://npm.io/package/steam-tradeoffers.md) ^3.0.3
- [steam-web-api-key](https://npm.io/package/steam-web-api-key.md) ^0.0.3

## Recent versions

- 3.0.1 (latest) — 2016-10-06
- 3.0.0 — 2016-03-30
- 2.2.5 — 2016-03-23
- 2.2.4 — 2016-01-31
- 2.2.3 — 2015-12-14
- 2.2.2 — 2015-12-14
- 2.2.1 — 2015-12-14
- 2.2.0 — 2015-12-14
- 2.1.1 — 2015-12-13
- 2.1.0 — 2015-12-09
- 2.0.0 — 2015-11-10
- 1.3.2 — 2015-10-07
- 1.3.1 — 2015-10-04
- 1.2.1 — 2015-09-04
- 1.2.0 — 2015-09-04
- … 3 more at https://npm.io/package/steam-parentbot/versions

## README

# ParentBot

[![Codacy Badge](https://www.codacy.com/project/badge/0bebac574a7040179d83778a4dd18aa9)](https://www.codacy.com/app/dragonbanshee/node-steam-parentbot)

A module that provides a simple base class for a Steam bot that can be easily overwritten and customized.

I made this (mainly for myself) because I was getting tired of writing the same code over and over again that does the same things. This is a way to eliminate the copying and pasting of code, while still allowing you to fully customize it.

# Installation
First you will need to install [node.js](http://nodejs.org) if you haven't already. <b>This will only work with Node.js >= 4.0.0</b>.

Once you have node and npm installed, type this command in shell, cmd, powershell, etc:
```javascript
npm install steam-parentbot
```

Once it's installed, you will need to create your config file, you may use the one in the examples folder, or you can create one anywhere. It must follow the same structure as the one in example.js or example-es6.js

# ES5 vs ES6 (new!)
I have rewritten the bot to use an ES6 class instead of an ES5 function. This will not change the functionality of the bot, but it will change how the bot options are defined.

First change (affects both): Requiring
```javascript
// Old version require
var ParentBot = require('steam-parentbot').ParentBot; // .ParentBot for original version

// New version require
var ParentBot = require('steam-parentbot').ES6; // .ES6 for new version
```

Second (new): ChildBot and overwriting
```javascript
// Old version ChildBot
var ParentBot = require('steam-parentbot').ParentBot;

var ChildBot = function() {
	ChildBot.super_.apply(this, arguments);
}

require('util').inherits(ChildBot, ParentBot);

ChildBot.prototype._onFriendMsg(steamID, message, type) { } // overridden method

var Bot = new ChildBot('username', 'password');

// New version ChildBot
var ParentBot = require('steam-parentbot').ES6;

class ChildBot extends ParentBot {
	_onFriendMsg(steamID, message, type) { } //overridden method
}

var Bot = new ChildBot('username', 'password');
```

Your best bet for #2 is looking at the file `parentbot-es6.js`. It shows how classes work in JavaScript which should help you override the super ParentBot class.

# Options
To initialize the bot, you must use `var Bot = new ChildBot(username, password)`, but you may also add an optional `options` object. This object can contain the following (and any others if you are adding to the bot):
```javascript
//Without options
var Bot = new ChildBot(username, password);

//With options
var Bot = new ChildBot(username, password, {
	apikey: '1234567890', //steam api key, will be registered automatically if one isn't supplied
	sentryfile: 'username.sentry', //sentry file that stores steamguard info, defaults to username.sentry
	logfile: 'username.log', //filename to log stuff to, defaults to username.log
	guardCode: 'XXXXX', //steam guard code, only needed if you get error 63 when logging in, can remove after sentry is generated
	twoFactorCode: 'XXXXX', //two factor authentication code, only needed if you're using the mobile 2FA
	sharedSecret: 'XXXXXXXXXXXXXXXXXXXXXXXXXXX=', //shared secret, needed to automatically generate twoFactorCode
	identitySecret: 'XXXXXXXXX/XXXXXXXXXXXXXXX/X=', //identity secret, needed to automatically confirm trade offers, must be used with confirmationInterval
	confirmationInterval: 10000, //how often we should check for new trades to confirm in miliseconds, must be used with identitySecret
	gamePlayed: 440 //game that the bot will play, don't include for no game
	service: 'Parental', //service for SteamUnifiedMessages, leave blank to not include
	richPresenceID: 440 //game to use rich presence with, don't include for no rich presence
});

```

# Default methods and handlers
The base class ParentBot comes with a lot of built in methods and listeners. You can add your own, and edit the built in ones right in your config file.

The event handlers are:
```javascript
_onError() //steamClient.on('error')
_onConnected() //steamClient.on('connected')
_onLogOnResponse(response) //steamClient.on('logOnResponse')
_onLoggedOff(eresult) //steamClient.on('loggedOff')
_onDebug() //steamClient.on('debug')

_onUpdateMachineAuth(response, callback) //steamUser.on('updateMachineAuth')

_onFriendMsg(steamID, message, type, chatter) //steamFriends.on('friendMsg')
_onFriend(steamID, relationship) //steamFriends.on('friend')
```

The two default methods are
```javascript
connect() //steamClient.connect()
logOn() //steamClient.logOn()
```

# Overwriting built in methods and handlers
This module was designed to provide a base class, as well as allow the user full customization. The module comes with lots of listeners built in already (the only ones you probably want to overwrite are _onFriend and _onFriendMsg since they don't really contain anything useful except for telling users that the bot isn't set up correctly (unless thats what you want).

There are already some built in instances of libraries and things that you can use in your config file. You can access all of these by doing `Bot.property.method`. For a list of methods, please visit the links for each property below. List of properties you can use:

- steamClient - an instance of [Steam.SteamClient()](https://github.com/seishun/node-steam#steamclient)
- steamUser - an instance of [Steam.SteamUser(steamClient)](https://github.com/seishun/node-steam/tree/master/lib/handlers/user#steamuser)
- steamFriends - an instance of [Steam.SteamFriends(steamClient)](https://github.com/seishun/node-steam/tree/master/lib/handlers/friends#steamfriends)
- steamTrading - an instance of [Steam.SteamTrading(steamClient)](https://github.com/seishun/node-steam/tree/master/lib/handlers/trading#steamtrading)
- steamGameCoordinator - an instance of [Steam.SteamGameCoordinator(steamClient, appID)](https://github.com/seishun/node-steam/tree/master/lib/handlers/game_coordinator#steamgamecoordinator)
- steamUnifiedMessages - an instance of [Steam.SteamUnifiedMessages(steamClient, service)](https://github.com/seishun/node-steam/tree/master/lib/handlers/unified_messages)
- steamRichPresence - an instance of [Steam.SteamRichPresence(steamClient, appID)](https://github.com/seishun/node-steam/tree/master/lib/handlers/rich_presence#steamrichpresence)
- logger - an instance of [Winston.Logger](https://github.com/winstonjs/winston)
- steamWebLogon - an instance of [SteamWebLogon](https://github.com/Alex7Kom/node-steam-weblogon) (use this for logging into Steam web, replacement for steamClient.on('webSessionID');
- steamTrade - an instance of [SteamTrade](https://github.com/seishun/node-steam-trade)
- offers - an instance of [SteamTradeOffers](https://github.com/Alex7Kom/node-steam-tradeoffers)
- steamCommunity - and instance of [SteamCommunity](https://github.com/DoctorMckay/node-steamcommunity)


If you need to use the any require objects directly without instantiating them first, the following are available:
```javascript
var ParentBot = require('steam-parentbot').ParentBot;
var Steam = ParentBot.Steam;
var SteamCommunity = ParentBot.SteamCommunity;
var SteamWebApiKey = ParentBot.SteamWebApiKey;
```
This will allow you to use certain methods not available to any handlers, but to the steam client itself (one useful example is Steam enums).

To overwrite a default handler (the ones with a _ in front), do this in your config file, assuming that `ChildBot` is the child of `ParentBot` (this example will show how to change _onFriend):
```javascript
var admins = ['76561198091343023'];
var Bot = new ChildBot('username', 'password');

ChildBot.prototype._onFriend = function(steamID, relationship) {
    if(relationship === 2) {
        if(admins.indexOf(steamID) !== -1) {
            Bot.steamFriends.addFriend(steamID);
        }
        else {
            Bot.logger.warn('Someone who isn\'t an admin tried to add me, denying...');
            Bot.steamFriends.removeFriend(steamID);
        }
    }
}
```

This example overwrites the _onFriend handler to create a custom friend handler that only accepts friend requests from admins. _onFriend is the function that is passed to `this.steamFriends.on('friend', function(steamID, relationship) { that._onFriend(steamID, relationship); });`, so there is no need to add a new listener, you can just modify the function.

If you want to create a listener from an internal module (such as Steam), you can do it like this. Note: __do not add listeners for things that are already being listened to.__
```javascript
//parentbot inheritence and stuff

var Bot = new ChildBot('username', 'password');

Bot.steamUser.on('tradeOffers', function(number) {
	if(number > 0) {
		// do stuff with trade offers
	}
});
```

This is how you add listeners to internal modules.


If you want to create your own listener from an external module (this works the same way for modules that are already in use since I didn't create all listeners, like tradeOffers), you would do it like this

```javascript
var MySQL = require('mysql');

// inherit from parentbot, see example.js for how to do this

var Bot = new ChildBot('username', 'password');

Bot.connection = MySQL.creatConnection({
	host: 'localhost',
	user: 'root',
	password: 'password'
});

Bot.connection.on('error', function(e) {
	Bot.logger.error(e);
});
```

That is how you add your own listeners to your bot from external libraries.

# Help
__This repository is beginner friendly__. If you have a problem, no matter how simple it is, PLEASE open an issue, and either I or other users will try to answer it as quickly as possible. If you need help with something that is really complex or would take a long time, you can [add me on steam](http://steamcommunity.com/id/dragonbanshee).

# Contributors
__Pull requests are welcome!__ If you found a bug and fixed it, send a pull request. If you think that you added something useful, send a pull request. Please try to follow the existing style though. I wrote [this guide](https://github.com/efreak/node-steam-chat-bot/wiki/contributing), and I think it still applies here.

Feel free to add your name and github link here if you contributed. Also add what you did to contribute.
- [dragonbanshee (project creator)](https://github.com/dragonbanshee)
- [andrewda (added 2FA login and mobile confirmation)](https://github.com/andrewda)

---
_Source: https://npm.io/package/steam-parentbot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
