diff --git a/Chapter 1 - Basics/Chapter 1.1 - Introduction/README.md b/Chapter 1 - Basics/Chapter 1.1 - Introduction/README.md index 2d4fa82..40e78ee 100644 --- a/Chapter 1 - Basics/Chapter 1.1 - Introduction/README.md +++ b/Chapter 1 - Basics/Chapter 1.1 - Introduction/README.md @@ -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) diff --git a/Chapter 3 - User Interaction/Chapter 3.2 - Chatting With Friends/README.md b/Chapter 3 - User Interaction/Chapter 3.2 - Chatting With Friends/README.md new file mode 100644 index 0000000..07a9e41 --- /dev/null +++ b/Chapter 3 - User Interaction/Chapter 3.2 - Chatting With Friends/README.md @@ -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). diff --git a/Chapter 3 - User Interaction/Chapter 3.2 - Chatting With Friends/config.json b/Chapter 3 - User Interaction/Chapter 3.2 - Chatting With Friends/config.json new file mode 100644 index 0000000..2fe64e4 --- /dev/null +++ b/Chapter 3 - User Interaction/Chapter 3.2 - Chatting With Friends/config.json @@ -0,0 +1,5 @@ +{ + "username": "", + "password": "", + "sharedSecret": "" +} diff --git a/Chapter 3 - User Interaction/Chapter 3.2 - Chatting With Friends/project4.js b/Chapter 3 - User Interaction/Chapter 3.2 - Chatting With Friends/project4.js new file mode 100644 index 0000000..ed8bbea --- /dev/null +++ b/Chapter 3 - User Interaction/Chapter 3.2 - Chatting With Friends/project4.js @@ -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 :/") + } +}); \ No newline at end of file diff --git a/Chapter 3 - User Interaction/Chapter 3.3 - Sending Group Invites/README.md b/Chapter 3 - User Interaction/Chapter 3.3 - Sending Group Invites/README.md new file mode 100644 index 0000000..3986cbe --- /dev/null +++ b/Chapter 3 - User Interaction/Chapter 3.3 - Sending Group Invites/README.md @@ -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). diff --git a/Chapter 3 - User Interaction/Chapter 3.3 - Sending Group Invites/config.json b/Chapter 3 - User Interaction/Chapter 3.3 - Sending Group Invites/config.json new file mode 100644 index 0000000..4eca841 --- /dev/null +++ b/Chapter 3 - User Interaction/Chapter 3.3 - Sending Group Invites/config.json @@ -0,0 +1,6 @@ +{ + "username": "", + "password": "", + "sharedSecret": "", + "groupID": "" +} diff --git a/Chapter 3 - User Interaction/Chapter 3.3 - Sending Group Invites/project4.js b/Chapter 3 - User Interaction/Chapter 3.3 - Sending Group Invites/project4.js new file mode 100644 index 0000000..6208508 --- /dev/null +++ b/Chapter 3 - User Interaction/Chapter 3.3 - Sending Group Invites/project4.js @@ -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 :/") + } +}); \ No newline at end of file diff --git a/Chapter 3 - User Interaction/Chapter 3.4 - Commenting on Profile & Removing Friends/README.md b/Chapter 3 - User Interaction/Chapter 3.4 - Commenting on Profile & Removing Friends/README.md new file mode 100644 index 0000000..b727351 --- /dev/null +++ b/Chapter 3 - User Interaction/Chapter 3.4 - Commenting on Profile & Removing Friends/README.md @@ -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). diff --git a/Chapter 3 - User Interaction/Chapter 3.4 - Commenting on Profile & Removing Friends/config.json b/Chapter 3 - User Interaction/Chapter 3.4 - Commenting on Profile & Removing Friends/config.json new file mode 100644 index 0000000..4eca841 --- /dev/null +++ b/Chapter 3 - User Interaction/Chapter 3.4 - Commenting on Profile & Removing Friends/config.json @@ -0,0 +1,6 @@ +{ + "username": "", + "password": "", + "sharedSecret": "", + "groupID": "" +} diff --git a/Chapter 3 - User Interaction/Chapter 3.4 - Commenting on Profile & Removing Friends/project4.js b/Chapter 3 - User Interaction/Chapter 3.4 - Commenting on Profile & Removing Friends/project4.js new file mode 100644 index 0000000..9ec170d --- /dev/null +++ b/Chapter 3 - User Interaction/Chapter 3.4 - Commenting on Profile & Removing Friends/project4.js @@ -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 :/") + } +}); diff --git a/Chapter 3 - User Interaction/README.md b/Chapter 3 - User Interaction/README.md index 5f673f3..d0fde4b 100644 --- a/Chapter 3 - User Interaction/README.md +++ b/Chapter 3 - User Interaction/README.md @@ -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). diff --git a/Chapter 6 - Connecting Sites and Bots/Chapter 6.1 - Prerequisites/README.md b/Chapter 6 - Connecting Sites and Bots/Chapter 6.1 - Prerequisites/README.md index ffad5b5..64b471f 100644 --- a/Chapter 6 - Connecting Sites and Bots/Chapter 6.1 - Prerequisites/README.md +++ b/Chapter 6 - Connecting Sites and Bots/Chapter 6.1 - Prerequisites/README.md @@ -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) diff --git a/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/README.md b/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/README.md index 3fd86ec..fd72fb4 100644 --- a/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/README.md +++ b/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/README.md @@ -22,11 +22,12 @@ templates using Handlebars. First let's create a couple new views: `deposit