Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
1,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.18 KB | None | 0 0
  1. let fs = require('fs'),
  2. requestify = require('requestify'),
  3. SteamUser = require('steam-user'),
  4. SteamTotp = require('steam-totp'),
  5. SteamCommunity = require("steamcommunity"),
  6. SteamGroups = require('steam-groups'),
  7. TradeOfferManager = require('steam-tradeoffer-manager'),
  8. GlobalOffensive = require('globaloffensive'),
  9. mysql = require('mysql');
  10.  
  11. let request = require("request");
  12.  
  13. let client = new SteamUser(),
  14. community = new SteamCommunity(),
  15. steamGroups = new SteamGroups(client);
  16. csgo = new GlobalOffensive(client);
  17.  
  18. let manager = new TradeOfferManager({
  19. "steam": client,
  20. //"domain": "example.com",
  21. "language": "en"
  22. });
  23.  
  24. let logOnOptions = {
  25. "accountName": "",
  26. "password": ""
  27. };
  28.  
  29. let connection = mysql.createConnection({
  30. host : 'localhost',
  31. user : '',
  32. password : '',
  33. database : ''
  34. });
  35.  
  36. connection.connect();
  37. client.logOn(logOnOptions);
  38.  
  39. client.on('loggedOn', function() {
  40. let botName = logOnOptions.accountName;
  41. console.log("Logged in to the account : " + botName);
  42. client.setPersona(SteamUser.EPersonaState.Online);
  43. client.gamesPlayed(730);
  44. });
  45.  
  46. client.on('webSession', function(sessionID, cookies) {
  47. manager.setCookies(cookies, function(err) {
  48. if (err) {
  49. console.log(err);
  50. process.exit(1);
  51. return;
  52. }
  53.  
  54. console.log("Utilizing the following API key : " + manager.apiKey);
  55. });
  56.  
  57. community.setCookies(cookies);
  58. //community.startConfirmationChecker(30000, "");
  59. setTimeout(function(){getAll();},everySeconds*1000);
  60. });
  61.  
  62. client.on('friendRelationship', function(id, relationship) {
  63. if (relationship == 2) {
  64. client.addFriend(id);
  65. console.log("Added user : " + id + " to friends list.");
  66. client.chatMessage(id, 'Thank you for adding this bot, please launch cs:go and message !rank to me. Please login on http://bs-clan.de and store your Teamspeak UID before.');
  67.  
  68. connection.query("SELECT * FROM user WHERE steamid=" + id + " LIMIT 1", function(err, rows, fields) {
  69. if (err) throw err;
  70. if (rows > 0) {
  71. console.log(id + " is already present in database");
  72. } else {
  73. console.log(id + " is not in our database, adding them");
  74. connection.query("INSERT INTO users (steamid) VALUES ('" + id + "')", function(shit, rows, fields) {
  75. if (shit) {
  76. throw shit;
  77. }
  78. });
  79. }
  80. });
  81. }
  82. });
  83.  
  84. client.on('friendMessage', function(senderID, message) {
  85. console.log("Received message from : " + senderID + ": " + message);
  86. if (message === "!rank") {
  87. console.log("Rank request from : " + senderID);
  88. csgo.requestPlayersProfile(senderID, function(result) {
  89. if (result) {
  90. let rank = result.ranking.rankId;
  91. console.log("User " + senderID + "'s rank is : " + rank);
  92.  
  93. if (rank == 0) {
  94. client.chatMessage(senderID, "Your rank is : Unranked");
  95. } else if (rank == 1) {
  96. client.chatMessage(senderID, "Your rank is : Silver I");
  97. } else if (rank == 2) {
  98. client.chatMessage(senderID, "Your rank is : Silver II");
  99. } else if (rank == 3) {
  100. client.chatMessage(senderID, "Your rank is : Silver III");
  101. } else if (rank == 4) {
  102. client.chatMessage(senderID, "Your rank is : Silver IV");
  103. } else if (rank == 5) {
  104. client.chatMessage(senderID, "Your rank is : Silver Elite");
  105. } else if (rank == 6) {
  106. client.chatMessage(senderID, "Your rank is : Silver Elite Master");
  107. } else if (rank == 7) {
  108. client.chatMessage(senderID, "Your rank is : Gold Nova I");
  109. } else if (rank == 8) {
  110. client.chatMessage(senderID, "Your rank is : Gold Nova II");
  111. } else if (rank == 9) {
  112. client.chatMessage(senderID, "Your rank is : Gold Nova III");
  113. } else if (rank == 10) {
  114. client.chatMessage(senderID, "Your rank is : Gold Nova Master");
  115. } else if (rank == 11) {
  116. client.chatMessage(senderID, "Your rank is : Master Guardian I");
  117. } else if (rank == 12) {
  118. client.chatMessage(senderID, "Your rank is : Master Guardian II");
  119. } else if (rank == 13) {
  120. client.chatMessage(senderID, "Your rank is : Master Guardian Elite");
  121. } else if (rank == 14) {
  122. client.chatMessage(senderID, "Your rank is : Distinguished Master Guardian");
  123. } else if (rank == 15) {
  124. client.chatMessage(senderID, "Your rank is : Legendary Eagle");
  125. } else if (rank == 16) {
  126. client.chatMessage(senderID, "Your rank is : Legendary Eagle Master");
  127. } else if (rank == 17) {
  128. client.chatMessage(senderID, "Your rank is : Supreme Master First Class");
  129. } else if (rank == 18) {
  130. client.chatMessage(senderID, "Your rank is : Global Elite");
  131. } else {
  132. client.chatMessage(senderID, "Your rank is : " + rank);
  133. }
  134. connection.query('UPDATE users SET rank = "' + rank + '", needupdate = "1", updated = "' + Date.now() + '" WHERE steamid =' + senderID, function(err, rows, fields) {
  135. if (err) throw err;
  136. console.log("Updating MYSQL table for user : " + senderID + " with rank : " + rank);
  137. client.chatMessage(senderID, "Rank updated. Your Teamspeak Rank will be updated in up to one minute.");
  138. })
  139. }
  140. });
  141. }
  142. });
  143.  
  144. function getAll() {
  145. console.log("Looping through our friends");
  146. var url = "https://api.steampowered.com/ISteamUser/GetFriendList/v1/?key=" + manager.apiKey + "&format=json&steamid=" + client.steamID;
  147. request(url, function(error, response, body) {
  148. var friendsList = JSON.parse(body);
  149. friends = friendsList.friendslist.friends;
  150. for (var i = 0; i < friends.length; i++) {
  151. var id = friends[i].steamid;
  152. console.log(id);
  153. csgo.requestPlayersProfile(friends[i].steamid, function(result, err) {
  154. if (err) throw err;
  155. if (result) {
  156. let rank = result.ranking.rankId;
  157. console.log("User " + id + "'s rank is : " + rank);
  158.  
  159. connection.query('UPDATE users SET rank = "' + rank + '", needupdate = "1", updated = "' + Date.now() + '" WHERE steamid =' + id, function(err, rows, fields) {
  160. if (err) throw err;
  161. console.log("Updating MYSQL table for user : " + id + " with rank : " + rank);
  162. })
  163. } else {
  164. console.log("No result for user");
  165. }
  166. });
  167. }
  168. setTimeout(function(){getAll();},everySeconds*1000);
  169. });
  170. }
  171.  
  172. var everySeconds = 5 //Check every X seconds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement