Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Commit

Permalink
Update exports, add richpresence
Browse files Browse the repository at this point in the history
  • Loading branch information
kjsmita6 committed Nov 10, 2015
1 parent bf4e7a1 commit 42db11b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A module that provides a simple base class for a Steam bot that can be easily ov
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 v4.x.x</b>.
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
Expand All @@ -29,7 +29,8 @@ var Bot = new ChildBot(username, password, {
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,
gamePlayed: 440 //game that the bot will play, don't include for no game
service: 'Parental' //service for SteamUnifiedMessages, leave blank to not include
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
});

```
Expand Down Expand Up @@ -61,17 +62,26 @@ logOn() //steamClient.logOn()
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)

If you need to use the `Steam` object directly from node-steam, do something like this:
```javascript
var ParentBot = require('steam-parentbot');
var Steam = ParentBot.Steam;
```
This will allow you to use certain methods not available to any handlers, but to the steam client itself (one useful example is Steam._processProto).

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'];
Expand Down Expand Up @@ -113,7 +123,7 @@ If you want to create your own listener from an external module (this works the
```javascript
var MySQL = require('mysql');

// inherit from parentbot, see [example.js](https://github.com/dragonbanshee/node-steam-parentbot/blob/master/examples/example.js) for how to do this
// inherit from parentbot, see example.js for how to do this

var Bot = new ChildBot('username', 'password');

Expand Down
20 changes: 13 additions & 7 deletions examples/example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var util = require('util');
var ParentBot = require('../parentBot.js').ParentBot; //change to 'steam-parentbot' if not running from examples directory
var ParentBot = require('../ParentBot.js'); //change to 'steam-parentbot' if not running from examples directory
var Steam = ParentBot.Steam; //instance of the Steam object

var MySQL = require('mysql'); //require your own modules

Expand All @@ -10,16 +11,21 @@ var ChildBot = function () {
util.inherits(ChildBot, ParentBot);

var Bot = new ChildBot('username', 'password', {
apikey: 'xxxxx', //default apikey option for steam

apikey: '1234567890987654321', //default apikey option for steam
guardCode: 'ABCDE', //put guardcode here, remove after successful login
sellPrice: '1 ref' //add your own options
});

ChildBot.prototype._onFriendMsg = function (steamID, message, chatter, type) { //overwrite default event handlers
if(message === '!prices') {
Bot.steamFriends.sendMessage(steamID, 'Selling for ' + Bot.options.sellPrice); //use your custom options
ChildBot.prototype._onFriendMsg = function (steamID, message, type) { //overwrite default event handlers
if(type === Steam.EChatEntryType.ChatMsg) {
if(message === '!prices') {
Bot.steamFriends.sendMessage(steamID, 'Selling for ' + Bot.options.sellPrice); //use your custom options
}
this.logger.info(steamID + ' sent: ' + message);
}
else {
console.log(type);
}
this.logger.info(steamID + ' sent: ' + message);
}

Bot.steamTrading.on('tradeProposed', function (tradeID, steamID) { //create your own listeners
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "steam-parentbot",
"version": "1.3.2",
"version": "2.0.0",
"description": "A module that provides a simple base class for a Steam bot that can be easliy overwritten and customized.",
"main": "parentbot.js",
"main": "ParentBot.js",
"author": {
"name": "Kyle Smith",
"email": "smith.kyle1734@gmail.com"
Expand All @@ -16,7 +16,7 @@
"node": ">=4.0.0"
},
"dependencies": {
"steam": "^1.2.0",
"steam": "^1.3.0",
"steam-trade": "git://github.com/seishun/node-steam-trade.git",
"steam-tradeoffers": "^2.0.2",
"steam-web-api-key": "^0.0.1",
Expand Down
27 changes: 15 additions & 12 deletions parentbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const ParentBot = function (username, password, options) {
this.steamFriends = new Steam.SteamFriends(this.steamClient);
this.steamTrading = new Steam.SteamTrading(this.steamClient);
this.steamGameCoordinator = (this.options.gamePlayed ? new Steam.SteamGameCoordinator(this.steamClient, parseInt(this.options.gamePlayed)) : undefined);
this.steamRichPresence = (this.options.richPresenceID ? new Steam.steamRichPresence(this.steamClient, parseInt(this.options.richPresenceID)) : undefined);
this.steamWebLogon = new SteamWebLogon(this.steamClient, this.steamUser);
if(this.service) {
this.steamUnifiedMessages = new Steam.SteamUnifiedMessages(this.steamClient, this.service);
Expand Down Expand Up @@ -72,14 +73,18 @@ const ParentBot = function (username, password, options) {
this.steamFriends.on('friend', (steamID, relationship) => { this._onFriend(steamID, relationship); });
}


module.exports = ParentBot;
ParentBot.Steam = Steam;

var prototype = ParentBot.prototype;

prototype.connect = function () {
prototype.connect = function connectCallback() {
this.steamClient.connect();
this.logger.debug('Connecting to Steam...');
}

prototype.logOn = function () {
prototype.logOn = function logOnCallback() {
this.logger.debug('Logging in...');
const that = this;
try {
Expand Down Expand Up @@ -113,17 +118,17 @@ prototype.logOn = function () {
}
}

prototype._onError = function () {
prototype._onError = function errorCallback() {
this.logger.error('Disconnected from Steam, reconnecting...');
this.connect();
}

prototype._onConnected = function () {
prototype._onConnected = function connectedCallback() {
this.logger.verbose('Connected to Steam, logging in...');
this.logOn();
}

prototype._onLogOnResponse = function (response) {
prototype._onLogOnResponse = function logOnResponseCallback(response) {
const that = this;
if (response.eresult === Steam.EResult.OK) {
this.logger.info('Logged into Steam!');
Expand Down Expand Up @@ -169,12 +174,12 @@ prototype._onLogOnResponse = function (response) {
}
}

prototype._onLoggedOff = function () {
prototype._onLoggedOff = function logedOffCallback() {
this.logger.error('Logged off of Steam, logging in again...');
this.logOn();
}

prototype._onUpdateMachineAuth = function (response, callback) {
prototype._onUpdateMachineAuth = function updateMachineAuthCallback(response, callback) {
this.logger.debug('New sentry: ' + response.filename);
fs.writeFileSync(this.sentryfile, response.bytes);
callback({
Expand All @@ -185,20 +190,18 @@ prototype._onUpdateMachineAuth = function (response, callback) {
});
}

prototype._onFriendMsg = function (steamID, message, type) {
prototype._onFriendMsg = function friendMsgCallback(steamID, message, type) {
if (type === Steam.EChatEntryType.ChatMsg) {
this.logger.info('Message from ' + steamID + ': ' + message);
this.steamFriends.sendMessage(steamID, 'Hi, thanks for messaging me! If you are getting this message, it means that my ' +
'owner hasn\'t configured me properly. Annoy them with messages until they do!');
}
}

prototype._onFriend = function (steamID, relationship) {
prototype._onFriend = function friendCallback(steamID, relationship) {
if (relationship === Steam.EFriendRelationship.RequestRecipient) {
this.steamFriends.addFriend(steamID);
this.steamFriends.sendMessage(steamID, 'Hi, thanks for adding me! If you are getting this message, it means that my ' +
'owner hasn\'t configured me properly. Annoy them with messages until they do!');
}
}

exports.ParentBot = ParentBot;
}

0 comments on commit 42db11b

Please sign in to comment.