Maxouille

Autojoin battles PS!

Apr 20th, 2021
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Autojoin battles PS!
  3. // @namespace autojoinbattlesps
  4. // @description Custom client command to autojoin battles for specific users
  5. // @include http://play.pokemonshowdown.com/
  6. // @include https://play.pokemonshowdown.com/
  7. // @include http://play.pokemonshowdown.com/*
  8. // @include https://play.pokemonshowdown.com/*
  9. // @include http://*.psim.us/
  10. // @include https://*.psim.us/
  11. // @include http://*.psim.us/*
  12. // @include https://*.psim.us/*
  13. // @version 2.0.1
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. var countInit = 0;
  18. var eaubot = "eaubot";
  19. var watchedUsers = {eaubot};
  20. var joinedBattles = [];
  21.  
  22. var init = function() {
  23. if (!ConsoleRoom.prototype.customCommands) {
  24. if (countInit > 10) {
  25. return alert('Autojoin battles: helper script not detected\nPlease download it now from https://greasyfork.org/en/scripts/33834\nThen refresh this page');
  26. }
  27. countInit++;
  28. return setTimeout(init, 250);
  29. }
  30.  
  31. ConsoleRoom.prototype.customCommands['autojoinbattles'] = function(self, user) {
  32. user = toId(user);
  33. if (user === '') {
  34. addHelp(self);
  35. return false;
  36. }
  37. if (watchedUsers[user]) {
  38. self.add('User \'' + user + '\' is already on your autojoin list.');
  39. return false;
  40. }
  41. watchedUsers[user] = setInterval(function() {
  42. app.send('/cmd userdetails ' + user);
  43. }, 5000);
  44. self.add('You are now automatically joining ' + user + '\'' + (user.charAt(user.length - 1) !== 's' ? 's' : '') + ' battles.');
  45. return false;
  46. };
  47.  
  48. ConsoleRoom.prototype.customCommands['stopautojoinbattles'] = function(self, user) {
  49. user = toId(user);
  50. if (user === '') {
  51. addHelp(self);
  52. return false;
  53. }
  54. if (!watchedUsers[user]) {
  55. self.add('User \'' + user + '\' isn\'t on your autojoin list.');
  56. return false;
  57. }
  58. clearInterval(watchedUsers[user]);
  59. delete watchedUsers[user];
  60. self.add('You are no longer automatically joining ' + user + '\'' + (user.charAt(user.length - 1) !== 's' ? 's' : '') + ' battles.');
  61. return false;
  62. };
  63.  
  64. ConsoleRoom.prototype.customCommands['autojoinbattleslist'] = function(self) {
  65. var users = '';
  66. for (var i in watchedUsers) {
  67. if (users !== '') users += ', ';
  68. users += i;
  69. }
  70. if (users === '') {
  71. self.add('Your autojoin list is empty.');
  72. } else {
  73. self.add('Users in your autojoin list: ' + users + '.');
  74. }
  75. return false;
  76. };
  77. };
  78.  
  79. var addHelp = function(self) {
  80. self.add('/autojoinbattles [user] - Add the user [user] to the autojoin list.');
  81. self.add('/stopautojoinbattles [user] - Remove the user [user] from the autojoin list.');
  82. self.add('/autojoinbattleslist - List all the users in your autojoin list.');
  83. }
  84.  
  85. var parseUserdetailsResponse = function(data) {
  86. if (watchedUsers[data.userid]) {
  87. var battleid;
  88. for (var i in data.rooms) {
  89. battleid = i.replace(/[^A-Za-z0-9-]/g, '');
  90. if (battleid.substr(0, 7) === 'battle-' && joinedBattles.indexOf(battleid) === -1 && (toId(data.rooms[i].p1) === data.userid || toId(data.rooms[i].p2) === data.userid)) {
  91. ConsoleRoom.prototype.send('/j ' + battleid);
  92. joinedBattles.push(battleid);
  93. }
  94. }
  95. }
  96. };
  97.  
  98. window.addEventListener('load', function() {
  99. init();
  100. app.on('response:userdetails', parseUserdetailsResponse, this);
  101. });
Advertisement
Add Comment
Please, Sign In to add comment