Advertisement
Guest User

Untitled

a guest
Sep 10th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. // FIRST PART THAT GETS CALLED WHEN USER CLICKS BUTTON //
  2.  
  3. client.on('startData', function (user) {
  4. console.log("Started getting Data");
  5. //Useful to know when someone disconnects
  6. console.log(user);
  7.  
  8. var t = false;
  9. LolApi.Summoner.getByName(user)
  10. .then(function (summoner) {
  11. var id = summoner[user].id;
  12.  
  13. LolApi.getRecentGames(id)
  14. .then(function (summoners) {
  15. var list = summoners[1].fellowPlayers;
  16. for(i = 0; i < list.length; i++){
  17.  
  18. var id = summoners[1].fellowPlayers[i].summonerId;
  19. console.log("hello " + id);
  20. data(id, client);
  21. }
  22.  
  23. });
  24. });
  25. });
  26.  
  27. // LOOPING FUNCTIONS //
  28.  
  29. function addMore(name){
  30. var con = mysql.createConnection({
  31. host: "sql9.freemysqlhosting.net",
  32. user: "sql9132819",
  33. password: "5jt2vZeRmH",
  34. database: "sql9132819"
  35. });
  36. con.query("INSERT INTO League (User) VALUES ('" + name + "')",function(err,rows){
  37. if(err){
  38.  
  39. } else if(!err) {
  40. try{
  41.  
  42. } catch (err) {
  43.  
  44. }
  45. }
  46. });
  47. }
  48. function startAgain(id, client){
  49.  
  50. console.log(id);
  51. LolApi.getRecentGames(id, client)
  52. .then(function (summoners) {
  53. var list = summoners[1].fellowPlayers;
  54. for(i = 0; i < list.length; i++){
  55.  
  56. var id = summoners[1].fellowPlayers[i].summonerId;
  57. console.log("hello " + id);
  58. data(id, client);
  59. }
  60.  
  61. });
  62. }
  63. function data(id, client){
  64. LolApi.Summoner.getByID(id)
  65. .then(function (summonert) {
  66. var name = summonert[id].name;
  67. console.log(name);
  68. addMore(name);
  69. setTimeout(function pop(){
  70. startAgain(id, client);
  71. }, 700);
  72. client.emit("addNew");
  73. });
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement