├── config.json ├── README.md ├── LICENSE └── bot.js /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "username" : "username", 3 | "password" : "password", 4 | "admin" : "steamID64 number", 5 | "my64id" : "steamID64 number", 6 | "tfa" : "sharedsecret code", 7 | "trade" : "identitysecret code", 8 | "apikey" : "apikey", 9 | "rememberPassword" : true 10 | } 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VanillaBot 2 | NodeJS Steam bot for 1:1 same set Trading Cards, Background, and Emoticon Trade 3 | 4 | https://steamcommunity.com/id/VanillaBot/ 5 | 6 | If you have question, please leave a comment on [owner profile](https://steamcommunity.com/profiles/76561198078744223) instead on GitHub 7 | 8 | ## Instalation and Running bot 9 | 10 | Install NodeJS: https://nodejs.org/ 11 | 12 | Install needed module via npm (`npm install *module*`) using cmd (Windows) or terminal (Linux): 13 | - "steamcommunity" 14 | - "steam-totp" 15 | - "steam-user" 16 | - "steam-tradeoffer-manager" 17 | - "decode-html" 18 | 19 | Download / Clone repository ([Download ZIP](https://github.com/Vanilla72/VanillaBot/archive/master.zip)) 20 | 21 | Put entire file inside node module directory (you can use command `npm root` or `npm root -g` to check it) 22 | 23 | Change *config.json* value: 24 | - username: your bot username 25 | - password: your bot password 26 | - admin: Owner Steam64ID (use https://steamid.io/lookup/) 27 | - my64id: Bot Steam64ID (use https://steamid.io/lookup/) 28 | - tfa: shared_secret code (in Android you can find it on `/data/data/com.valvesoftware.android.steam.community/files/Steamguard-YourSteamID64Code`) 29 | - trade: identity_secret code (in Android you can find it on `/data/data/com.valvesoftware.android.steam.community/files/Steamguard-YourSteamID64Code`) 30 | - apikey: Steam API key (https://steamcommunity.com/dev/apikey) 31 | - rememberPassword: true 32 | 33 | (Optional) Change "MYBACKGROUND" text with your profile background name (example: "X Game Uncommon Profile Background") so it doesn't get traded away 34 | 35 | Run bot using `node bot.js` 36 | 37 | ## FAQ 38 | 39 | > How to change Online status? 40 | 41 | A: Change setPersona number on [line 201](https://github.com/Vanilla72/VanillaBot/blob/master/bot.js#L201) 42 | 43 | > Market Confirmation? 44 | 45 | A: Market confirmation didn't works for some reason, I'm not sure why. 46 | 47 | > Why bot can't do non-marketable card trade? 48 | 49 | A: It's because the relevant code got removed and it's quite buggy. 50 | 51 | So far VanillaBot use `if (item.marketable == false){ //do something about non marketable card }`, but Steam sometimes send wrong information about it, which makes bot think it's marketable card / cross-trade. I tried checking the "Marketable" tags or checking *This item can no longer be bought or sold on the Community Market* text, and it still doesn't works because Steam sending wrong information. 52 | 53 | Workaround exist by checking Market price *each card*, which takes a lot of time and have chance bot got rate-limited by Steam (also *might* break Steam Term of Service because Market bot is not allowed) 54 | 55 | *will added more if needed* 56 | 57 | ## Add / Change Bot Feature 58 | 59 | First of all, sorry with the mess I created. Hopefully you're able to read it. 60 | 61 | Please visit relevant module wiki to add / change feature 62 | 63 | - General: [steam-user](https://github.com/DoctorMcKay/node-steam-user/blob/master/README.md#contents) 64 | - Trading: [steam-tradeoffer-manager](https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/TradeOffer#table-of-contents) 65 | - Trade item information: [CEconItem](https://github.com/DoctorMcKay/node-steamcommunity/wiki/CEconItem) 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /bot.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | $$\ $$\ $$\ $$\ $$\ $$$$$$$\ $$\ 4 | $$ | $$ | \__|$$ |$$ | $$ __$$\ $$ | 5 | $$ | $$ |$$$$$$\ $$$$$$$\ $$\ $$ |$$ | $$$$$$\ $$ | $$ | $$$$$$\ $$$$$$\ 6 | \$$\ $$ |\____$$\ $$ __$$\ $$ |$$ |$$ | \____$$\ $$$$$$$\ |$$ __$$\\_$$ _| 7 | \$$\$$ / $$$$$$$ |$$ | $$ |$$ |$$ |$$ | $$$$$$$ | $$ __$$\ $$ / $$ | $$ | 8 | \$$$ / $$ __$$ |$$ | $$ |$$ |$$ |$$ |$$ __$$ | $$ | $$ |$$ | $$ | $$ |$$\ 9 | \$ / \$$$$$$$ |$$ | $$ |$$ |$$ |$$ |\$$$$$$$ | $$$$$$$ |\$$$$$$ | \$$$$ | 10 | \_/ \_______|\__| \__|\__|\__|\__| \_______| \_______/ \______/ \____/ 11 | 12 | https://github.com/PraskaLukestiwa/VanillaBot 13 | Apache-2.0 License 14 | 15 | Sorry for this mess 16 | */ 17 | 18 | var isJSON = true; 19 | var validLoginKey = ""; 20 | var config = require("./config.json"); 21 | //var login_key = require("./loginkey.json"); 22 | 23 | var SteamCommunity = require("steamcommunity"); 24 | var fs = require('fs'); 25 | var fs2 = require('fs'); 26 | var steam = new SteamCommunity(); 27 | var SteamTotp = require('steam-totp'); 28 | var SteamUser = require('steam-user'); 29 | var client = new SteamUser(); 30 | var SteamID = SteamCommunity.SteamID; 31 | var admin = config.admin; 32 | var TradeOfferManager = require('steam-tradeoffer-manager'); 33 | var identitysecret = config.trade; 34 | var decode = require('decode-html'); 35 | var manager = new TradeOfferManager({ 36 | "steam": client, 37 | "community": steam, 38 | "domain": "example.com", 39 | "language": "en", 40 | "globalAssetCache": true 41 | }); 42 | 43 | try { 44 | var rawdata = fs.readFileSync('loginkey.json'); 45 | var fileLoginKey = JSON.parse(rawdata); 46 | } catch (e) { 47 | isJSON = false; 48 | } 49 | 50 | if (isJSON == true){ 51 | var login_key = require("./loginkey.json"); 52 | validLoginKey = login_key.loginkey; 53 | } 54 | else { 55 | var jsonformat = '{ "loginkey" : "" }'; 56 | fs.appendFile("loginkey.json", jsonformat, {flag: 'w'}, function(err) {}); 57 | validLoginKey = ""; 58 | } 59 | 60 | var antispam; 61 | var markedSteamID; 62 | var unblockedSteamID; 63 | var removefriendSteamID; 64 | var blockSteamID; 65 | var blocklistSteamID; 66 | var donatorName; 67 | var spammerSteamID; 68 | var counterofferSteamID; 69 | 70 | var cards; 71 | var date; 72 | var lastAdd = 0; 73 | 74 | var lastOfferID; 75 | var vanityname; 76 | 77 | //fs.appendFile("log.txt", "", {flag: 'w'}, function(err) {}); 78 | fs.appendFile("log.txt", "", {flag: 'a'}, function(err) {}); 79 | 80 | function matchDescription() { 81 | //return 'This item can no longer be bought or sold on the Community Market.'; 82 | return 'Community Market'; 83 | } 84 | function rolldice() { 85 | var x = Math.floor((Math.random() * 6) + 1); 86 | return (x); 87 | } 88 | function currentdate(){ 89 | var date = new Date(); 90 | var dateformat = (("0" +date.getDate()).slice(-2) + "/" 91 | + (+date.getMonth()+1) + "/" 92 | + ("0" +date.getFullYear()).slice(-2) + " - " 93 | + ("0" +date.getHours()).slice(-2) + ":" 94 | + ("0" +date.getMinutes()).slice(-2) + ":" 95 | + ("0" +date.getSeconds()).slice(-2)); 96 | return (dateformat); 97 | } 98 | function twofactor() { 99 | var tfa = SteamTotp.generateAuthCode(config.tfa); 100 | return (tfa); 101 | } 102 | function stmCommand(SteamID){ 103 | 104 | var myType = []; 105 | var myAssetId = []; 106 | var myItemName = []; 107 | 108 | var theirType = []; 109 | var theirAssetId = []; 110 | var theirItemName = []; 111 | 112 | manager.getInventoryContents(753, 6, true, function(err, inventory, currencies){ 113 | if (err){ 114 | var log = (currentdate() + " - Unable to load my inventory - "+err); 115 | console.log(log); 116 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 117 | client.chatMessage(SteamID, err); 118 | setTimeout(function(){ 119 | client.chatMessage(SteamID, "If this error keep happening, please contact my Owner or leave comment"); 120 | }, 1500); 121 | } 122 | else { 123 | inventory.forEach(function(item) { 124 | myType.push(item.type); 125 | myAssetId.push(item.assetid); 126 | myItemName.push(item.name); 127 | }); 128 | console.log(myType); 129 | console.log(myAssetId); 130 | console.log(myItemName); 131 | } 132 | }); 133 | }; 134 | function acceptConfirmation() { 135 | var time = Math.floor(Date.now() / 1000); 136 | var conf_key = SteamTotp.getConfirmationKey(config.trade, time, 'conf'); 137 | var allowKey = SteamTotp.getConfirmationKey(config.trade, time, 'allow'); 138 | 139 | setTimeout(function(){ 140 | 141 | steam.getConfirmations(time, conf_key, function(err, confirmations){ 142 | if (err){ 143 | var log = (currentdate() + " - "+ err); 144 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 145 | console.log(log); 146 | } 147 | else if (confirmations.length == 0){ 148 | var log = (currentdate() + " - Nothing to confirm"); 149 | console.log(log); 150 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 151 | } 152 | else { 153 | steam.acceptAllConfirmations(time, conf_key, allowKey, function(err, conf) { 154 | if (err) { 155 | var log = (currentdate() + " - "+ err); 156 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 157 | console.log(log); 158 | } 159 | else { 160 | conf.forEach (function(item) { 161 | var log = (currentdate() + " - Confirmed Trade Offer #" +item.creator); 162 | console.log(log); 163 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 164 | }); 165 | } 166 | }); 167 | } 168 | }); 169 | }, 1000); 170 | } 171 | function spamtimer() { 172 | antispam = 0; 173 | markedSteamID = 0; 174 | } 175 | 176 | setInterval(currentdate, 1000); 177 | setInterval(twofactor, 1000); 178 | setInterval(spamtimer, 2000); 179 | 180 | String.prototype.insert = function (index, string) { 181 | if (index > 0) 182 | return this.substring(0, index) + string + this.substring(index, this.length); 183 | else 184 | return string + this; 185 | }; 186 | 187 | // -------------- LOGIN DATA -------------- 188 | 189 | client.logOn({ 190 | "accountName": config.username, 191 | "password": config.password, 192 | "twoFactorCode": SteamTotp.generateAuthCode(config.tfa), 193 | "rememberPassword" : config.rememberPassword, 194 | "loginKey": validLoginKey 195 | }); 196 | 197 | client.on('loggedOn', function (details) { 198 | var log = (currentdate() + " - Sucesfully Logged in"); 199 | fs.appendFile("log.txt", log+ "\n", {flag: 'a'}, function(err) {}); 200 | console.log(log); 201 | vanityname = client.vanityURL; 202 | client.setPersona(1); //"0": "Offline", "1": "Online", "2": "Busy", "3": "Away", "4": "Snooze", "5": "LookingToTrade", "6": "LookingToPlay" 203 | client.setUIMode(1); //"None": 0, "BigPicture": 1, "Mobile": 2, "Web": 3 204 | 205 | //client.gamesPlayed("Custom Steam Game titles"); //63 characters - http://www.lettercount.com/ 206 | //client.gamesPlayed(1121910); 207 | }); 208 | 209 | client.on('error', function(err) { 210 | var log = (currentdate() + " - Logon Error: "+err); 211 | fs.appendFile("log.txt", log+ "\n", {flag: 'a'}, function(err) {}); 212 | console.log(log); 213 | }); 214 | 215 | client.on('webSession', function(sessionID, cookies) { 216 | steam.setCookies(cookies); 217 | manager.setCookies(cookies); 218 | var log = (currentdate() + " - Got our cookies"); 219 | fs.appendFile("log.txt", log+ "\n", {flag: 'a'}, function(err) {}); 220 | console.log(log); 221 | 222 | setTimeout(function(){ 223 | steam.resetItemNotifications(); 224 | }, 10000); 225 | }); 226 | 227 | client.on('loginKey', function (key) { 228 | var jsonformat = '{ "loginkey" : "' +key+ '" }'; 229 | fs.appendFile("loginkey.json", jsonformat, {flag: 'w'}, function(err) {}); 230 | }); 231 | 232 | client.on('friendRelationship', function(steamID, relationship) { 233 | if (relationship == SteamUser.Steam.EFriendRelationship.RequestRecipient) { 234 | var log = (currentdate() + " - Incoming friend request from http://steamcommunity.com/profiles/" +steamID); 235 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 236 | console.log(log); 237 | client.addFriend(steamID); 238 | lastAdd == steamID; 239 | 240 | /* 241 | setTimeout(function(){ 242 | client.chatMessage(steamID, "Hello, thanks for the add"); 243 | setTimeout(function(){ 244 | client.chatMessage(steamID, "Please check trade rules and send me trade offer"); 245 | }, 1000); 246 | }, 2500); 247 | */ 248 | } 249 | else if (relationship == SteamUser.Steam.EFriendRelationship.None) { 250 | var log = (currentdate() + " - " +steamID+ " just removed from friend list"); 251 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 252 | console.log(log); 253 | } 254 | else { 255 | 256 | } 257 | }); 258 | 259 | steam.on("sessionExpired", function(err) { 260 | if (err) { 261 | setTimeout(function(){ 262 | var log = (currentdate() + " - Refreshing our session"); 263 | fs.appendFile("log.txt", log+ "\n", {flag: 'a'}, function(err) {}); 264 | console.log(log); 265 | }, 500); 266 | 267 | client.webLogOn(); 268 | 269 | setTimeout(function(){ 270 | manager.getOffer(lastOfferID, function (err, offer){ 271 | if (err){ 272 | var log = (currentdate() + " - "+ err); 273 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 274 | console.log(log); 275 | } 276 | else { 277 | offer.accept(); 278 | setTimeout(function(){ 279 | acceptConfirmation(); 280 | }, 3000); 281 | } 282 | }); 283 | }, 3000); 284 | } 285 | }); 286 | 287 | /* 288 | setTimeout(function(){ 289 | //for debugging purposes 290 | console.log("rip cookies :("); 291 | //steam.setCookies(["steamLogin=1||invalid", "steamLoginSecure=1||invalid"]); 292 | manager.setCookies(["steamLogin=1||invalid", "steamLoginSecure=1||invalid"]); 293 | }, 10000); 294 | */ 295 | 296 | client.on("friendMessage", function(senderID, message) { 297 | 298 | var text = message; 299 | 300 | // ---------- LOG INCOMING CHAT TO CONSOLE AND FILE CHATBOG_LOG.TXT ---------- // 301 | var log = (currentdate() + " - Message from " + senderID+ " : " + message); 302 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 303 | console.log(log); 304 | 305 | // ---------- ADMIN COMMAND ---------- 306 | 307 | if ((senderID == admin) && (text.includes("giveme") == true)){ 308 | 309 | var offer = manager.createOffer(admin); 310 | var countitem = 0; 311 | var itemname = []; 312 | text = text.split(" "); 313 | 314 | text.forEach(function(item){ 315 | if (item.includes("giveme")){ 316 | 317 | } 318 | else { 319 | itemname.push(item); 320 | } 321 | }); 322 | itemname = itemname.join(" "); 323 | 324 | manager.getInventoryContents(753, 6, true, function(err, inventory, currencies){ 325 | client.chatMessage(senderID, "Loading Inventories"); 326 | if (err){ 327 | var log = (currentdate() + " - Unable to send item - "+err); 328 | console.log(log); 329 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 330 | client.chatMessage(senderID, "Done"); 331 | } 332 | else { 333 | inventory.forEach(function(item) { 334 | if (item.type.includes(itemname) == true){ 335 | offer.addMyItem(item); 336 | countitem++; 337 | } 338 | }); 339 | if (countitem == 0){ 340 | client.chatMessage(senderID, "There's no item called: '"+itemname+"'"); 341 | } 342 | else { 343 | offer.send(function(err, status){ 344 | if (err){ 345 | var log = (currentdate() + " Unable to send Trade Offer - "+err); 346 | console.log(log); 347 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 348 | client.chatMessage(senderID, "Unable to send trade offer: "+err); 349 | } 350 | else { 351 | setTimeout(function(){ 352 | acceptConfirmation(); 353 | client.chatMessage(senderID, "Trade Offer sent"); 354 | }, 2000); 355 | } 356 | }); 357 | } 358 | } 359 | }); 360 | 361 | } 362 | else if ((senderID == admin) && (text.includes("takemy") == true)){ 363 | 364 | var offer = manager.createOffer(admin); 365 | var countitem = 0; 366 | var itemname = []; 367 | text = text.split(" "); 368 | 369 | text.forEach(function(item){ 370 | if (item.includes("takemy")){ 371 | 372 | } 373 | else { 374 | itemname.push(item); 375 | } 376 | }); 377 | itemname = itemname.join(" "); 378 | 379 | manager.getUserInventoryContents(admin, 753, 6, true, function(err, inventory, currencies){ 380 | if (err){ 381 | var log = (currentdate() + " - Unable to send item - "+err); 382 | console.log(log); 383 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 384 | client.chatMessage(senderID, "Done"); 385 | } 386 | else { 387 | inventory.forEach(function(item) { 388 | if (item.type.includes(itemname) == true){ 389 | offer.addTheirItem(item); 390 | countitem++; 391 | } 392 | }); 393 | if (countitem == 0){ 394 | client.chatMessage(senderID, "There's no item called: '"+itemname+"'"); 395 | } 396 | else { 397 | offer.send(function(err, status){ 398 | if (err){ 399 | var log = (currentdate() + " Unable to send Trade Offer - "+err); 400 | console.log(log); 401 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 402 | client.chatMessage(senderID, "Unable to send trade offer: "+err); 403 | } 404 | else { 405 | client.chatMessage(senderID, "Trade Offer sent"); 406 | } 407 | }); 408 | } 409 | } 410 | }); 411 | 412 | } 413 | else if ((senderID == admin) && (text == "relog")){ 414 | client.chatMessage(senderID, "ReLoggin"); 415 | client.webLogOn(); 416 | } 417 | else if ((senderID == admin) && (text.substring(0,6) == "rename")){ 418 | var newname = text.substring(7,text.length); 419 | client.setPersona(1, newname); 420 | } 421 | else if ((senderID == admin) && (text == "confirm")){ 422 | acceptConfirmation(); 423 | client.chatMessage(senderID, "Checking .."); 424 | } 425 | else if ((senderID == admin) && (text == "apikey")){ 426 | client.chatMessage(senderID, config.apikey); 427 | } 428 | else if ((senderID == admin) && (text.includes("addcomment") == true)){ 429 | steam.postUserComment(config.my64id, text.substring(11,text.length)); 430 | client.chatMessage(senderID, "Done"); 431 | } 432 | else if ((senderID == admin) && (text.includes("blocklist") == true)){ 433 | blocklistSteamID = (text.replace ( /[^\d]/g, '' )); 434 | var found = false; 435 | var fileread = fs.readFileSync('blocklist.txt').toString().split("\n"); 436 | 437 | for(i in fileread) { 438 | if (fileread[i].includes(blocklistSteamID)){ 439 | client.chatMessage(senderID, fileread[i]); 440 | found = true; 441 | break; 442 | } 443 | found = false; 444 | } 445 | if (found == false){ 446 | client.chatMessage(senderID, "I can't found it on block list"); 447 | } 448 | } 449 | else if ((senderID == admin) && (text.includes("unblock") == true)){ 450 | unblockedSteamID = (text.replace ( /[^\d]/g, '' )); 451 | client.unblockUser(unblockedSteamID); 452 | client.chatMessage(senderID, unblockedSteamID+ " Unblocked"); 453 | } 454 | else if ((senderID == admin) && (text.includes("removefriend") == true)){ 455 | removefriendSteamID = (text.replace ( /[^\d]/g, '' )); 456 | client.removeFriend(removefriendSteamID); 457 | client.chatMessage(senderID, removefriendSteamID+ " Removed"); 458 | } 459 | else if ((senderID == admin) && (text.includes("blockuser") == true)){ 460 | blockSteamID = (text.replace ( /[^\d]/g, '' )); 461 | client.removeFriend(blockSteamID); 462 | client.blockUser(blockSteamID); 463 | client.chatMessage(senderID, blockSteamID+ " Blocked"); 464 | var log = (currentdate() + " - Blocked " +blockSteamID+ ". Reason: Blocked by Owner"); 465 | fs.appendFile("blocklist.txt", log + "\n", {flag: 'a'}, function(err) {}); 466 | } 467 | else if ((senderID == admin) && message == "2fa"){ 468 | client.chatMessage(senderID, twofactor()); 469 | } 470 | else if (spammerSteamID == senderID.getSteamID64()){ 471 | //people who trying to spam will not receive any message from us 472 | } 473 | else if (text == "ping"){ 474 | client.chatMessage(senderID, "pong"); 475 | } 476 | 477 | 478 | antispam = text; 479 | markedSteamID = senderID.getSteamID64(); 480 | 481 | }) 482 | 483 | 484 | 485 | manager.on('newOffer', function(offer) { 486 | 487 | var trademsg = offer.message; 488 | 489 | var copyOffer = offer; 490 | var itemBotGive = []; 491 | var itemBotReceive = []; 492 | var myassetid = []; 493 | var theirassetid = []; 494 | 495 | var givenlength = offer.itemsToGive.length; 496 | var receivelength = offer.itemsToReceive.length; 497 | var removedcards = 0; 498 | var unmarketablecards = false; 499 | var blacklisteditem = false; 500 | var blacklistedcount = 0; 501 | var instantreject = false; 502 | 503 | var skip = false; 504 | 505 | offer.itemsToReceive.forEach(function(item) { 506 | 507 | theirassetid.push(item.assetid); 508 | 509 | if((item.type.includes("Profile Background") == true) || (item.type.includes("Emoticon") == true)){ 510 | var temp = item.type; 511 | var temp = temp.replace(/Uncommon /g,''); 512 | var temp = temp.replace(/Rare /g,''); 513 | itemBotReceive.push(temp); 514 | } 515 | else if (item.type.includes("Trading Card") == true) { 516 | itemBotReceive.push(item.type); 517 | } 518 | else { 519 | instantreject = true; 520 | } 521 | }); 522 | 523 | offer.itemsToGive.forEach(function(item) { 524 | 525 | myassetid.push(item.assetid); 526 | 527 | if((item.type.includes("Profile Background") == true) || (item.type.includes("Emoticon") == true)){ 528 | var temp = item.type; 529 | var temp = temp.replace(/Uncommon /g,''); 530 | var temp = temp.replace(/Rare /g,''); 531 | itemBotGive.push(temp); 532 | } 533 | else if (item.type.includes("Trading Card") == true) { 534 | itemBotGive.push(item.type); 535 | } 536 | else { 537 | instantreject = true; 538 | } 539 | }); 540 | 541 | for(i = 0; i < givenlength;i++){ 542 | for(j = 0; j < receivelength;j++){ 543 | if (itemBotGive[i] == itemBotReceive[j]){ 544 | if (itemBotGive[i] == "MYBACKGROUND"){ 545 | removedcards++; 546 | blacklistedcount++; 547 | itemBotReceive.splice(j, 1); 548 | blacklisteditem = true; 549 | break; 550 | } 551 | else { 552 | myassetid.splice((i-removedcards), 1); 553 | theirassetid.splice(j, 1); 554 | removedcards++; 555 | itemBotReceive.splice(j, 1); 556 | break; 557 | } 558 | } 559 | } 560 | } 561 | 562 | //Trade logic start here 563 | if (offer.partner.getSteamID64() == admin){ 564 | 565 | if (offer.itemsToGive.length == 0){ 566 | var log = (currentdate() + " - Accepting Trade Offer #" +offer.id+ " from Owner: " +offer.partner.getSteamID64()); 567 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 568 | console.log(log); 569 | lastOfferID = offer.id; 570 | offer.accept(function(err) { 571 | if (err) { 572 | var log = (currentdate() + " - "+ err); 573 | fs.appendFile("log.txt", log+ "\n", {flag: 'a'}, function(err) {}); 574 | } 575 | }); 576 | } 577 | else { 578 | var log = (currentdate() + " - Accepting Trade Offer #" +offer.id+ " from Owner: " +offer.partner.getSteamID64()); 579 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 580 | console.log(log); 581 | lastOfferID = offer.id; 582 | offer.accept(function(err) { 583 | if (err) { 584 | var log = (currentdate() + " - "+ err); 585 | fs.appendFile("log.txt", log+ "\n", {flag: 'a'}, function(err) {}); 586 | } 587 | }); 588 | setTimeout(function(){ 589 | acceptConfirmation(); 590 | }, 3000); 591 | } 592 | } 593 | 594 | else if (instantreject == true){ 595 | var log = (currentdate() + " - Rejecting Trade Offer from " +offer.partner.getSteamID64()+ " - Reason: Other item present"); 596 | console.log(log); 597 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 598 | offer.decline(); 599 | } 600 | else if (offer.isGlitched() == true){ 601 | var log = (currentdate() + " - Glitched Trade Offer #" +offer.id+ ", we'll try again later"); 602 | } 603 | else if (offer.itemsToReceive.length == 0){ // Bot receive 0 item -- begging, blocked 604 | client.removeFriend(offer.partner.getSteamID64()); 605 | client.blockUser(offer.partner.getSteamID64()); 606 | var log = (currentdate() + " - Blocked " +offer.partner.getSteamID64()+ ". Reason: Begging"); 607 | fs.appendFile("blocklist.txt", log + "\n", {flag: 'a'}, function(err) {}); 608 | console.log(log); 609 | offer.decline(); 610 | } 611 | 612 | else if (offer.itemsToGive.length == 0){ // Bot give 0 item -- donation 613 | 614 | var isDonation = true; 615 | offer.itemsToReceive.forEach(function(item) { 616 | if (item.type.includes("Profile Background") == true || item.type.includes("Emoticon") == true || item.type.includes("Trading Card") == true || item.type.includes("Booster Pack") == true){ 617 | //We want this item as donation 618 | } 619 | else { 620 | isDonation = false; 621 | } 622 | }); 623 | 624 | if (isDonation == true){ 625 | setTimeout(function(){ 626 | var id = offer.partner; 627 | steam.getSteamUser(id, function(err, user) { 628 | if (err) { 629 | console.log(err); 630 | fs.appendFile("log.txt", "DONATION ERROR" +err + " - Donation (" +offer.partner.getSteamID64()+ ") \n", {flag: 'a'}, function(err) {}); 631 | client.chatMessage(admin, "Someone donated but there's an error, please check log "+currentdate()); 632 | } 633 | else { 634 | offer.accept(function(err) { 635 | if (err) { 636 | console.log(err); 637 | fs.appendFile("log.txt", "DONATION ERROR" +err + " (" +offer.partner.getSteamID64()+ ") \n", {flag: 'a'}, function(err) {}); 638 | client.chatMessage(admin, "Someone donated but there's an error, please check log "+currentdate()); 639 | } 640 | else { 641 | var log = (currentdate() + " - Donation from " +offer.partner.getSteamID64()+ " - Receive "+offer.itemsToReceive.length+" new item"); 642 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 643 | console.log(log); 644 | steam.postUserComment(offer.partner.getSteamID64(), "+rep, thanks for supporting VanillaBot :bite:", function (err){ 645 | if (err){ 646 | var log = (currentdate() + " - Unable to post profile comment, sending 'thanks' messages"); 647 | console.log(log) 648 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 649 | client.chatMessage(offer.partner.getSteamID64(), "Hello, thanks for supporting VanillaBot. :bite:"); 650 | } 651 | else { 652 | var log = (currentdate() + " - Done posting profile comment"); 653 | console.log(log) 654 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 655 | } 656 | }); 657 | client.chatMessage(admin, ""+offer.partner.getSteamID64()+" just send me donation. Receive "+offer.itemsToReceive.length+" new item(s)"); //Reminds me in case if it's fail 658 | 659 | setTimeout(function(){ 660 | donatorName = user.name; 661 | donatorName = decode(donatorName); 662 | donatorName = donatorName.replace(/"/g, ""); 663 | donatorName = donatorName.split(" "); 664 | var filteredName = []; 665 | 666 | donatorName.forEach(function(item){ 667 | if (item.includes(".com") || item.includes("csgo") || item.includes(".gg") || item.includes(".RU") || item.includes("CSGO")){ 668 | 669 | } 670 | else { 671 | filteredName.push(item); 672 | } 673 | }); 674 | filteredName = filteredName.join(" "); 675 | 676 | var notes = "Donation from " + filteredName + " ( http://steamcommunity.com/profiles/" +offer.partner.getSteamID64()+ " ) \n Received " +offer.itemsToReceive.length+ " new item. Thank you. :bite: \n \n [b]Item List:[/b]\n"; 677 | offer.itemsToReceive.forEach(function(item, index) { 678 | if (index >= 10){ 679 | 680 | } 681 | else { 682 | notes = notes + "- " +item.name+ " (" +item.type+ ")\n"; 683 | } 684 | }); 685 | if (offer.itemsToReceive.length >= 10){ 686 | notes = notes + "\n and more.."; 687 | } 688 | steam.postUserComment(config.my64id, notes); // Bot will post detailed donation 689 | fs.appendFile("donation_backup.txt", notes, {flag: 'w'}, function(err) {}); 690 | //client.addFriend(offer.partner.getSteamID64()); 691 | 692 | }, 2000); 693 | } 694 | }); 695 | } 696 | }); 697 | }, 1000); 698 | } 699 | else { 700 | var log = (currentdate() + " - Rejecting Donation from " +offer.partner.getSteamID64()); 701 | console.log(log) 702 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 703 | offer.decline(); 704 | client.chatMessage(offer.partner.getSteamID64(), "Hello, I'm sorry but I have to reject your donation. I only accept Trading Cards, Emoticon, and Background donation :doubt: "); 705 | } 706 | } 707 | 708 | else if((givenlength == removedcards) && (receivelength == removedcards)){ 709 | 710 | if (blacklisteditem == true && removedcards == blacklistedcount){ 711 | var log = (currentdate() + " - Rejecting Trade Offer from " +offer.partner.getSteamID64()+ " - Reason: Blacklisted Item"); 712 | console.log(log) 713 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 714 | offer.decline(); 715 | } 716 | else if (blacklisteditem == true){ 717 | 718 | var log = (currentdate() + " - Countered ("+removedcards+ ":"+removedcards+") Trade Offer #" +offer.id+ " : " +offer.partner.getSteamID64()+ " - eason: Blacklisted Item"); 719 | console.log(log); 720 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 721 | 722 | var counteroffer = offer.counter(); 723 | offer.itemsToGive.forEach(function(item) { 724 | if (item.type == "MYBACKGROUND"){ 725 | counteroffer.removeMyItem({"appid": item.appid, "contextid": item.contextid, "assetid": item.assetid}); 726 | } 727 | }); 728 | offer.itemsToReceive.forEach(function(item) { 729 | if (item.type == "MYBACKGROUND"){ 730 | counteroffer.removeTheirItem({"appid": item.appid, "contextid": item.contextid, "assetid": item.assetid}); 731 | } 732 | }); 733 | myassetid.forEach(function(item) { 734 | counteroffer.removeMyItem({"appid": 753, "contextid": 6, "assetid": item}); 735 | }); 736 | theirassetid.forEach(function(item) { 737 | counteroffer.removeTheirItem({"appid": 753, "contextid": 6, "assetid": item}); 738 | }); 739 | 740 | counteroffer.setMessage("Sorry, I'm not gonna trade my MYBACKGROUND emoticon / my current Profile Background"); 741 | counteroffer.send(function(err, status){ 742 | if (err){ 743 | var log = (currentdate() + " Unable to send Counter Offer - "+err); 744 | console.log(log); 745 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 746 | offer.decline(); 747 | } 748 | }); 749 | 750 | setTimeout(function(){ 751 | acceptConfirmation(); 752 | }, 3000); 753 | } 754 | 755 | else { 756 | var log = (currentdate() + " - Accepting ("+removedcards+ ":"+removedcards+") Trade Offer #" +offer.id+ " : " +offer.partner.getSteamID64()); 757 | console.log(log); 758 | lastOfferID = offer.id; 759 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 760 | offer.accept(function(err) { 761 | if (err) { 762 | var log = (currentdate() + " - "+ err); 763 | fs.appendFile("log.txt", log+ "\n", {flag: 'a'}, function(err) {}); 764 | client.webLogOn(); 765 | } 766 | }); 767 | 768 | setTimeout(function(){ 769 | acceptConfirmation(); 770 | }, 3000); 771 | } 772 | } 773 | else if(removedcards == 0){ 774 | var log = (currentdate() + " - Rejecting Trade Offer from " +offer.partner.getSteamID64()+ " - Reason: Cross-Set"); 775 | console.log(log) 776 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 777 | offer.decline(); 778 | } 779 | 780 | else if ((offer.itemsToGive.length > offer.itemsToReceive.length) && removedcards > 0){ 781 | var log = (currentdate() + " - Countered ("+offer.itemsToGive.length+ ":"+offer.itemsToReceive.length+") Trade Offer #" +offer.id+ " : " +offer.partner.getSteamID64()+ " - Reason: Not same ammount"); 782 | console.log(log); 783 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 784 | var counteroffer = offer.counter(); 785 | 786 | offer.itemsToGive.forEach(function(item) { 787 | if (item.type == "MYBACKGROUND"){ 788 | counteroffer.removeMyItem({"appid": item.appid, "contextid": item.contextid, "assetid": item.assetid}); 789 | } 790 | }); 791 | offer.itemsToReceive.forEach(function(item) { 792 | if (item.type == "MYBACKGROUND"){ 793 | counteroffer.removeTheirItem({"appid": item.appid, "contextid": item.contextid, "assetid": item.assetid}); 794 | } 795 | }); 796 | 797 | myassetid.forEach(function(item) { 798 | counteroffer.removeMyItem({"appid": 753, "contextid": 6, "assetid": item}); 799 | }); 800 | theirassetid.forEach(function(item) { 801 | counteroffer.removeTheirItem({"appid": 753, "contextid": 6, "assetid": item}); 802 | }); 803 | 804 | if (counterofferSteamID == offer.partner.getSteamID64()){ 805 | counteroffer.setMessage("I'm not doing charity here"); 806 | } 807 | else if (offer.itemsToReceive.length == 1){ 808 | counteroffer.setMessage("Soo.. begging huh? That's not nice"); 809 | } 810 | else { 811 | counteroffer.setMessage(offer.itemsToReceive.length+ " : "+offer.itemsToReceive.length+" please. Read trade rules and don't be greedy"); 812 | } 813 | 814 | counteroffer.send(function(err, status){ 815 | if (err){ 816 | var log = (currentdate() + " - Unable to send Counter Offer - "+err); 817 | console.log(log); 818 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 819 | offer.decline(); 820 | } 821 | }); 822 | counterofferSteamID = offer.partner.getSteamID64(); 823 | 824 | setTimeout(function(){ 825 | acceptConfirmation(); 826 | }, 3000); 827 | } 828 | else if ((offer.itemsToGive.length < offer.itemsToReceive.length) && removedcards > 0){ 829 | var log = (currentdate() + " - Countered ("+offer.itemsToGive.length+ ":"+offer.itemsToReceive.length+") Trade Offer #" +offer.id+ " : " +offer.partner.getSteamID64()+ " - Reason: Too much item"); 830 | console.log(log); 831 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 832 | var counteroffer = offer.counter(); 833 | 834 | offer.itemsToGive.forEach(function(item) { 835 | if (item.type == "MYBACKGROUND"){ 836 | counteroffer.removeMyItem({"appid": item.appid, "contextid": item.contextid, "assetid": item.assetid}); 837 | } 838 | }); 839 | offer.itemsToReceive.forEach(function(item) { 840 | if (item.type == "MYBACKGROUND"){ 841 | counteroffer.removeTheirItem({"appid": item.appid, "contextid": item.contextid, "assetid": item.assetid}); 842 | } 843 | }); 844 | 845 | myassetid.forEach(function(item) { 846 | counteroffer.removeMyItem({"appid": 753, "contextid": 6, "assetid": item}); 847 | }); 848 | theirassetid.forEach(function(item) { 849 | counteroffer.removeTheirItem({"appid": 753, "contextid": 6, "assetid": item}); 850 | }); 851 | 852 | counteroffer.setMessage("Hello, VanillaBot here... You put too many item in your trade offer."); 853 | counteroffer.send(function(err, status){ 854 | if (err){ 855 | var log = (currentdate() + " - Unable to send Counter Offer - "+err); 856 | console.log(log); 857 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 858 | offer.decline(); 859 | } 860 | }); 861 | counterofferSteamID = offer.partner.getSteamID64(); 862 | 863 | setTimeout(function(){ 864 | acceptConfirmation(); 865 | }, 3000); 866 | } 867 | else if ((offer.itemsToGive.length == offer.itemsToReceive.length) && removedcards > 0){ 868 | var log = (currentdate() + " - Countered ("+offer.itemsToGive.length+ ":"+offer.itemsToReceive.length+") Trade Offer #" +offer.id+ " : " +offer.partner.getSteamID64()+ " - Reason: Trying cross-set"); 869 | console.log(log); 870 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 871 | var counteroffer = offer.counter(); 872 | 873 | offer.itemsToGive.forEach(function(item) { 874 | if (item.type == "MYBACKGROUND"){ 875 | counteroffer.removeMyItem({"appid": item.appid, "contextid": item.contextid, "assetid": item.assetid}); 876 | } 877 | }); 878 | offer.itemsToReceive.forEach(function(item) { 879 | if (item.type == "MYBACKGROUND"){ 880 | counteroffer.removeTheirItem({"appid": item.appid, "contextid": item.contextid, "assetid": item.assetid}); 881 | } 882 | }); 883 | 884 | myassetid.forEach(function(item) { 885 | counteroffer.removeMyItem({"appid": 753, "contextid": 6, "assetid": item}); 886 | }); 887 | theirassetid.forEach(function(item) { 888 | counteroffer.removeTheirItem({"appid": 753, "contextid": 6, "assetid": item}); 889 | }); 890 | 891 | counteroffer.setMessage("Hello, VanillaBot here... No cross-set please."); 892 | counteroffer.send(function(err, status){ 893 | if (err){ 894 | var log = (currentdate() + " - Unable to send Counter Offer - "+err); 895 | console.log(log); 896 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 897 | offer.decline(); 898 | } 899 | }); 900 | counterofferSteamID = offer.partner.getSteamID64(); 901 | 902 | setTimeout(function(){ 903 | acceptConfirmation(); 904 | }, 3000); 905 | } 906 | 907 | else { 908 | //Decline other trade offer 909 | var log = (currentdate() + " - Rejecting Trade Offer from " +offer.partner.getSteamID64()+ " - Reason: Else"); 910 | console.log(log); 911 | fs.appendFile("log.txt", log + "\n", {flag: 'a'}, function(err) {}); 912 | 913 | offer.decline(); 914 | } 915 | }); 916 | --------------------------------------------------------------------------------