Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pull Request] andrewda/node-steam-guide » Steam-Bot-Basics/node-steam-guide #111

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7d456e6
Merge pull request #1 from andrewda/master
DentFuse Mar 18, 2018
c0b43d4
Added a chapter teaching how to handle steam messages
DentFuse Mar 18, 2018
1d45f7c
Merge branch 'master' of https://github.com/DentFuse/node-steam-guide
DentFuse Mar 18, 2018
5f3ee7f
Added missing ";"
DentFuse Mar 21, 2018
d6717e2
Added ';' in project4.js
DentFuse Mar 21, 2018
7719128
Update README.md
andrewda Mar 21, 2018
a52e77c
Added chapter 3.2
DentFuse Apr 23, 2018
c485af7
CleanUp
DentFuse Apr 23, 2018
5a49a12
Update README.md
xmwx38 Apr 26, 2018
dc9a1d3
Update README.md
xmwx38 Apr 26, 2018
26ee89c
Update Chapter 1.1 README.md
xmwx38 Apr 26, 2018
7e8ac48
Set theme jekyll-theme-tactile
xmwx38 Apr 26, 2018
ce21448
Set theme jekyll-theme-cayman
xmwx38 Apr 26, 2018
0c0779e
Set theme jekyll-theme-cayman
xmwx38 Apr 26, 2018
2c151cc
Updated README.md - Chapter 6.1
xmwx38 May 9, 2018
a137787
Update README.md
xmwx38 Jun 5, 2018
63cd262
Updated Chapter 6.2, 6.3
xmwx38 Jun 13, 2018
3567f02
Chapter 7 added
xmwx38 Jun 13, 2018
37e77fe
Ch. 7 added; Updated README.md - Ch. 7.1
xmwx38 Jun 13, 2018
a68960b
Ch. 6.1 - Update README.md
xmwx38 Jun 14, 2018
db6f5f4
Update README.md
xmwx38 Jun 26, 2018
2b39f44
Merge branch 'master' into master
DentFuse Oct 19, 2018
be82ab7
Merge pull request #1 from Steam-Bot-Basics/master
DentFuse Oct 19, 2018
36d5779
Added Chapter 3.3 - Sending Group Invites
DentFuse Oct 21, 2018
078e52c
Added in index
DentFuse Oct 21, 2018
d1106ef
Merge pull request #2 from Steam-Bot-Basics/master
DentFuse Oct 21, 2018
4801d0b
Added commenting and removing friends
DentFuse Oct 23, 2018
281736c
Commenting and Removing friends
DentFuse Oct 23, 2018
ca43214
Merge branch 'master' of https://github.com/DentFuse/node-steam-guide
DentFuse Oct 23, 2018
364f48e
Add newline at EOF
DentFuse Oct 23, 2018
ec572e3
Merge pull request #1 from DentFuse/master
xmwx38 Nov 11, 2018
85dc900
Update Chapter 1.1 README.md
xmwx38 Nov 25, 2018
acd3268
Chapter 1.1 - Updated README.md
xmwx38 Jun 10, 2019
778ac06
Updated README.md
xmwx38 Oct 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Chapter 1 - Basics/Chapter 1.1 - Introduction/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Chapter 1.1 - Introduction

Steam bots can be used for many things, ranging from chat bots to item exchange
websites. Every Steam website you've ever used that takes items or sends you
items uses some form of Steam bot, be it scrap.tf, csgojackpot.com, or so many
more. Throughout this course, we'll learn how to create everything from chat
bots to fully-functioning trade/exchange websites using a series of
mini-projects.
Steam bots can be used for many things:
- Donation Bots
- Chat bots
- Trade bots (in steam or connected to a website)
Websites like scrap.tf, cs.money, and csgojackpot.com all use some sort of steam bot.

Without further adieu, let's jump right into the basics of programming Steam
bots in the next section.
In the next few sections of Chapter 1, you will learn how to begin setting up your very own bot.

[Continue Reading](../Chapter%201.2%20-%20Prerequisites)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Chatting With Friends

So we have added friends, now let's talk to them ! The `steam-user` module
emits an event `friendMessage` whenever a friend messages us. We will use it
as follows :

```js
client.on('friendMessage', (steamid, message) => {
// A friend with `steamid` has sent us a chat message saying `message`
});
```

This also emits two parameters along with the event: the user's `steamid`,
and the message the user has sent us.

Now let's reply to our friend when he sends us a message :

```js
client.on('friendMessage', (steamid, message) => {
client.chatMessage(steamid,"Hello There !");
});
```

Now we have added a listener for the `friendMessage` event. Also we now
reply to any user who sends us a message, regardless of his message. We use the
`.chatMessage` method we learnt about before to send the reply.

Great ! Now the bot talks to us ! Now let's try to teach the bot some specific
replies or commands.

```js
client.on('friendMessage', (steamid, message) => {
if (message === "Hello") {
client.chatMessage(steamid,"Hello There !");
}
});
```

Now we have added a `if` condition that checks if the reply is what we expect.
The bot will now reply with a warm `Hello There !` whenever a user sends a
message saying `Hello`. But the bot won't reply when the expected message
not sent, so to deal with that we add a `else` condition.

```js
client.on('friendMessage', (steamid, message) => {
if (message === "Hello") {
client.chatMessage(steamid,"Hello There !");
} else {
client.chatMessage(steamid,"I failed to understand you :/")
}
});
```

Now the bot will be reply saying `I failed to understand you :/` whenever an
user sends us an unexpected message. Now try adding some of your own `else if`
conditions. A working example of this has been added to the final code.

For the final working code, check out project4.js. Please do try adding an
`else if` condition yourself before seeing the final code, practising on your
own self is better than copy-pasting.


This chapter was written by [@DentFuse](https://github.com/DentFuse) for
[Steam-Bot-Basics/node-steam-guide](https://github.com/Steam-Bot-Basics/node-steam-guide).
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"username": "",
"password": "",
"sharedSecret": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const config = require('./config.json');

const client = new SteamUser();

const logOnOptions = {
accountName: config.username,
password: config.password,
twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
};

client.logOn(logOnOptions);

client.on('loggedOn', () => {
console.log('Logged into Steam');

client.setPersona(SteamUser.Steam.EPersonaState.Online);
client.gamesPlayed(440);
});

client.on('friendRelationship', (steamid, relationship) => {
if (relationship === 2) {
client.addFriend(steamid);
client.chatMessage(steamid, 'Hello there! Thanks for adding me!');
}
});
client.on('friendMessage', (steamid, message) => {
if (message === "Hello") {
client.chatMessage(steamid,"Hello There !");
} else if (message === "Hey") {
client.chatMessage(steamid,"Hey There !")
} else {
client.chatMessage(steamid,"I failed to understand you :/")
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Sending Group Invites

Now after adding friends we might want to send them group invites,
to do this we use the `inviteToGroup` method from the `steam-user` module.

The `inviteToGroup` method takes 2 parameters, the user's steam id to
whom the invite will be sent and the group id of the group. Also the
recipient must be a friend of the bot.
```js
inviteToGroup(userSteamID, groupSteamID)
```

Now let's assume that the steam id and the group id are stored in the
variables `steamid` and `groupid` repectively. Here's how we'll use them
to send a group invite.

```js
client.inviteToGroup(steamid, groupSteamID);
```

This can easily be integrated with the chat system as follows:


```js
client.on('friendMessage', (steamid, message) => {
if (message === "!group") {
client.chatMessage(steamid,"Sending you a Group Invite!");
client.inviteToGroup(steamid, groupSteamID);
}
});
```

This will send a group invite to the message sender whenever he sends us
a `!group` message.

An alternative to this would be to use the `inviteUserToGroup` method of the
`steamcommunity` module. There isn't much difference, the same parameters are
taken by `inviteUserToGroup` too.

```js
client.on('friendMessage', (steamid, message) => {
if (message === "!group") {
client.chatMessage(steamid,"Sending you a Group Invite!");
community.inviteUserToGroup(steamid, groupSteamID);
}
});
```

A working example of this has been added to the `project4.js` file, please
refer to it if you have any issues.

This chapter was written by [@DentFuse](https://github.com/DentFuse) for
[Steam-Bot-Basics/node-steam-guide](https://github.com/Steam-Bot-Basics/node-steam-guide).
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"username": "",
"password": "",
"sharedSecret": "",
"groupID": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const config = require('./config.json');

const client = new SteamUser();

const logOnOptions = {
accountName: config.username,
password: config.password,
twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
};

client.logOn(logOnOptions);

client.on('loggedOn', () => {
console.log('Logged into Steam');

client.setPersona(SteamUser.Steam.EPersonaState.Online);
client.gamesPlayed(440);
});

client.on('friendRelationship', (steamid, relationship) => {
if (relationship === 2) {
client.addFriend(steamid);
client.chatMessage(steamid, 'Hello there! Thanks for adding me!');
}
});
client.on('friendMessage', (steamid, message) => {
if (message === "Hello") {
client.chatMessage(steamid,"Hello There !");
} else if (message === "Hey") {
client.chatMessage(steamid,"Hey There !")
} else if (message === "!group") {
client.chatMessage(steamid,"Sending you a Group Invite!");
client.inviteToGroup(steamid, config.groupID);
// OR
community.inviteUserToGroup(steamid, config.groupID);
} else {
client.chatMessage(steamid,"I failed to understand you :/")
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Commenting On User's Profile & Removing Friends

The `steamcommunity` module also provides us a method to post
comments on a user's profile. this method is `postUserComment`
It takes two parameters, one being the `steamid` of the user,
and the other being the `message` to be posted.

```js
community.postUserComment(steamid,"My comment");
```

This can also be easily integrated with the chat system:

```js
client.on('friendMessage', (steamid, message) => {
if (message === "!comment") {
client.chatMessage(steamid,"Commenting on your profile!");
community.postUserComment(steamid, "My comment");
}
});
```

Now about removing friends. The bot, like any other user has a limit
to the number of friends he can have. So we need to make sure that old
friends, who haven't traded or chatted with the bot in a long time are removed.
To do this we `removeFriend` method from the `steamcommunity` module.

The `removeFriend` takes one parameter, the steamid of the user to remove.

```js
client.removeFriend(steamid);
```

So this is the basics of user interaction. final code has been added to the
`project4.js` file, check it out if you have any problems.

This chapter was written by [@DentFuse](https://github.com/DentFuse) for
[Steam-Bot-Basics/node-steam-guide](https://github.com/Steam-Bot-Basics/node-steam-guide).
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"username": "",
"password": "",
"sharedSecret": "",
"groupID": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const config = require('./config.json');

const client = new SteamUser();

const logOnOptions = {
accountName: config.username,
password: config.password,
twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
};

client.logOn(logOnOptions);

client.on('loggedOn', () => {
console.log('Logged into Steam');

client.setPersona(SteamUser.Steam.EPersonaState.Online);
client.gamesPlayed(440);
});

client.on('friendRelationship', (steamid, relationship) => {
if (relationship === 2) {
client.addFriend(steamid);
client.chatMessage(steamid, 'Hello there! Thanks for adding me!');
}
});
client.on('friendMessage', (steamid, message) => {
if (message === "Hello") {
client.chatMessage(steamid,"Hello There !");
} else if (message === "Hey") {
client.chatMessage(steamid,"Hey There !")
} else if (message === "!group") {
client.chatMessage(steamid,"Sending you a Group Invite!");
client.inviteToGroup(steamid, config.groupID);
// OR
community.inviteUserToGroup(steamid, config.groupID);
} else if (message === "!comment") {
client.chatMessage(steamid,"Commenting on your profile!");
community.postUserComment(steamid, "My comment");
} else if (message === "!remove") {
client.chatMessage(steamid,"See you again later...")
client.removeFriend(steamid)
} else {
client.chatMessage(steamid,"I failed to understand you :/")
}
});
10 changes: 6 additions & 4 deletions Chapter 3 - User Interaction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
## Table of Contents

- [Chapter 3.1 - Friend Requests](./Chapter%203.1%20-%20Friend%20Requests)
- [Chapter 3.2 - Chatting With Friends](./Chapter%203.2%20-%20Chatting%20With%20Friends)
- [Chapter 3.3 - Sending Friend Invites](./Chapter%203.3%20-%20Sending%20Group%20Invites)

## Summary

In this chapter, you will learn how to interact with users by sending friend
requests, handling requests, sending messages, and dealing with various other
interactions.
requests, handling requests, receiving and sending messages, and dealing with
various other interactions.

## Authors

This chapter was written by [@andrewda](https://github.com/andrewda) and
[@Arze1](https://github.com/Arze1).
This chapter was written by [@andrewda](https://github.com/andrewda),
[@Arze1](https://github.com/Arze1) and [@DentFuse](https://github.com/DentFuse).
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ The dependencies we need for this chapter:

- [`passport.socketio`](https://www.npmjs.com/package/passport.socketio)
- [`connect-mongo`](https://www.npmjs.com/package/connect-mongo)
- [`cookie-parser`](https://www.npmjs.com/package/cookie-parser)
- Install [`MongoDB`](https://docs.mongodb.com/manual/installation) CLI

[Continue Reading](../Chapter%206.2%20-%20Getting%20Started)
Loading