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
  • {{this.name}} (${{this.price}})
  • {{/each}} + + + + - - - ``` @@ -45,11 +46,12 @@ templates using Handlebars. First let's create a couple new views: `deposit
  • {{this.name}} (${{this.price}})
  • {{/each}} + + + + - - - ``` @@ -75,11 +77,12 @@ Then we'll change our `main.hbs`: {{else}} Click here to login {{/if}} + + + + - - - ``` diff --git a/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/deposit.hbs b/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/deposit.hbs index d31b3e2..58b6695 100644 --- a/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/deposit.hbs +++ b/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/deposit.hbs @@ -10,9 +10,10 @@
  • {{this.name}} (${{this.price}})
  • {{/each}} + + + + - - - diff --git a/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/main.hbs b/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/main.hbs index 4483d9a..61b2b99 100644 --- a/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/main.hbs +++ b/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/main.hbs @@ -15,9 +15,10 @@ {{else}} Click here to login {{/if}} + + + + - - - diff --git a/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/withdraw.hbs b/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/withdraw.hbs index 126a9e8..55f89a7 100644 --- a/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/withdraw.hbs +++ b/Chapter 6 - Connecting Sites and Bots/Chapter 6.2 - Getting Started/project10/views/withdraw.hbs @@ -10,9 +10,10 @@
  • {{this.name}} (${{this.price}})
  • {{/each}} + + + + - - - diff --git a/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/deposit.hbs b/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/deposit.hbs index d31b3e2..58b6695 100644 --- a/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/deposit.hbs +++ b/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/deposit.hbs @@ -10,9 +10,10 @@
  • {{this.name}} (${{this.price}})
  • {{/each}} + + + + - - - diff --git a/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/main.hbs b/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/main.hbs index 4483d9a..61b2b99 100644 --- a/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/main.hbs +++ b/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/main.hbs @@ -15,9 +15,10 @@ {{else}} Click here to login {{/if}} + + + + - - - diff --git a/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/withdraw.hbs b/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/withdraw.hbs index 126a9e8..55f89a7 100644 --- a/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/withdraw.hbs +++ b/Chapter 6 - Connecting Sites and Bots/Chapter 6.3 - Beginning the Connection/project10/views/withdraw.hbs @@ -10,9 +10,10 @@
  • {{this.name}} (${{this.price}})
  • {{/each}} + + + + - - - diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/README.md b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/README.md new file mode 100644 index 0000000..2cb3563 --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/README.md @@ -0,0 +1,45 @@ +# Chapter 7.1 - Simple Updates + +We'll be using our code from [Chapter 6.3](../../Chapter%206%20-%20Connecting%20Sites%20and%20Bots/Chapter%206.3%20-%20Beginning%20the%20Connection). Let's name it `project11`. + +First we'll edit `./views/main.hbs`... + +```html + + + + + + Steam Trades + + + + {{#if user}} +
    +

    Welcome, {{user.personaname}} +

    +
    +

    You have {{#if user.credits}}{{user.credits}}{{else}}0{{/if}} credits

    +
    +
    +
  • Deposit
  • +
  • Withdraw
  • +
    +
    +
    +
  • Logout
  • +
    + {{else}} +
    + Login through +
    + {{/if}} + + + + + + + +``` +We added `Font-Awesome` support & made use of it. Also, many `div` containers have been created, and `class` tags added. The login message has been changed, and a Steam icon added to it. The "welcome" header now includes the user's avatar after their name. Their have been some style additions to the headers. A list container was added to the "Deposit", "Withdraw", and "Logout" buttons. diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/app.js b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/app.js new file mode 100644 index 0000000..a3e5920 --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/app.js @@ -0,0 +1,234 @@ +const express = require('express'); +const handlebars = require('express-handlebars'); +const session = require('express-session'); +const cookieParser = require('cookie-parser'); +const passportSocket = require('passport.socketio'); +const async = require('async'); +const passport = require('passport'); +const SteamStrategy = require('passport-steam').Strategy; +const path = require('path'); +const mongoose = require('mongoose'); +const http = require('http'); +const socket = require('socket.io'); +const MongoStore = require('connect-mongo')(session); +const SteamCommunity = require('steamcommunity'); + +const Inventory = require('./models/inventory'); +const Item = require('./models/item'); +const User = require('./models/user'); +const Price = require('./models/price'); + +const priceUpdater = require('./helpers/priceUpdater'); + +const app = express(); +const server = http.Server(app); +const io = socket(server); +const hbs = handlebars.create(); +const community = new SteamCommunity(); +const sessionStore = new MongoStore({ + mongooseConnection: mongoose.connection +}); + +mongoose.connect('mongodb://127.0.0.1:27017/guide'); +priceUpdater(6 * 60 * 60 * 1000); + +passport.serializeUser((user, done) => { + User.update( + { + steamid: user.id + }, + { + $set: user._json + }, + { upsert: true }, + err => { + done(err, user._json); + } + ); +}); + +passport.deserializeUser((obj, done) => { + User.findOne( + { + steamid: obj.steamid + }, + (err, user) => { + done(err, user); + } + ); +}); + +passport.use( + new SteamStrategy( + { + returnURL: 'http://localhost:3037/auth/steam/return', + realm: 'http://localhost:3037/', + apiKey: config.apiKey + }, + (identifier, profile, done) => { + return done(null, profile); + } + ) +); + +io.use( + passportSocket.authorize({ + cookieParser: cookieParser, + key: 'U_SESSION', + secret: config.secretString, + store: sessionStore + }) +); + +io.on('connection', socket => { + socket.on('deposit', data => { + const user = socket.request.user; + console.log(`${user.personaname} is depositting ${data.assetid}`); + // we'll send the trade offer here + }); + + socket.on('withdraw', data => { + const user = socket.request.user; + console.log(`${user.personaname} is withdrawing ${data.assetid}`); + // we'll send the trade offer here + }); +}); + +app.engine('hbs', hbs.engine); +app.set('views', path.join(__dirname, 'views')); +app.set('view engine', 'hbs'); + +app.use( + session({ + secret: config.secretString, + name: 'U_SESSION', + resave: true, + saveUninitialized: true, + store: sessionStore + }) +); + +app.use(passport.initialize()); +app.use(passport.session()); +app.use(express.static('public')); +app.use(cookieParser()); + +app.get('/', (req, res) => { + res.render('main', { + user: req.user + }); +}); + +app.get('/deposit', (req, res) => { + if (req.user) { + Inventory.findOne( + { + steamid: req.user.steamid + }, + (err, inv) => { + if (inv && Date.now() - inv.updated < 6 * 60 * 60 * 1000) { + res.render('deposit', { + user: req.user, + items: inv.items + }); + } else { + community.getUserInventoryContents( + req.user.steamid, + 730, + 2, + true, + (err, inv) => { + if (err) { + console.log(err); + } else { + async.map( + inv, + (item, done) => { + Price.findOne( + { + market_hash_name: item.market_hash_name + }, + (err, doc) => { + item.price = doc ? doc.price : '?'; + done(null, item); + } + ); + }, + (err, results) => { + Inventory.update( + { + steamid: req.user.steamid + }, + { + $set: { + updated: Date.now(), + items: results + } + }, + err => { + if (err) { + console.log(err); + } + } + ); + + res.render('deposit', { + user: req.user, + items: results + }); + } + ); + } + } + ); + } + } + ); + } else { + res.redirect('/auth/steam'); + } +}); + +app.get('/withdraw', (req, res) => { + if (req.user) { + Item.find({}, (err, inv) => { + async.map( + inv, + (item, done) => { + Price.findOne( + { + market_hash_name: item.name + }, + (err, doc) => { + item.price = doc ? doc.price : '?'; + done(null, item.toObject()); + } + ); + }, + (err, results) => { + res.render('withdraw', { + user: req.user, + items: results + }); + } + ); + }); + } else { + res.redirect('/auth/steam'); + } +}); + +app.get( + /^\/auth\/steam(\/return)?$/, + passport.authenticate('steam', { failureRedirect: '/' }), + (req, res) => { + res.redirect('/'); + } +); + +app.get('/logout', (req, res) => { + req.logout(); + res.redirect('/'); +}); + +server.listen(3037); diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/config.json b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/config.json new file mode 100644 index 0000000..242c679 --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/config.json @@ -0,0 +1,4 @@ +{ + "apiKey": "", + "secretString": "" +} diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/helpers/priceUpdater.js b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/helpers/priceUpdater.js new file mode 100644 index 0000000..9b8ca91 --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/helpers/priceUpdater.js @@ -0,0 +1,41 @@ +const _ = require('lodash'); +const request = require('request'); + +const Price = require('../models/price'); + +module.exports = interval => { + update(); + + setInterval(update, interval); +}; + +function update() { + request('https://api.csgofast.com/price/all', (err, response, body) => { + if (err) { + console.log(err); + } else { + let json = {}; + + try { + json = JSON.parse(body); + } catch (e) { + console.log(e); + } + + _.forOwn(json, (price, market_hash_name) => { + Price.update( + { market_hash_name }, + { + $set: { price } + }, + { upsert: true }, + err => { + if (err) { + console.log(err); + } + } + ); + }); + } + }); +} diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/inventory.js b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/inventory.js new file mode 100644 index 0000000..6d363ad --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/inventory.js @@ -0,0 +1,14 @@ +const mongoose = require('mongoose'); + +module.exports = mongoose.model('Inventory', { + steamid: String, + updated: Number, + items: [ + { + market_name: String, + assetid: String, + image: String, + price: Number + } + ] +}); diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/item.js b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/item.js new file mode 100644 index 0000000..8ccf63e --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/item.js @@ -0,0 +1,8 @@ +const mongoose = require('mongoose'); + +module.exports = mongoose.model('Item', { + market_hash_name: String, + assetid: String, + image: String, + price: Number +}); diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/price.js b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/price.js new file mode 100644 index 0000000..b87affd --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/price.js @@ -0,0 +1,6 @@ +const mongoose = require('mongoose'); + +module.exports = mongoose.model('Price', { + market_hash_name: String, + price: Number +}); diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/user.js b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/user.js new file mode 100644 index 0000000..58161d4 --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/models/user.js @@ -0,0 +1,8 @@ +const mongoose = require('mongoose'); + +module.exports = mongoose.model('User', { + steamid: String, + personaname: String, + avatar: String, + avatarfull: String +}); diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/public/main.js b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/public/main.js new file mode 100644 index 0000000..243088c --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/public/main.js @@ -0,0 +1,21 @@ +var socket = io(); + +$( + (function() { + $('.deposit.item').click(function(one, two) { + socket.emit('deposit', { + assetid: $(this).data('assetid') + }); + + alert('We will send you a tradeoffer for your ' + $(this).text()); + }); + + $('.withdraw.item').click(function(one, two) { + socket.emit('withdraw', { + assetid: $(this).data('assetid') + }); + + alert('We will send you a tradeoffer with a ' + $(this).text()); + }); + })() +); diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/views/deposit.hbs b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/views/deposit.hbs new file mode 100644 index 0000000..58b6695 --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/views/deposit.hbs @@ -0,0 +1,19 @@ + + + + Deposit + + +

    Deposit Items

    + + + + + + + + diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/views/main.hbs b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/views/main.hbs new file mode 100644 index 0000000..ef0f919 --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/views/main.hbs @@ -0,0 +1,33 @@ + + + + Steam Trades + + + {{#if user}} +
    +

    Welcome, {{user.personaname}} +

    +
    +

    You have {{#if user.credits}}{{user.credits}}{{else}}0{{/if}} credits

    +
    +
    +
  • Deposit
  • +
  • Withdraw
  • +
    +
    +
    +
  • Logout
  • +
    + {{else}} +
    + Login through +
    + {{/if}} + + + + + + + diff --git a/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/views/withdraw.hbs b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/views/withdraw.hbs new file mode 100644 index 0000000..55f89a7 --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/Chapter 7.1 - Simple Updates/project11/views/withdraw.hbs @@ -0,0 +1,19 @@ + + + + Withdraw + + +

    Withdraw Items

    + + + + + + + + diff --git a/Chapter 7 - Updating the Handlebars Frontend/README.md b/Chapter 7 - Updating the Handlebars Frontend/README.md new file mode 100644 index 0000000..3204de0 --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/README.md @@ -0,0 +1,13 @@ +# Chapter 7 - Updating the Handlebars Frontend + +## Table of Contents + +- [Chapter 7.1 - Simple Updates](./Chapter%207.1%20-%20Simple%20Updates) + +## Summary + +This chapter will be about updating the handlebars frontend. + +## Authors + +This chapter was written by [@xmwx38](https://github.com/xmwx38). diff --git a/Chapter 7 - Updating the Handlebars Frontend/package.json b/Chapter 7 - Updating the Handlebars Frontend/package.json new file mode 100644 index 0000000..7f6f6fe --- /dev/null +++ b/Chapter 7 - Updating the Handlebars Frontend/package.json @@ -0,0 +1,21 @@ +{ + "name": "project10", + "version": "1.0.0", + "license": "CC-BY-4.0", + "dependencies": { + "connect-mongo": "^1.3.2", + "express": "^4.15.3", + "express-handlebars": "^3.0.0", + "express-session": "^1.15.3", + "mongoose": "^4.11.1", + "morgan": "^1.8.2", + "passport": "^0.3.2", + "passport-steam": "^1.0.8", + "passport.socketio": "^3.7.0", + "socket.io": "^2.0.3", + "steam-totp": "^2.0.1", + "steam-tradeoffer-manager": "^2.8.0", + "steam-user": "^3.21.7", + "steamcommunity": "^3.31.0" + } +} diff --git a/README.md b/README.md index dc9169e..9f4555d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ -# Andrew's Guide to Steam Bots +# Guide to Steam Bots +### Forked from [andrewda/node-steam-guide](https://github.com/andrewda/node-steam-guide) [![Codacy][codacy-img]][codacy-url] -[![PayPal][paypal-img]][paypal-url] -[![Steam Donate][steam-img]][steam-url] [![Creative Commons][cc-img]][cc-url] @@ -13,32 +12,36 @@ A complete guide to building Steam bots using Node.js. ## Table of Contents - [Chapter 1 - Basics](./Chapter%201%20-%20Basics) - - [Chapter 1.1 - Introduction](./Chapter%201%20-%20Basics/Chapter%201.1%20-%20Introduction) - - [Chapter 1.2 - Prerequisites](./Chapter%201%20-%20Basics/Chapter%201.2%20-%20Prerequisites) - - [Chapter 1.3 - Starting to Code](./Chapter%201%20-%20Basics/Chapter%201.3%20-%20Starting%20to%20Code) - - [Chapter 1.4 - TOTP](./Chapter%201%20-%20Basics/Chapter%201.4%20-%20TOTP) - - [Chapter 1.5 - Errors](./Chapter%201%20-%20Basics/Chapter%201.5%20-%20Errors) + - [Chapter 1.1 - Introduction](./Chapter%201%20-%20Basics/Chapter%201.1%20-%20Introduction) + - [Chapter 1.2 - Prerequisites](./Chapter%201%20-%20Basics/Chapter%201.2%20-%20Prerequisites) + - [Chapter 1.3 - Starting to Code](./Chapter%201%20-%20Basics/Chapter%201.3%20-%20Starting%20to%20Code) + - [Chapter 1.4 - TOTP](./Chapter%201%20-%20Basics/Chapter%201.4%20-%20TOTP) + - [Chapter 1.5 - Errors](./Chapter%201%20-%20Basics/Chapter%201.5%20-%20Errors) - [Chapter 2 - Trading](./Chapter%202%20-%20Trading) - - [Chapter 2.1 - Prerequisites](./Chapter%202%20-%20Trading/Chapter%202.1%20-%20Prerequisites) - - [Chapter 2.2 - Handling Trade Offers](./Chapter%202%20-%20Trading/Chapter%202.2%20-%20Handling%20Trade%20Offers) - - [Chapter 2.3 - Sending Trade Offers](./Chapter%202%20-%20Trading/Chapter%202.3%20-%20Sending%20Trade%20Offers) - - [Chapter 2.4 - Accepting Donations](./Chapter%202%20-%20Trading/Chapter%202.4%20-%20Accepting%20Donations) -- [Chapter 3 - User Interaction](./Chapter%203%20-%20User%20Interaction) - - [Chapter 3.1 - Friend Requests](./Chapter%203%20-%20User%20Interaction/Chapter%203.1%20-%20Friend%20Requests) + - [Chapter 2.1 - Prerequisites](./Chapter%202%20-%20Trading/Chapter%202.1%20-%20Prerequisites) + - [Chapter 2.2 - Handling Trade Offers](./Chapter%202%20-%20Trading/Chapter%202.2%20-%20Handling%20Trade%20Offers) + - [Chapter 2.3 - Sending Trade Offers](./Chapter%202%20-%20Trading/Chapter%202.3%20-%20Sending%20Trade%20Offers) + - [Chapter 2.4 - Accepting Donations](./Chapter%202%20-%20Trading/Chapter%202.4%20-%20Accepting%20Donations) +- [Chapter 3 - User +Interaction](./Chapter%203%20-%20User%20Interaction) + - [Chapter 3.1 - Friend Requests](./Chapter%203%20-%20User%20Interaction/Chapter%203.1%20-%20Friend%20Requests) + - [Chapter 3.2 - Chatting With Friends](./Chapter%203%20-%20User%20Interaction/Chapter%203.2%20-%20Chatting%20With%20Friends) + - [Chapter 3.3 - Sending Friend Invites](./Chapter%203%20-%20User%20Interaction/Chapter%203.3%20-%20Sending%20Group%20Invites) - [Chapter 4 - Basics of Web Development](./Chapter%204%20-%20Basics%20of%20Web%20Development) - - [Chapter 4.1 - Prerequisites](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.1%20-%20Prerequisites) - - [Chapter 4.2 - Base App](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.2%20-%20Base%20App) - - [Chapter 4.3 - Templates](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.3%20-%20Templates) - - [Chapter 4.4 - Databases](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.4%20-%20Databases) - - [Chapter 4.5 - WebSockets](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.5%20-%20WebSockets) + - [Chapter 4.1 - Prerequisites](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.1%20-%20Prerequisites) + - [Chapter 4.2 - Base App](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.2%20-%20Base%20App) + - [Chapter 4.3 - Templates](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.3%20-%20Templates) + - [Chapter 4.4 - Databases](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.4%20-%20Databases) + - [Chapter 4.5 - WebSockets](./Chapter%204%20-%20Basics%20of%20Web%20Development/Chapter%204.5%20-%20WebSockets) - [Chapter 5 - Advanced Web Development](./Chapter%205%20-%20Advanced%20Web%20Development) - - [Chapter 5.1 - Prerequisites](./Chapter%205%20-%20Advanced%20Web%20Development/Chapter%205.1%20-%20Prerequisites) - - [Chapter 5.2 - Authentication](./Chapter%205%20-%20Advanced%20Web%20Development/Chapter%205.2%20-%20Authentication) + - [Chapter 5.1 - Prerequisites](./Chapter%205%20-%20Advanced%20Web%20Development/Chapter%205.1%20-%20Prerequisites) + - [Chapter 5.2 - Authentication](./Chapter%205%20-%20Advanced%20Web%20Development/Chapter%205.2%20-%20Authentication) - [Chapter 6 - Connecting Sites and Bots](./Chapter%206%20-%20Connecting%20Sites%20and%20Bots) - - [Chapter 6.1 - Prerequisites](./Chapter%206%20-%20Connecting%20Sites%20and%20Bots/Chapter%206.1%20-%20Prerequisites) - - [Chapter 6.2 - Getting Started](./Chapter%206%20-%20Connecting%20Sites%20and%20Bots/Chapter%206.2%20-%20Getting%20Started) - - [Chapter 6.3 - Beginning the Connection](./Chapter%206%20-%20Connecting%20Sites%20and%20Bots/Chapter%206.3%20-%20Beginning%20the%20Connection) - + - [Chapter 6.1 - Prerequisites](./Chapter%206%20-%20Connecting%20Sites%20and%20Bots/Chapter%206.1%20-%20Prerequisites) + - [Chapter 6.2 - Getting Started](./Chapter%206%20-%20Connecting%20Sites%20and%20Bots/Chapter%206.2%20-%20Getting%20Started) + - [Chapter 6.3 - Beginning the Connection](./Chapter%206%20-%20Connecting%20Sites%20and%20Bots/Chapter%206.3%20-%20Beginning%20the%20Connection) +- [Chapter 7 - Updating the Handlebars Frontend](./Chapter%207%20-%20Updating%20the%20Handlebars%20Frontend) + - [Chapter 7.1 - Simple Updates](./Chapter%207%20-%20Updating%20the%20Handlebars%20Frontend/Chapter%207.1%20-%20Simple%20Updates) *(more chapters to come)* @@ -70,21 +73,11 @@ http://cs.money/. Please read the [contribution guidelines](/CONTRIBUTING.md) before creating a Pull Request. -## Donating - -If you found this guide useful, there are a few ways for you to support me and -keep this project going: -- [Steam](https://steamcommunity.com/tradeoffer/new/?partner=132224795&token=HuEE9Mk1) -- [Patreon](https://www.patreon.com/andrewda) [codacy-img]: https://img.shields.io/codacy/grade/5822ba91cc994725932f71ee6b926400.svg?style=flat-square -[codacy-url]: https://www.codacy.com/app/andrewda/node-steam-guide -[paypal-img]: https://img.shields.io/badge/donate-PayPal-blue.svg?style=flat-square -[paypal-url]: https://www.paypal.me/andrewda/5 -[steam-img]: https://img.shields.io/badge/donate-Steam-lightgrey.svg?style=flat-square -[steam-url]: https://steamcommunity.com/tradeoffer/new/?partner=132224795&token=HuEE9Mk1 +[codacy-url]: https://app.codacy.com/app/Steam-Bot-Basics/node-steam-guide/dashboard [cc-img]: https://i.creativecommons.org/l/by/4.0/88x31.png [cc-url]: https://creativecommons.org/licenses/by/4.0/ diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..c419263 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file