Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. const SteamUser = require('steam-user');
  2. const SteamTotp = require('steam-totp')
  3. const config = require ('./config.json')
  4. const SteamCommunity = require('steamcommunity')
  5. const TradeOfferManager = require('steam-tradeoffer-manager')
  6. const Winston = require('winston')
  7.  
  8. const client = new SteamUser();
  9. const community = new SteamCommunity();
  10. const manager = new TradeOfferManager({
  11.  
  12. });
  13.  
  14. //Auto Login and auth
  15.  
  16. const logOnOptions = {
  17. accountName: config.username,
  18. password: config.password,
  19. twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
  20. };
  21.  
  22. SteamCommunity.ChatState = 3;
  23.  
  24.  
  25.  
  26. client.logOn(logOnOptions);
  27.  
  28. client.on('loggedOn', () => {
  29. console.log('Successfully logged on');
  30. client.setPersona(SteamUser.Steam.EPersonaState.Online);
  31. client.gamesPlayed(["Nycklar | Bio För Pris | Inne"]);
  32. });
  33.  
  34. client.on("friend.Message", function(steamID, message) {
  35. if (message == "Tja"){
  36. client.chatMessage(steamID, "Tja");
  37. }
  38.  
  39. });
  40.  
  41. client.on('webSession', (sessionid, cookies) => {
  42. manager.setCookies(cookies);
  43.  
  44. community.setCookies(cookies);
  45. community.startConfirmationChecker(20000, config.identitysecret);
  46. });
  47.  
  48. //Some trade stuff
  49.  
  50. function acceptOffer(offer) {
  51. offer.accept((err) => {
  52. community.checkConfirmations();
  53. console.log("We accepted an offer")
  54. if (err) console.log ("There was an error accepting the offer.")
  55. });
  56. }
  57.  
  58. function declineOffer(offer) {
  59. offer.decline((err) => {
  60. console.log("We declined an offer.")
  61. if (err) console.log ("There was an error declining the offer.")
  62. });
  63. }
  64.  
  65. manager.on('newOffer', (offer) => {
  66. if (offer.partner.getSteamID64() === config.ownerID) {
  67. acceptOffer(offer);
  68. }
  69.  
  70. };
  71.  
  72. //Auto friend req accept etc
  73.  
  74. client.friends.on('relationships', function(){
  75. var friendcount = 0;
  76. for (steamID in client.friends.friends) {
  77. friendcount++;
  78. if (client.friends.friends[steamID] === SteamUser.Steam.EFriendRelationship.RequestRecipient) {
  79. logger.info("Friend request while offline from: "+steamID);
  80. client.friends.addFriend(steamID);
  81. }
  82. }
  83. logger.debug("We have "+friendcount+" friends.");
  84. if (friendcount > 200) {
  85. logger.warn("We're approaching the default friends limit.");
  86. }
  87. });
  88.  
  89. client.friends.on('friend', function (steamID, realationship) {
  90. if (relationship == SteamUser.Steam.EFriendRelationship.RequestRecipent) {
  91. logger.info('[' + steamID + '] Accepted friend request');
  92. client.friends.addFriend(steamID);
  93. }
  94. else if (relationship == SteamUser.Steam.EFriendRelationship.None) {
  95. logger.info('[' + steamID + '] Un-friended');
  96. }
  97. });
  98.  
  99. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement