Advertisement
Guest User

Untitled

a guest
Jul 13th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.58 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.  
  18. // CONST
  19.  
  20.  
  21.  
  22. //SKIT
  23. const manager = new TradeOfferManager ({
  24. steam: client,
  25. community: community,
  26. language: 'en'
  27. });
  28.  
  29.  
  30. const logOnOptions = {
  31. accountName: config.username,
  32. password: config.password,
  33. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  34. };
  35.  
  36. client.logOn(logOnOptions);
  37.  
  38. client.on('loggedOn', () => {
  39. console.log('Succesfully logged on.');
  40. client.chatMessage(ownerID, "Succesfully logged on.")
  41.  
  42. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  43. client.gamesPlayed([440]); // Custom game name HÄÄÄÄÄÄR!
  44. });
  45.  
  46. client.on('accountInfo', function(name, country) {});
  47. //SKIT
  48.  
  49.  
  50.  
  51. // FRIEND MESSAGES ------------------------------------------------------------------------------------------------------------------------------------------- FRIEND MESSAGES//
  52. client.on("friendMessage", function(steamID, message) {
  53. if (message == "!commands") {
  54. client.chatMessage(steamID, "My commands are:");
  55. client.chatMessage(steamID, "!stock to get my current stock");
  56. client.chatMessage(steamID, "!owner to know who my owner is.");
  57. client.chatMessage(steamID, "!how2trade to know how to trade with me")
  58. client.chatMessage(steamID, "!donate to donate (wip)")
  59. client.chatMessage(steamID, "!tradelink to get my tradelink")
  60. client.chatMessage(steamID, "!donators to see all my donators.")
  61. client.getPersonas([steamID], function(personas) {
  62. var persona = personas[steamID.getSteamID64()];
  63. var name = persona ? persona.player_name : (`['${steamID.getSteamID64()}']`); {
  64. console.log(`${name} (${steamID.getSteamID64()}) Skrev !commands`);
  65. }
  66. });
  67. }
  68. else if (message == "!stock") {
  69. manager.getInventoryContents(440, 2, true, function (err, inventory) {
  70. if (err) {
  71. client.chatMessage(steamID, "Oooopsi daisy that didn't work.")
  72. return;
  73. }
  74. var refined, reclaimed, scrap, keys = 0;
  75. for (var i = 0; i < inventory.length; i++) {
  76. var item = inventory [i];
  77. var name = item.market_hash_name;
  78. if (name == "Refined Metal") {
  79. refined++;
  80. } else if (name == "Reclaimed Metal") {
  81. reclaimed++;
  82. } else if (name == "Scrap Metal") {
  83. scrap++
  84. } else if (name == "Mann Co.Supply Crate Key") {
  85. keys++
  86. }
  87.  
  88. }
  89. client.chatMessage(steamID, "Stock is "),
  90. client.chatMessage(steamID, "Mann Co.Supply Crate Keys:", keys),
  91. client.chatMessage(steamID, "Refined:", refined),
  92. client.chatMessage(steamID, "Reclaimed:", reclaimed),
  93. client.chatMessage(steamID, "Scrap:", scrap)
  94. })
  95. } else if (message == "!how2trade") {
  96. 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")
  97.  
  98. } else if (message == "!owner") {
  99. client.chatMessage(steamID, "I am coded by Aethez you can find his profile in my comments on my profile.")
  100.  
  101.  
  102. } else if(message.match("!play") && steamID == config.ownerID) { // TITTA HÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄR
  103. message = message.replace("!play ", "");
  104. console.log(message);
  105. client.gamesPlayed([message, 440])
  106.  
  107. } else if(message.match("!tf2") && steamID == config.ownerID) {
  108. console.log(message);
  109. client.gamesPlayed([440])
  110.  
  111. } else if (message.match("!online") && steamID == ownerID) {
  112. client.gamesPlayed([])
  113. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  114.  
  115. } else if (message.match("!busy") && steamID == ownerID) {
  116. client.gamesPlayed([])
  117. client.setPersona(SteamUser.Steam.EPersonaState.Busy);
  118.  
  119. } else if (message.match("!away") && steamID == ownerID) {
  120. client.gamesPlayed([])
  121. client.setPersona(SteamUser.Steam.EPersonaState.Away);
  122.  
  123. } else if (message.match("!ocommands") && steamID == ownerID) {
  124. client.chatMessage(ownerID, "My owner commands are:")
  125. client.chatMessage(ownerID, "!play to choose what the bot should play")
  126. client.chatMessage(ownerID, "!tf2 to play tf2")
  127. client.chatMessage(ownerID, "!online to only go online and not play tf2")
  128. client.chatMessage(ownerID, "!busy to go busy and not play tf2")
  129. client.chatMessage(ownerID, "!away to go away and not play tf2")
  130. client.chatMessage(ownerID, "!tradelink not owner command only but...")
  131.  
  132. } else if (message.match("!donate")) {
  133. client.chatMessage(steamID, "If you want to donate just trade me with nothing on my side! Put a message with the following text: DONATION")
  134.  
  135. } else if (message == "!tradelink") {
  136. client.chatMessage(steamID, "https://steamcommunity.com/tradeoffer/new/?partner=886523840&token=Y-s4Jvor")
  137.  
  138. } else if (message.match("!donators")) {
  139. client.chatMessage(steamID, "I haven't recieved any donations yet. Do you want to be on this list, simply donate! Doesnt matter how much!")
  140.  
  141. } else {
  142. client.chatMessage(steamID, "Sorry i couldn't understand that type !commands to get further information about what i can do.")
  143.  
  144. }
  145.  
  146. });
  147. // FRIEND MESSAGES ------------------------------------------------------------------------------------------------------------------------------------------- FRIEND MESSAGES//
  148.  
  149.  
  150.  
  151.  
  152.  
  153. // TRADING
  154. client.on('webSession', (sessionid, cookies) => {
  155. manager.setCookies(cookies);
  156.  
  157. community.setCookies(cookies);
  158. community.startConfirmationChecker(20000, config.identitySecret);
  159. });
  160.  
  161. function acceptOffer(offer) {
  162. offer.accept((err) => {
  163. community.checkConfirmations();
  164. console.log("Succesfully accepted a trade!");
  165. client.chatMessage(ownerID, "Succesfully accepted a trade!")
  166. if (err) console.log("There was an error accepting the offer."), client.chamessage(ownerID, "There was an error accepting the offer.");
  167. });
  168. }
  169.  
  170. function declineOffer(offer) {
  171. offer.decline((err) => {
  172. console.log("Declined an offer");
  173. client.chatMessage(ownerID, "Declined an offer")
  174. if (err) console.log("There was an error declining the offer.");
  175. });
  176. }
  177.  
  178. client.setOption("promptSteamGuardCode", false);
  179.  
  180. function processOffer(offer) {
  181. if (offer.isGlitched() || offer.state === 11) {
  182. console.log("A trade offer was glitched declining.");
  183. client.chatMessage(ownerID, "A trade offer was glitched declining.")
  184. declineOffer(offer);
  185. } else if (offer.partner.getSteamID64() === ownerID) {
  186. acceptOffer(offer);
  187. } else {
  188. var ourItems = offer.itemsToGive;
  189. var theirItems = offer.itemstoReceive;
  190. var ourValue = 0;
  191. var theirValue = 0;
  192. for (var i in ourItems) {
  193. var item = ourItems[i].market_name;
  194. if(Prices[item]) {
  195. ourValue += Prices[item].sell;
  196.  
  197. } else {
  198. console.log("Invalid Value.");
  199. ourValue += 99999;
  200. }
  201. }
  202. for(var i in theirItems) {
  203. var item= theirItems[i].market_name;
  204. if(Prices[item]) {
  205. theirValue += Prices[item].buy;
  206. } else {
  207. console.log("Their value was different.")
  208. client.chatMessage(ownerID, "I got a trade offer but i declined it because their value was different:")
  209. }
  210. }
  211. }
  212. console.log("Our value: "+ourValue);
  213. console.log("Their Value: "+theirValue);
  214. console.log("These were the items i offered: "+itemsToGive);
  215. console.log("These were the items he offered: "+itemstoReceive);
  216. client.chatMessage(ownerID, "Our value: "+ourValue);
  217. client.chatMessage(ownerID, "Their Value:"+theirValue)
  218. client.chatMessage(ownerID, "These were the items i offered: "+itemsToGive);
  219. client.chatMessage(ownerID, "These were the items they offered: "+itemstoReceive);
  220.  
  221. if (ourValue <= theirValue) {
  222. acceptOffer(offer);
  223. } else {
  224. declineOffer(offer);
  225. }
  226. }
  227.  
  228.  
  229. manager.on('newOffer', (offer) => {
  230. processOffer(offer);
  231. });
  232. //TRADING
  233.  
  234.  
  235.  
  236.  
  237.  
  238. //Friends!!!
  239. client.on('friendRelationship', function(sid, relationship) {
  240. if (relationship == SteamUser.EFriendRelationship.RequestRecipient) {
  241. console.log("We recieved a friend request from "+sid);
  242. client.addFriend(sid, function (err, name) {
  243. if (err) {
  244. console.log(err);
  245. return;
  246. } else {
  247. console.log("Accepted user with the name of "+name);
  248. client.chatMessage(config.ownerID, "Added 1 person, their name is: " +name);
  249. client.chatMessage(sid, "Hi thanks for adding me, type !commands to get my command list.");
  250. }
  251. });
  252. }
  253.  
  254. });
  255. //FRIENDS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement