Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let fs = require('fs'),
- requestify = require('requestify'),
- SteamUser = require('steam-user'),
- SteamTotp = require('steam-totp'),
- SteamCommunity = require("steamcommunity"),
- SteamGroups = require('steam-groups'),
- TradeOfferManager = require('steam-tradeoffer-manager'),
- GlobalOffensive = require('globaloffensive'),
- mysql = require('mysql');
- let request = require("request");
- let client = new SteamUser(),
- community = new SteamCommunity(),
- steamGroups = new SteamGroups(client);
- csgo = new GlobalOffensive(client);
- let manager = new TradeOfferManager({
- "steam": client,
- //"domain": "example.com",
- "language": "en"
- });
- let logOnOptions = {
- "accountName": "",
- "password": ""
- };
- let connection = mysql.createConnection({
- host : 'localhost',
- user : '',
- password : '',
- database : ''
- });
- connection.connect();
- client.logOn(logOnOptions);
- client.on('loggedOn', function() {
- let botName = logOnOptions.accountName;
- console.log("Logged in to the account : " + botName);
- client.setPersona(SteamUser.EPersonaState.Online);
- client.gamesPlayed(730);
- });
- client.on('webSession', function(sessionID, cookies) {
- manager.setCookies(cookies, function(err) {
- if (err) {
- console.log(err);
- process.exit(1);
- return;
- }
- console.log("Utilizing the following API key : " + manager.apiKey);
- });
- community.setCookies(cookies);
- //community.startConfirmationChecker(30000, "");
- setTimeout(function(){getAll();},everySeconds*1000);
- });
- client.on('friendRelationship', function(id, relationship) {
- if (relationship == 2) {
- client.addFriend(id);
- console.log("Added user : " + id + " to friends list.");
- 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.');
- connection.query("SELECT * FROM user WHERE steamid=" + id + " LIMIT 1", function(err, rows, fields) {
- if (err) throw err;
- if (rows > 0) {
- console.log(id + " is already present in database");
- } else {
- console.log(id + " is not in our database, adding them");
- connection.query("INSERT INTO users (steamid) VALUES ('" + id + "')", function(shit, rows, fields) {
- if (shit) {
- throw shit;
- }
- });
- }
- });
- }
- });
- client.on('friendMessage', function(senderID, message) {
- console.log("Received message from : " + senderID + ": " + message);
- if (message === "!rank") {
- console.log("Rank request from : " + senderID);
- csgo.requestPlayersProfile(senderID, function(result) {
- if (result) {
- let rank = result.ranking.rankId;
- console.log("User " + senderID + "'s rank is : " + rank);
- if (rank == 0) {
- client.chatMessage(senderID, "Your rank is : Unranked");
- } else if (rank == 1) {
- client.chatMessage(senderID, "Your rank is : Silver I");
- } else if (rank == 2) {
- client.chatMessage(senderID, "Your rank is : Silver II");
- } else if (rank == 3) {
- client.chatMessage(senderID, "Your rank is : Silver III");
- } else if (rank == 4) {
- client.chatMessage(senderID, "Your rank is : Silver IV");
- } else if (rank == 5) {
- client.chatMessage(senderID, "Your rank is : Silver Elite");
- } else if (rank == 6) {
- client.chatMessage(senderID, "Your rank is : Silver Elite Master");
- } else if (rank == 7) {
- client.chatMessage(senderID, "Your rank is : Gold Nova I");
- } else if (rank == 8) {
- client.chatMessage(senderID, "Your rank is : Gold Nova II");
- } else if (rank == 9) {
- client.chatMessage(senderID, "Your rank is : Gold Nova III");
- } else if (rank == 10) {
- client.chatMessage(senderID, "Your rank is : Gold Nova Master");
- } else if (rank == 11) {
- client.chatMessage(senderID, "Your rank is : Master Guardian I");
- } else if (rank == 12) {
- client.chatMessage(senderID, "Your rank is : Master Guardian II");
- } else if (rank == 13) {
- client.chatMessage(senderID, "Your rank is : Master Guardian Elite");
- } else if (rank == 14) {
- client.chatMessage(senderID, "Your rank is : Distinguished Master Guardian");
- } else if (rank == 15) {
- client.chatMessage(senderID, "Your rank is : Legendary Eagle");
- } else if (rank == 16) {
- client.chatMessage(senderID, "Your rank is : Legendary Eagle Master");
- } else if (rank == 17) {
- client.chatMessage(senderID, "Your rank is : Supreme Master First Class");
- } else if (rank == 18) {
- client.chatMessage(senderID, "Your rank is : Global Elite");
- } else {
- client.chatMessage(senderID, "Your rank is : " + rank);
- }
- connection.query('UPDATE users SET rank = "' + rank + '", needupdate = "1", updated = "' + Date.now() + '" WHERE steamid =' + senderID, function(err, rows, fields) {
- if (err) throw err;
- console.log("Updating MYSQL table for user : " + senderID + " with rank : " + rank);
- client.chatMessage(senderID, "Rank updated. Your Teamspeak Rank will be updated in up to one minute.");
- })
- }
- });
- }
- });
- function getAll() {
- console.log("Looping through our friends");
- var url = "https://api.steampowered.com/ISteamUser/GetFriendList/v1/?key=" + manager.apiKey + "&format=json&steamid=" + client.steamID;
- request(url, function(error, response, body) {
- var friendsList = JSON.parse(body);
- friends = friendsList.friendslist.friends;
- for (var i = 0; i < friends.length; i++) {
- var id = friends[i].steamid;
- console.log(id);
- csgo.requestPlayersProfile(friends[i].steamid, function(result, err) {
- if (err) throw err;
- if (result) {
- let rank = result.ranking.rankId;
- console.log("User " + id + "'s rank is : " + rank);
- connection.query('UPDATE users SET rank = "' + rank + '", needupdate = "1", updated = "' + Date.now() + '" WHERE steamid =' + id, function(err, rows, fields) {
- if (err) throw err;
- console.log("Updating MYSQL table for user : " + id + " with rank : " + rank);
- })
- } else {
- console.log("No result for user");
- }
- });
- }
- setTimeout(function(){getAll();},everySeconds*1000);
- });
- }
- var everySeconds = 5 //Check every X seconds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement