如何做steam交易機器人?
像菠菜網那種
你得有一堆號,還要有一堆手機,而且這堆手機要記得全部交好話費然後初步你就可以觀察觀察市場然後做個人體機器人了
自己剛剛在網上看到的:
POSTED ON DECEMBER 2, 2014BY RANNMANNIN DEVELOPERSWITH 53097 VIEWS
Creating a Steam Trade Bot with Node.js
Update 2015-07-25: node-steam v1.0 recently was released. A lot of the functionality of node-steam has drastically changed with this update. Make sure to install version 0.6.8 when following this guide. A new version of this article using node-steam 1.0 and trade offers can be found here: Creating a Steam Trade Bot with Node.js/IO.js (Updated for Node-Steam v1.0)
The first part of this article provides some background into Steam trade bots, what options are available, how to setup your system to use Node, and some of the packages you』ll need to get started. Beyond the first section, I』ll stop talking in generalizations and focus on one specific example. If you are new to the trade bot scene, please start from the beginning. If you』re just trying to get a handle on how to write a trade bot but understand what libraries you』ll need, go ahead and skip down to 「Writing your first bot」.
Background, environment, and required packagesCreating a Steam trade bot is easier today than it ever has been due to the amount of open source libraries out there. There are two common libraries available for making a Steam trade bot: Jessecar』s C# version (which uses VoiDeD』s SteamKitlibrary), and Seishun』s Node.js version (which requires his port of SteamKit). There are some less-common ones floating around in Java and Python, but they』re mostly dead projects. For this article though, we』ll be focusing on just the Node.js version since JavaScript is both more portable and easier to write than C#.
Setting up your environmentNote: I』ve never really done development work on Windows, so any Windows-specific instructions may be a little rough.
Linux (CentOS 7)Assuming a fresh install, you』ll need to setup some extra repos.
RPMForge is optional, but it』s a common thing to enable. These versions may change over time, but as of Dec 2014 the links are up to date. If you』re running CentOS 6, or just want some more information on what we』re doing, you can follow the instructions at my wife』s blog instead.
123
45678yum -y install yum-protectbase # protect base repos# install EPELrpm -Uvh http://mirrors.kernel.org/fedora-epel/7/x86_64/e/epel-release-7-2.noarch.rpm# install rpmforgewget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt # import keysrpm -K rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm # verify package integrityrpm -i rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm # installWith EPEL repos setup, installing Node.js is the same as any other package. We also need git to install repos that aren』t in the npm ecosystem. Git is likely installed already, but just in case it』s not try to install it anyway.
1yum -y install npm nodejs gitCreate a new directory wherever you want your trade bot to live, such as ~/steamtrade/ and you』re ready to start your project.
Windows 7Grab a snack; this one could take a while. I spent about four hours to finally get everything working, but hopefully with the notes below it will got a bit smoother for you.
Download the Node.js installer. Install with default settings.
Edit 2015-05-22: You also need git to clone a node repo outisde of NPM: Git - Installing Git. Make sure it』s in your PATH otherwise npm can』t use it. If you install git and open a terminal (cmd/powershell), you can type 「git」 to see if it』s available. If it』s not working, add it to the PATH in the same way that Python is added below in the paragraph below.
Some of the dependencies require special packages on Windows to compile. First we need to grab an old version of Python, which is pretty quick and painless. Python 2.7.6 is the newest supported version, but anything in the v2 range will do. Version beyond 3.0 will cause builds to fail. If you already have 3+ installed, update your path with the older version. Sometimes the install will fail to update your path, so you』ll need to add it. If you used the default install options, just append the following to your path:
1;C:Python27There』s some conflicting information about this next part. According to the author, you need Visual Studio 2010 for the ursadependency (2012 for Win8). The express version is supposed to work, but I had no luck. After some trial and error, I eventually installed the full version of Visual Studio 2013 (Warning: this is a few gigs).
If you』re running 64-bit Node.js, you may also need the Windows 7 64-bit SDK (~60MB).
You also need the normal version (not Light) of OpenSSL should be installed to either C:OpenSSL-Win32 or C:OpenSSL-Win64.
If you run into errors installing Steam through npm later, you may need a compiler update for the Windows SDK 7.1, but I don』t think you actually need this with Visual Studio 2013.
Open the command prompt (cmd.exe) and navigate to your project directory. In my case, I』m working from C:Users
annmanngitCrateDump.
annmanngit&>mkdir CrateDumpC:Users
annmanngit&>cd CrateDumpC:Users
annmanngitCrateDump&>Installing dependencies
Run the following from the command line. It can take a while for protobuf to install and you』ll see a lot of warnings, but this is normal.
1
npm install steam@0.6.8 winstonTip: If this is a project box where you』re going to be experimenting with lots of trade bots, you can add the 「-g」 option to install these packages globally (sudo required on Linux) so you won』t have to install them for each project individually.
WINDOWS: If your build is failing with something like error MSB6006: "CL.exe" exited with code -1073741515, visual studio not found errors, or fatal error LNK1181: cannot open input file kernel32.lib, then you either did not install the SDK or npm is trying to build with the wrong version of Visual Studio. Yellow warnings are normal, red errors are not. I ran into an issue where npm was trying to use the wrong version of Visual Studio or completely unable to find any version. This can be fixed by manually specifying what version we want. Since I』m using Visual Studio 2013, here』s the command I ran.
1npm install steam@0.6.8 winston --msvs_version=2013A breakdown of the packages we』re installing:
- Steam – Seishun』s SteamKit port to Node.js. It has fewer features than the C# version, but it does more than enough (and is soooo much lighter)
- fs – Allows the use of filesystem operations. Ex: read/write files. We use this to save our Steam Guard information. Edit: This no longer needs installed via NPM.
- winston – A really nice logging tool, for both log files and the console.
- readline – Allows for user interaction in the terminal. We use this to enter Steam Guard codes when needed. Edit: This no longer needs installed via NPM.
Now you get to choose whether you want to use Steam trade offers or directly interact with users through the old-fashioned trades. It really comes down to what you want to do. If the main interface is a website, trade offers may work better for you. If you have no interface at all, regular trades are probably the best solution. You can always build a text-based interface through Steam chat. Take a moment and really plan how you want users to interact with this bot; your decision will affect the entire development process.
There is nothing preventing you from using both, but keep in mind that you will need to write handlers for each method, even if they achieve the same goal.
Steam Trade Offers
Trade offers are often troublesome due to cryptic errors only displaying numbers, failures for seemingly no reason, or sometimes, very rarely, a trade will be marked as failed even though it succeeded (and vise versa). This means you』ll need to do extra error checking after the trade has returned success/fail to make sure it really did what Steam is telling you.
Even with these flaws, lately I』ve been using trade offers over regular trades on a near exclusive basis. There』s less chance for trickery by users and latency isn』t an issue. Heck, the bot could even crash 20 times before accepting a trade offer and the user may not even notice.
The documentation and installation instructions for trade offers can be found in the github repo by Alexey Komarov. If you just want to get started now though, you can type the following:
1npm install steam-tradeoffersAlternatively, Steve Rabouin, better known as Backpack.tf』s Brad Pitt, has a fork of this repo with some slight changes. It tends to receive updates quicker, but I don』t have a great reason why you should use it.
1npm install git://http://github.com/srabouin/node-steam-tradeoffers.gitThis article will not include examples for trade offers.
Steam TradingRegular trading is a fairly straight-forward, but you need to lookout for users trying to exploit your bot. There are ways to trick the bot into thinking an item was put up when it wasn』t, or thinking a worthless item is a more valuable item. You can always add extra checks to decrease the likelihood of being stolen from, but bots can never be as smart as a human. The more direct interaction users can have with it, the more opportunities for things to go wrong. In general though, this Node library is pretty solid. If used correctly you shouldn』t have any problems with thieves.
One interesting issue I』ve run into is with bot-on-bot interactions using live trading. Events can fire off so quickly that one bot can put up its entire inventory before the other one even starts looking for items to go into the trade window. One may see 70 items posted, the other may see 0. In the past I』ve had to use a handful of setTimeout callbacks to achieve moderate success between bots. Trade offers would be a better solution for exchanging between bots.
Nonetheless, most use cases work well with regular Steam trading. If you』re not sure which to choose, this library is probably the easiest to learn from since you can interact with the bot while testing in stages. Using trade offers means everything is submitted it one go and you have to parse all the responses from within Node.
The steam trading repo is maintained by the same person who built the Steam library for Node.js. It is not published through the Node Package Manager (NPM), so you』ll need to specify the git URL to install it.
1npm install git://http://github.com/seishun/node-steam-trade.gitSteam API KeyOne last thing before we start coding. You might want a Steam Web API key for loading anything off the official API, such as the TF2 item schema. If you don』t already have one, you can get one assigned to your account here: Steam Community. Most projects don』t actually need this (the project here won』t), but if you want to do complex item filtering then you should grab the schema first and cross-reference items via their defindex and quality values.
Writing your first botIn this example we』ll be building a crate dump bot. It seems like a silly thing to build, but I』ve had a huge number of requests to make another one since the original crate dump bot I wrote (in C#) stopped working over a year ago. I promised I would write another, so consider this a promise fulfilled wrapped in a tutorial.
The idea is that everyone playing TF2 is swamped with crates, but occasionally someone wants to go on an unboxing spree and requires a bunch of a specific series. They can trade the bot and ask it to put up 20 crates of series 54, for example, and it does so free of charge. Think of the 「Need a penny? Take a penny. Have a penny? Leave a penny,」 trays at your local store.
Build the corePretty much every project starts off looking the same: define all your required libraries, login to Steam, deal with Steam guard codes if needed, connect to the web interface, and listen for various events to fire (ex: chat messages, trade requests). This is boring, but it』s good to learn at least once. Build your own quickstart repository and you』ll be set to launch future projects much quicker.
A lot of this stuff is pretty easy to understand and breaking it up in sections might make it more confusing. Follow along with the comments for a bit.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137// In practice we would use a config.json file, but for this example well// just do it inline.username = your_username; // Bots Steam Usernamepassword = your_password; // Bots Steam Password// Define all our included variablesvar steam = require(steam);var steamtrade = require(steam-trade);var winston = require(winston);var readline = require(readline);var fs = require(fs);// We have to use application IDs in our requests, so this is just a helpervar appid = { TF2: 440, Steam: 753};// We also have to know context IDs which are a bit tricker.// For Steam, ID 1 is gifts, and 6 is trading cards, emoticons, backgrounds// For TF2 and DOTA we always use 2. These are just some default values.var contextid = { TF2: 2, Steam: 6}// Well reference this to make sure were only in one trade at a time.var inTrade = false;// Since were taking user input inside the trade window, we have to make our// inventory global. Otherwise our trade chat listener doesnt know what we have.var myBackpack;// Setup readline to read from console. This is used for Steam Guard codes.var rl = readline.createInterface({ input: process.stdin, output: process.stdout});// Setup logging to file and consolevar logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({ colorize: true, level: debug }), new (winston.transports.File)({ level: info, timestamp: true, filename: cratedump.log, json: false }) ]});// Initialize the Steam client and our trading libraryvar client = new steam.SteamClient();var trade = new steamtrade();// Our library has a list of Steam servers in case one isnt provided.// You can define them if you want to make sure theyre accurate;// Just make sure to keep them up to date or you could run into issues.if(fs.existsSync(servers.json)) { steam.servers = JSON.parse(fs.readFileSync(servers.json));}// We can provide a sentry file for Steam Guard when we login to avoid// having to enter a code each time. If we have one saved to file, use it.var sentryfile;if(fs.existsSync(sentryfile. + username + .hash)) { sentryfile = fs.readFileSync(sentryfile. + username + .hash);}// Now we can finally start doing stuff! Lets try logging in.client.logOn({ accountName: username, password: password, shaSentryfile: sentryfile // If null, a new Steam Guard code will be requested});// If Steam returns an error the "error" event is emitted.// We can deal with some of them.// See docs on Event Emitter to understand how this works: // Events Node.js v6.3.0 Manual Documentationclient.on(error, function(e) { // Error code for invalid Steam Guard code if (e.eresult == steam.EResult.AccountLogonDenied) { // Prompt the user for Steam Gaurd code rl.question(Steam Guard Code: , function(code) { // Try logging on again client.logOn({ accountName: username, password: password, authCode: code }); }); } else { // For simplicity, well just log anything else. // A list of ENUMs can be found here: // SteamKit/eresult.steamd at d0114b0cc8779dff915c4d62e0952cbe32202289 · SteamRE/SteamKit · GitHub logger.error(Steam Error: + e.eresult); // Note: Sometimes Steam returns InvalidPassword (5) for valid passwords. // Simply trying again solves the problem a lot of the time. }});// If we just entered a Steam Guard code, the "sentry" event goes off// with our new hash.client.on(sentry, function(sentry) { http://logger.info(Got new sentry file hash from Steam. Saving.); fs.writeFile(sentryfile. + username + .hash, sentry);});// After successful login...client.on(loggedOn, function() { http://logger.info(Logged on to Steam); // Optional: Rename the bot on login. client.setPersonaName("CrateDumpBot"); // Make sure were not displaying as online until were ready client.setPersonaState(steam.EPersonaState.Offline); });/* At this point, you should be logged into Steam but appear offline. * We havent logged into the web API yet to do any trading. * Steam hands us a session ID before we can use the API. * Additionally, our Trade library requires the session ID and cookie, * so we have to wait for the following event to be emitted.*/client.on(webSessionID, function(sessionid) { trade.sessionID = sessionid; // Share the session between libraries client.webLogOn(function(cookie) { cookie.forEach(function(part) { // Share the cookie between libraries trade.setCookie(part.trim()); // Now we can trade! }); http://logger.info(Logged into web); // No longer appear offline client.setPersonaState(steam.EPersonaState.LookingToTrade); });});*WHEW*! Still with me?
It』s best to test things incrementally, so try running it with just the above. Plus, this will allow you to generate a new Steam Guard hash immediately. It takes 7 days before you can use Steam trading on a new device, so getting this out-of-the-way early means you can spend an entire week learning the trading library while the timer counts down.
Make it do somethingThe above snippet works just fine if you supply an real username/password. Unfortunately, the bot doesn』t actually do anything. We need to add a few more event listeners to make it useful.
The CrateDump bot will accept friend requests from everyone. If you expect hundreds of users to use the bot, you』ll need to remove old friends when the account list is full, but that』s beyond the scope of this tutorial. We just want to get something working for now, so accept all friend invites and trade requests, and explain to new users how to get started.
142143144145146147148149150151152153154155156157158159160161162163164165166167168169170// If a user adds me...client.on(friend, function(steamID, relationship) { if (relationship == steam.EFriendRelationship.PendingInvitee) { http://logger.info([ + steamID + ] Accepted friend request); client.addFriend(steamID); } else if (relationship == steam.EFriendRelationship.None) { http://logger.info([ + steamID + ] Un-friended); }});// If a user messages me through Steam...client.on(friendMsg, function(steamID, message, type) { if (type == steam.EChatEntryType.ChatMsg) { // Regular chat message http://logger.info([ + steamID + ] MSG: + message); // Log it client.sendMessage(steamID, Im a bot that accepts all your unwanted items. If you would like to grab a few crates from me, please request a trade.); }});// If a user sends a trade request...client.on(tradeProposed, function(tradeID, steamID) { if (inTrade) { client.respondToTrade(tradeID, false); // Decline client.sendMessage(steamID, Im currently trading with someone else.); } else { client.respondToTrade(tradeID, true); // Accept http://logger.info([ + steamID + ] Accepted trade request); }});So far we have only added Steam client listeners. Now we get to add some for our trading library. Here』s where it starts to get fun!
The Steam client starts a new trade session when a trade is accepted, but it has no more functionality than that. We start by listening for a new trade session and then actually open a 「trade window」 with the steam-trade library (note: not a real trade window, just a pretend one that uses the API). Then we need to load our inventory after the trade starts so we know what we have available if they request a crate.
172173174175176177178179180181182183184185186187188189190191// After we accept the trade, we deal with the trade sessionclient.on(sessionStart, function(steamID) { inTrade = true; client.setPersonaState(steam.EPersonaState.Busy); trade.open(steamID, function() { // Pass the trade off to our steam-trade library trade.loadInventory(appid.TF2, contextid.TF2, function(inv) { if (!inv) { logger.error(Error getting own inventory. Cancelling trade.); client.sendMessage(steamID, Could not load my inventory. Please try again later.); trade.cancel(steamID); } else { logger.debug(Found +inv.length+ items in my inventory.); myBackpack = inv; // Now we can access it globally // If you want to put items up in the trade window immediately, // here is where you could do it. Instead were calling a custom function. onTradeStart(steamID); // Our custom function } }); });});In order to avoid callback hell where we can, let』s make our own function called onTradeStart that is called every time a trade is successfully loaded. We need to explain how to use the bot, so that』s a good place to start. It』s sort of ironic that we』re avoiding callback hell with a great example of what callback hell looks like…
Tip: Using a library like async allows you to execute things in order without using a bunch of callbacks. This can make your code more readable if you find yourself doing the following frequently.
256257258259260261262263264265266function onTradeStart(steamID) { trade.chatMsg(If youe adding crates, please put them up now., function() { trade.chatMsg(Any other items traded to me will be considered a donation., function() { trade.chatMsg(If you want a crate, request one via the following command: , function() { trade.chatMsg(!add , function() { trade.chatMsg(ex: "!add 82 5" will add 5 crates of series #82); }); }); }); });}
Now we』ll assume the user has started the trade and hopefully read the little guide in their trade chat window. Just to be sure they』re not requesting anything silly, let』s double-check any command they try to use for valid syntax before handing it off to a function.
194195196197198199200201202203204205// Messages received in the trade windowtrade.on(chatMsg, function(msg) { logger.debug(TradeMsg: +msg); // Use regex grouping to parse the result as we check syntax if (req = msg.match(/^!add (d+) (d+)/i)) { var series = req[1]; var amount = req[2]; addCrates(series, amount); // Our custom function } else { trade.chatMsg(Unrecognized command. Please use !add ); }});If the user is just dumping their items onto the bot, the above event may never be emitted. This is fine since all we really need to do is accept any proposed trade. Standard practice is to let the other user click 「ready」 when they want to complete the trade and have the bot follow their lead. This will be our cue too.
207208209210211212213214215216217218219220// When they ready uptrade.on(ready,function() { logger.debug(User clicked ready); trade.ready(function() { // In theory you should be able to confirm the trade now, // but in practice Steam is sometimes too slow. A 1.5 // sec delay is added to compensate. setTimeout(function () { trade.confirm(function() { logger.debug(Confirming Trade); }); }, 1500); });});Since this is a demo, there』s a few extra common trade events that you may want to listen for. We don』t need them for this particular project, but I always find examples more useful than just documentation.
222223224225226227228229230231232233234// Any time an item changes in the trade windowtrade.on(offerChanged, function(itemAdded, item) { if (itemAdded) http://logger.info(User added: +item.name); else http://logger.info(User removed: +item.name);});// If they uncheck readytrade.on(unready,function() { // Once again, we dont care in this case. logger.debug(User clicked unready);});Just two more pieces of the puzzle until everything comes together! We』re on a roll with event listeners, so let』s finish those up.
Before we send our bot out into the world we should probably teach it how to handle terminated trades. We don』t want it to hang forever thinking, 「Are you still there?」 (unless you』re into that kind of thing).
Oh, and don』t forget about the variables we set near the beginning of this project!
236237238239240241242243244245246247248249250251// Trade ends (successfully or otherwise)trade.on(end, function(result, getItems) { inTrade = false; // Allow new trades myBackpack = null; // Prevent stale backpack information by resetting it // Change from Busy back to Looking To Trade client.setPersonaState(steam.EPersonaState.LookingToTrade); if (result == timeout) { logger.warn(Trade timed out); client.sendMessage(trade.tradePartnerSteamID, The trade timed out. This usually means Steam is having problems. Please try again later.); } else if (result == complete) { http://logger.info(Trade complete); } else { logger.debug(Trade ended: +result); }});The possible result statuses are: complete, empty, cancelled, timeout, or failed. You can log all the items exchanged if you want, but in our case we really don』t care who does what with the bot; it』s a free service.
All that』s left is defining our addCrates function, but before we do that we should take a moment to understand what sort of item information we actually have available.
TF2 item schemaThe following is a single JSON object obtained from a trade, in this case for Crate #82. We generally refer to this by the variable, 『item』, so accessing the values such as the name is done via: 『item.name』.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778{ id: 2618574353, classid: 414905317, instanceid: 0, amount: 1, pos: 9, appid: 440, icon_url: fWFc82js0fmoRAP-qOIPu5THSWqfSmTELLqcUywGkijVjZULUrsm1j-9xgEIfgYFWCT0uSpKidzvAvyzBOESnN97s8MNizRqwQIoMrfnZGAxJFCTV_RdD_A8ogq9DXZlvcZmAIXjpb1eKhKv6tVvzKVcLg, icon_url_large: fWFc82js0fmoRAP-qOIPu5THSWqfSmTELLqcUywGkijVjZULUrsm1j-9xgEIfgYFWCT0uSpKidzvAvyzBOESnN97s8MNizRqwQIoMrfnZGAxJFCTV_RdD_A8ogq9DXZlvcZmAIXjpb1eKhKv6tVvzKVcLg, icon_drag_url: , name: Mann Co. Supply Munition Series #82, market_hash_name: Mann Co. Supply Munition Series #82, market_name: Mann Co. Supply Munition Series #82, name_color: 7D6D00, background_color: 3C352E, type: Level 20 Supply Crate, tradable: 1, marketable: 1, commodity: 1, descriptions: [{ value: Crate Series #82, color: 7ea9d1 }, { value: You need a Mann Co. Supply Crate Key to open this.You can pick one up at the Mann Co. Store. }, { value: }, { value: This crate contains one of the following items: }, { value: Pretty Boys Pocket Pistol Strangifier, color: 8b8989 }, { value: Phlogistinator Strangifier, color: 8b8989 }, { value: Cleaners Carbine Strangifier, color: 8b8989 }, { value: Strange Cosmetic Part: Kills, color: 8b8989 }, { value: Strange Part: Full Health Kills, color: 8b8989 }, { value: Strange Part: Headshot Kills, color: 8b8989 }, { value: Private Eye Strangifier, color: 8b8989 }, { value: Big Chief Strangifier, color: 8b8989 }, { value: or an Exceedingly Rare Series #3 Unusual Hat!, color: 7ea9d1 }], actions: [{ name: Item Wiki Page..., link: Active series }], tags: [{ internal_name: Unique, name: Unique, category: Quality, color: 7D6D00, category_name: Quality }, { internal_name: Supply Crate, name: Crate, category: Type, category_name: Type }], app_data: { def_index: 5734, quality: 6 }, contextid: 2}
There are a few important values in here, and a lot that we couldn』t care less about. This item object is actually a hybrid of information obtained from two different Steam APIs. The first is user backpack information from GetPlayerItems, which contains very basic information such as an original item ID, current item ID (this changes with every trade or action taken on the item), defindex, and item quality. The second is the definition of all TF2 item information from GetSchema, which includes item qualities, names, descriptions, attributes and images. Each item from GetSchema is given an index number, 「defindex」, which is mapped to an object defining the item. Not all the information from either API is included in the items returned here, but most of the information we need is.
Tip: If you ever need any extra information about an item, grab the defindex and look up the item in the schema by that index.
With the data provided, we will assume that all crates have a tag where the internal_name is 「Supply Crate」. Any item can have any number of tags, and any inventory can have any amount of items (up to 2000 in TF2』s case). It sounds like we need a loop within a loop filter out all our crates from our inventory! Rather than brute forcing directly, we』ll use javascript』s 「filter」 and 「some」 functions since they』re more efficient. Then we』ll try to grab the series number from the item name, and finally add the requested amount to the trade if we have them.
265266267268269270271272273274275276277278279280281282283284285286287288289290function addCrates(series, amount) { // Filter out all the crates var pool = myBackpack.filter(function (item) { return item.tags.some(function(element, index, array) { return element.internal_name == Supply Crate; }); }); // Filter out the series var re = new RegExp(# + series, i); // ex: #82 pool = pool.filter(function (item) { return item.name.match(re); }); // Let the user know we dont have enough if (amount &> pool.length) { logger.debug(User requested +amount+ of series +series+. I only have +pool.length+ available.); trade.chatMsg(I have +pool.length+ crates of series +series+ available.); } // Add what we should to the current trade for (var i = 0; i &< amount i &< pool.length; i++) { logger.debug(Adding +pool[i].name); trade.addItem(pool[i]); }}With this function, the entire project is complete. If you were hacking away while reading along, run it with: node filename.js and see how you did!.
TL;DRIf you just want to jump right in with a working bot, this project is available on github. It should just work out of the box, but remember that Steam Guard will not let you trade on a new device for 7 days, which means you have to wait a week to test any of this!
CaveatsIn our example we built the entire project in a single file. While this is good for learning, it is a horrible design. Node.JS is designed to be modular and our code should be too. The 「core」 code should probably be its own project which is included in all your other projects.
If you』re new to JavaScript, the asynchronous nature is probably very confusing. Instead of reading code from top to bottom like in traditional blocking languages, JavaScript executes everything as fast as it can, even if it』s not in order. The code will run top to bottom, but when there is a delay, such as waiting for a network action to complete or waiting for a file to read, code continues to execute beyond the current point. This is why we use callbacks and listeners. Callbacks, or functions handed to other functions to be executed at completion, allow us to wait until a task completes before moving on. There are plenty of guides out there on how to start using Node.js and JavaScript, and if this is your first introduction to either of those I recommend doing some reading before starting a project like this.
Good luck, and happy hacking!
Update 2015-01-09: Steam has added captchas to trade offers in order to stop malware from stealing items through trade offers. Numerous services and libraries exist for solving them (Death By Catpcha, for example), but you generally will pay a fraction of a penny per solve. It』s still viable but not really recommended to use trade offer libraries anymore.
Update 2015-01-10: Steam has removed captchas from trade offers and implemented recaptcha after the most popular malware provider pushed an update with integrated Death By Catpcha. This new version cannot be solved by the previous services and require an actual mouse click. So while the API still exists for trade offers, it can no longer be utilized by trade bots. Although there may be a way around it with headless browsers (ex: Phantom.js), consider trade offers dead in the water for the time being.
Update 2015-01-14: It seems anyone with 5000 or more trades on record does not have to enter captchas. Super active traders with expensive backpacks may still be just as vulnerable. If you are one of these and want to further protect your items, a secure alternate account may be beneficial.
Update 2015-01-21: Captchas have been removed and been replaced by email confirmation. This can easily be automated via imap libraries such as: GitHub - mscdex/node-imap: An IMAP client module for node.js.. Or you can just turn it off, but Steam refuses to return scammed/hacked items if you do.
出處:http://firepowered.org/developer/creating-a-steam-trade-bot-with-node-js/可以看看我寫的steam機器人製作教程。
從零開始搭建steam交易機器人(1)- 申請賬號,製作驗證器 - 知乎專欄之前也開發過類似csgoreaper的菠菜網
自己做了一個交易機器人。。。
也是看的博客學的。不過上面好多API都已經換了,或者不能用了
因為問的人實在比較多,做了個機器人介面;24小時自動接收報價和自動接收交易;
有人無限舉報的我回答。。不知道是搶了你的生意還是?
開始教程系列,直接貼源碼!
手把手教你製作STEAM機器人(一)
我寫過一個庫,不過礙於學業我還沒時間去更新,你可以先看看,是php的
地址:
代碼託管 項目管理 WebIDE 企業服務coding.net樓主想發財啊 我記得前段時間貼吧有人賣這個玩意兒 然後演算法和網站自己搞 前期投入點廣告費但是現在賭博網站越來越多 什麼hunt lotto double 2x 各種各樣新的賭發還有菠菜的lounge fanobet 啥的沒什麼油水哇
steam wiki有
推薦閱讀:
※四旋翼無人機飛行控制演算法H∞控制?
※當初的「燈罩」已經改頭換面,變「甜甜圈」後備受寵愛
※實際動力學計算中,機械臂的轉動慣量怎麼獲得?
※【演講PPT乾貨】發那科一家公司的凈利潤比中國40家機器人上市公司還多
※機器人與人類的和諧之道在哪裡?搞工業的朋友們怎麼看。
TAG:機器人 | 交易 | Steam | 反恐精英:全球攻勢CS:GO |