Guest User

Untitled

a guest
Jul 23rd, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.62 KB | None | 0 0
  1. //CONST
  2. const SteamUser = require('steam-user');
  3. const SteamTotp = require('steam-totp');
  4. const SteamCommunity = require('steamcommunity');
  5. const TradeOfferManager = require('steam-tradeoffer-manager');
  6. const config = require('./config.json');
  7. const TeamFortress2 = require ('tf2');
  8. const Prices = require('./prices.json');
  9. const client = new SteamUser();
  10. const tf2 = new TeamFortress2(client);
  11. const community = new SteamCommunity();
  12. var ownerID = config.ownerID
  13.  
  14.  
  15.  
  16.  
  17. // CONST
  18.  
  19.  
  20.  
  21. //SKIT
  22. const manager = new TradeOfferManager ({
  23. steam: client,
  24. community: community,
  25. language: 'en'
  26. });
  27.  
  28.  
  29. const logOnOptions = {
  30. accountName: config.username,
  31. password: config.password,
  32. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  33. };
  34.  
  35. client.logOn(logOnOptions);
  36.  
  37. client.on('loggedOn', () => {
  38. console.log('Succesfully logged on.');
  39. client.chatMessage(ownerID, "Succesfully logged on.")
  40. let keys = 0;
  41. let refined = 0;
  42. let reclaimed = 0;
  43. let scrap = 0;
  44. manager.getInventoryContents(440, 2, true, function (err, inventory) {
  45. if (err) {
  46. client.chatMessage(steamID, "Oooopsi daisy that didn't work.")
  47. return;
  48. }
  49. for (var i = 0; i < inventory.length; i++) {
  50. var item = inventory [i];
  51. var name = item.market_hash_name;
  52. if (name == "Refined Metal") {
  53. refined++;
  54. } else if (name == "Reclaimed Metal") {
  55. reclaimed++;
  56. } else if (name == "Scrap Metal") {
  57. scrap++;
  58. } else if (name == "Mann Co.Supply Crate Key") {
  59. keys++;
  60. }
  61.  
  62. }
  63. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  64. client.gamesPlayed([440]); // Custom game name HÄÄÄÄÄÄR!
  65. });
  66. //SKIT
  67.  
  68.  
  69.  
  70. // FRIEND MESSAGES ------------------------------------------------------------------------------------------------------------------------------------------- FRIEND MESSAGES//
  71. client.on("friendMessage", function(steamID, message) {
  72. if (message == "!commands") {
  73. client.chatMessage(steamID, "My commands are:");
  74. client.chatMessage(steamID, "!stock to get my current stock");
  75. client.chatMessage(steamID, "!owner to know who my owner is.");
  76. client.chatMessage(steamID, "!how2trade to know how to trade with me")
  77. client.chatMessage(steamID, "!donate to donate (wip)")
  78. client.chatMessage(steamID, "!tradelink to get my tradelink")
  79. client.chatMessage(steamID, "!donators to see all my donators.")
  80. client.chatMessage(steamID, "!message to send my owner a message but remember to post your steam username in the message.")
  81. client.getPersonas([steamID], function(personas) {
  82. var persona = personas[steamID.getSteamID64()];
  83. var name = persona ? persona.player_name : (`['${steamID.getSteamID64()}']`); {
  84. console.log(`${name} (${steamID.getSteamID64()}) Skrev !commands`);
  85. client.chatMessage(ownerID, `${name} (${steamID.getSteamID64()}) Skrev !commands`)
  86. }
  87. });
  88. }
  89. else if (message.match("!stock")) {
  90. client.chatMessage(steamID, "Keys" + keys)
  91.  
  92. } else if (message == "!how2trade") {
  93. client.chatMessage(steamID, "You basically send a trade offer with the correct amount, you can check my listings here https://backpack.tf/classifieds?steamid=76561198846789568")
  94.  
  95. } else if (message == "!owner") {
  96. client.chatMessage(steamID, "I am coded by Aethez you can find his profile in my comments on my profile.")
  97.  
  98.  
  99. } else if(message.match("!play") && steamID == config.ownerID) { // TITTA HÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄR
  100. message = message.replace("!play ", "");
  101. console.log(message);
  102. client.gamesPlayed([message, 440])
  103.  
  104. } else if(message.match("!tf2") && steamID == config.ownerID) {
  105. console.log(message);
  106. client.gamesPlayed([440])
  107.  
  108. } else if (message.match("!online") && steamID == ownerID) {
  109. client.gamesPlayed([])
  110. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  111.  
  112. } else if (message.match("!busy") && steamID == ownerID) {
  113. client.gamesPlayed([])
  114. client.setPersona(SteamUser.Steam.EPersonaState.Busy);
  115.  
  116. } else if (message.match("!away") && steamID == ownerID) {
  117. client.gamesPlayed([])
  118. client.setPersona(SteamUser.Steam.EPersonaState.Away);
  119.  
  120. } else if (message.match("!ocommands") && steamID == ownerID) {
  121. client.chatMessage(ownerID, "My owner commands are:")
  122. client.chatMessage(ownerID, "!play to choose what the bot should play")
  123. client.chatMessage(ownerID, "!tf2 to play tf2")
  124. client.chatMessage(ownerID, "!online to only go online and not play tf2")
  125. client.chatMessage(ownerID, "!busy to go busy and not play tf2")
  126. client.chatMessage(ownerID, "!away to go away and not play tf2")
  127. client.chatMessage(ownerID, "!tradelink not owner command only but...")
  128. client.chatMessage(ownerID, "!restart to restart the bot.")
  129.  
  130. } else if (message.match("!donate")) {
  131. client.chatMessage(steamID, "If you want to donate just trade me with nothing on my side! Put a message with the following text: DONATION")
  132.  
  133. } else if (message == "!tradelink") {
  134. client.chatMessage(steamID, "https://steamcommunity.com/tradeoffer/new/?partner=886523840&token=Y-s4Jvor")
  135.  
  136. } else if (message.match("!donators")) {
  137. client.chatMessage(steamID, "I haven't recieved any donations yet. Do you want to be on this list, simply donate! Doesnt matter how much!")
  138. } else if (message.match("!restart") && steamID == ownerID) {
  139. client.chatMessage(ownerID, "Restarting...")
  140. process.quit()
  141. } else if (message.match("!message")) {
  142. message = message.replace ("!message ", "");
  143. console.log(steamID, message)
  144. } else if (message.match("!trade")) {
  145. client.chatMessage(steamID, "Inviting.")
  146. client.trade(steamID)
  147. } else if (message.match("!avatar") && steamID == ownerID) {
  148. message = message.replace("!avatar ", "");
  149. var image = message
  150. community.uploadAvatar(image)
  151. } else if (message == "!profile") {
  152. client.chatMessage(steamID, "This is my profile link: https://steamcommunity.com/id/AethezTradeBot/")
  153. } else if (message.match("!name") && steamID == ownerID) {
  154. message = message.replace("!name ", "");
  155. var realname = message
  156. client.setPersona(1, realname)
  157. var realname = realname.toString();
  158. } else if (message == "!date") {
  159. var datum = new Date();
  160. datum.toDateString(datum)
  161. console.log(datum)
  162. var today = datum.toDateString();
  163. client.chatMessage(steamID, today)
  164. } else if (message == "!removeme") {
  165. client.removeFriend(steamID)
  166. client.chatMessage(ownerID, "Succesfully removed a user")
  167. } else if (message == "!slots") {
  168. var backpackslots = tf2.backpackSlots
  169. var backpackslotsen = backpackslots.toString()
  170. client.chatMessage(steamID, backpackslotsen)
  171. }
  172.  
  173.  
  174. });
  175.  
  176. // FRIEND MESSAGES ------------------------------------------------------------------------------------------------------------------------------------------- FRIEND MESSAGES//
  177.  
  178.  
  179.  
  180.  
  181.  
  182. // TRADING
  183. client.on('webSession', (sessionid, cookies) => {
  184. manager.setCookies(cookies);
  185.  
  186. community.setCookies(cookies);
  187. community.startConfirmationChecker(20000, config.identitySecret);
  188. });
  189.  
  190. function acceptOffer(offer) {
  191. offer.accept((err) => {
  192. community.checkConfirmations();
  193. console.log("We Accepted an offer");
  194. if (err) console.log("There was an error accepting the offer.");
  195. });
  196. }
  197.  
  198. function declineOffer(offer) {
  199. offer.decline((err) => {
  200. console.log("We Declined an offer");
  201. if (err) console.log("There was an error declining the offer.");
  202. });
  203. }
  204.  
  205. function processOffer(offer) {
  206. if (offer.isGlitched() || offer.state === 11) {
  207. console.log("Offer was glitched, declining.");
  208. declineOffer(offer);
  209. } else if (offer.partner.getSteamID64() === config.ownerID) {
  210. acceptOffer(offer);
  211. manager.getInventoryContents(440, 2, true, function (err, inventory) {
  212. if (err) {
  213. client.chatMessage(ownerID, "Couldnt get my stock.")
  214. return;
  215. }
  216. for (var i = 0; i < inventory.length; i++) {
  217. var item = inventory [i];
  218. var name = item.market_hash_name
  219. if (name == "Refined Metal") {
  220. refined++;
  221. } else if (name == "Reclaimed Metal") {
  222. reclaimed++
  223. } else if (name == "Scrap Metal") {
  224. scrap++;
  225. } else if (name == "Mann Co.Supply Crate Key") {
  226. keys++;
  227. }
  228. }
  229. });
  230.  
  231. } else {
  232. var ourItems = offer.itemsToGive;
  233. var theirItems = offer.itemsToReceive;
  234. var ourValue = 0;
  235. var theirValue = 0;
  236. for (var i in ourItems) {
  237. var item = ourItems[i].market_name;
  238. if(Prices[item]) {
  239. ourValue += Prices[item].sell;
  240. } else {
  241. console.log("Invalid Value.");
  242. ourValue += 99999;
  243. }
  244. }
  245. for(var i in theirItems) {
  246. var item= theirItems[i].market_name;
  247. if(Prices[item]) {
  248. theirValue += Prices[item].buy;
  249. } else {
  250. console.log("Their value was different.")
  251. }
  252. }
  253.  
  254. console.log("Our value: "+ourValue);
  255. console.log("Their value: "+theirValue);
  256.  
  257. if (ourValue <= theirValue) {
  258. acceptOffer(offer);0
  259. manager.getInventoryContents(440, 2, true, function (err, inventory) {
  260. if (err) {
  261. client.chatMessage(ownerID, "Couldnt get my stock when i completed a trade.")
  262. return;
  263. }
  264. for (var i = 0; i < inventory.length; i++) {
  265. var item = inventory [i];
  266. var name = item.market_hash_name
  267. if (name == "Refined Metal") {
  268. refined++;
  269. } else if (name == "Reclaimed Metal") {
  270. reclaimed++
  271. } else if (name == "Scrap Metal") {
  272. scrap++;
  273. } else if (name == "Mann Co.Supply Crate Key") {
  274. keys++;
  275. }
  276. }
  277. });
  278. } else {
  279. declineOffer(offer);
  280. }
  281. }
  282. }
  283.  
  284. client.setOption("promptSteamGuardCode", false);
  285.  
  286. manager.on('newOffer', (offer) => {
  287. processOffer(offer);
  288. });
  289. //TRADING
  290.  
  291.  
  292.  
  293.  
  294.  
  295. //Friends!!!
  296. client.on('friendRelationship', function(sid, relationship) {
  297. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  298. console.log("We recieved a friend request from "+sid);
  299. client.addFriend(sid, function (err, name) {
  300. if (err) {
  301. console.log(err);
  302. return;
  303. } else {
  304. console.log("Accepted user with the name of "+name);
  305. client.chatMessage(config.ownerID, "Added 1 person, their name is: " +name);
  306. client.chatMessage(sid, "Hi thanks for adding me, type !commands to get my command list.");
  307. }
  308. });
  309. }
  310.  
  311. });
  312. //FRIENDS
Add Comment
Please, Sign In to add comment