Maxouille

showdown.js

Aug 6th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. // ==UserScript==
  2. // @name RTB
  3. // @version 1.0.0
  4. // @grant unsafeWindow
  5. // @author me
  6. // @match http://play.pokemonshowdown.com/*
  7. // @match https://play.pokemonshowdown.com/*
  8. // @match http://*.psim.us/*
  9. // @match https://*.psim.us/*
  10. // ==/UserScript==
  11.  
  12. var teams = {};
  13. var search = false;
  14.  
  15. fetch('https://raw.githubusercontent.com/Maxouille64/database/main/teams.json')
  16. .then(response => response.json())
  17. .then(data => teams = data)
  18. .then(teams => app.send('/code RANDOMIZABLE FORMATS: \n' + Object.keys(teams)));
  19.  
  20. const BYPASS_CORS = 'https://cors-anywhere-hd.herokuapp.com/https://drive.google.com/uc?id=' //à changer
  21. const cancel_button = document.getElementById("rtbcancelSearch");
  22.  
  23. function getRandom(min, max) {
  24. let random = (Math.floor(Math.random() * max/2)+ min/2) * 2;
  25. return random;
  26. };
  27.  
  28. function cancel_rtb() {
  29. cancel = true;
  30. cancel_button.style="display: none";
  31. };
  32.  
  33. function getCookie(cname) {
  34. var name = cname + "=";
  35. var ca = document.cookie.split(';');
  36. for(var i = 0; i < ca.length; i++) {
  37. var c = ca[i];
  38. while (c.charAt(0) == ' ') {
  39. c = c.substring(1);
  40. }
  41. if (c.indexOf(name) == 0) {
  42. return c.substring(name.length, c.length);
  43. }
  44. }
  45. return "";
  46. };
  47.  
  48. function rtb(Tier, txt){
  49. let myteams = txt.split("===");
  50. var team = myteams[getRandom(2, myteams.length)];
  51. //for node.js use global instead of window
  52. //var console = global.console;
  53. window.console.log = function(msg){
  54. if(msg.includes('|popup|Your team was rejected for the following reasons'))
  55. //app.closePopup();
  56. rtb(Tier,txt);
  57. return;
  58. };
  59. if (cancel == true) {
  60. cancel = false;
  61. cancel_button.style="display: none";
  62. return;
  63. } else if(team) {
  64. team.replace(/^\s\s*/, '');
  65. team.replace(/\s\s*$/, '');
  66. app.send("/code " + team);
  67. team_json = PokemonTeams.importTeam(team);
  68. app.sendTeam(team_json);
  69. app.send(`/battle! ${Tier}`);
  70. } else {
  71. cancel_button.style="display: none";
  72. app.send("/code request failed/unavailable tier, try with /rtb [tier] in a chatroom");
  73. return;
  74. };
  75. }
  76.  
  77. function rta(Tier, team){
  78. if (cancel == true) {
  79. cancel = false;
  80. cancel_button.style="display: none";
  81. return;
  82. } else if(team) {
  83. team.replace(/^\s\s*/, '');
  84. team.replace(/\s\s*$/, '');
  85. app.send("/code " + team);
  86. team_json = PokemonTeams.importTeam(team);
  87. app.sendTeam(team_json);
  88. app.send(`/battle! ${Tier}`);
  89. } else {
  90. cancel_button.style="display: none";
  91. app.send("/code request failed/unavailable tier, try with /rtb [tier] in a chatroom");
  92. return;
  93. };
  94. }
  95.  
  96.  
  97.  
  98. function rtc(Tier, User, txt) {
  99. let myteams = txt.split("===");
  100. var team = myteams[getRandom(2, myteams.length)];
  101. window.console.log = function(msg){
  102. if(msg.includes('|popup|Your team was rejected for the following reasons'))
  103. //app.closePopup();
  104. rtc(Tier,User,txt);
  105. return;
  106. };
  107. if (team) {
  108. team.replace(/^\s\s*/, '');
  109. team.replace(/\s\s*$/, '');
  110. app.send(`/code ${team}`);
  111. team_json = PokemonTeams.importTeam(team);
  112. app.sendTeam(team_json);
  113. app.send(`/challenge ${User}, ${Tier}`);
  114. } else {
  115. app.send("/code request failed/unavailable tier, try with /rtb [tier] in a chatroom");
  116. };
  117. };
  118.  
  119. var cancel = false;
  120.  
  121. ConsoleRoom.prototype.customCommands = {};
  122. ConsoleRoom.prototype.customCommands['rtb'] = function(Self, Tier) {
  123. var mod = getCookie("mod");
  124. cancel_button.style="";
  125. if (mod == "default") {
  126. fetch(BYPASS_CORS + teams[Tier])
  127. .then(rep => rep.text())
  128. .then(result => rtb(Tier, result))
  129. } else if (mod == "easy") {
  130. fetch(`https://maxouille.pythonanywhere.com/lunatic/?input={"tier":"${Tier}","mod":"easy"}`).then(r => r.text()).then(result => {
  131. console.log(result);
  132. rta(Tier, result);
  133. })
  134. } else if (mod == "normal") {
  135. fetch(`https://maxouille.pythonanywhere.com/lunatic/?input={"tier":"${Tier}","mod":"normal"}`).then(r => r.text()).then(result => {
  136. console.log(result);
  137. rta(Tier, result);
  138. })
  139. } else if (mod == "hard") {
  140. fetch(`https://maxouille.pythonanywhere.com/lunatic/?input={"tier":"${Tier}","mod":"hard"}`).then(r => r.text()).then(result => {
  141. console.log(result);
  142. rta(Tier, result);
  143. })
  144. } else if (mod == "lunatic") {
  145. fetch(`https://maxouille.pythonanywhere.com/lunatic/?input={"tier":"${Tier}","mod":"lunatic"}`).then(r => r.text()).then(result => {
  146. console.log(result);
  147. rta(Tier, result);
  148. })
  149. } else if (mod == "matrix") {
  150. fetch('https://maxouille.pythonanywhere.com/matrix/?input={"tier":"gen8ou"}').then(r => r.text()).then(result => {
  151. console.log(result);
  152. rta(Tier, result);
  153. })
  154. } else if (mod == "teambuilder") {
  155. fetch(`https://maxouille.pythonanywhere.com/teambuilder/?input={"tier":"${Tier}","data":${localStorage.getItem("showdown_teams")}}`).then(r => r.text()).then(result => {
  156. console.log(result);
  157. //rta(Tier, result);
  158. })
  159. } else {
  160. fetch(BYPASS_CORS + teams[Tier])
  161. .then(rep => rep.text())
  162. .then(result => rtb(Tier, result))};
  163. };
  164.  
  165. ConsoleRoom.prototype.customCommands['rtc'] = function(Self, Tier, User) {
  166. fetch(BYPASS_CORS + teams[Tier])
  167. .then(rep => rep.text())
  168. .then(result => rtc(Tier, User, result))};
  169.  
  170. ConsoleRoom.prototype.parseCommandOrig = ConsoleRoom.prototype.parseCommand;
  171. ConsoleRoom.prototype.parseCommand = function(Text) {
  172. var cmd = '';
  173. var target = '';
  174. var noSpace = false;
  175. var user = 'guest';
  176. if (Text.substr(0, 2) !== '//' && Text.substr(0, 3) === '/rt') {
  177. app.send('/utm');
  178. var spaceIndex = Text.indexOf(' ');
  179. var commaIndex = Text.indexOf(',');
  180. if (commaIndex > 0) {
  181. Text = Text.split(",")
  182. cmd = Text[0].substr(1, spaceIndex - 1);
  183. console.log("//CMD");
  184. console.log(cmd);
  185. target = Text[0].substr(spaceIndex + 1).toLowerCase();
  186. console.log("//TARGET");
  187. console.log(target);
  188. user = Text[1]
  189. console.log("//user");
  190. console.log(user);
  191. }
  192. else if (spaceIndex > 0) {
  193. cmd = Text.substr(1, spaceIndex - 1);
  194. console.log("//CMD");
  195. console.log(cmd);
  196. target = Text.substr(spaceIndex + 1).toLowerCase();
  197. console.log("//TARGET");
  198. console.log(target);
  199. } else {
  200. console.log("//CMD");
  201. cmd = Text.substr(1);
  202. console.log(cmd)
  203. target = '';
  204. noSpace = true;
  205. }
  206. };
  207. if (this.customCommands[cmd.toLowerCase()]) return this.customCommands[cmd.toLowerCase()](this, target, user);
  208. return this.parseCommandOrig(Text);
  209. };
Advertisement
Add Comment
Please, Sign In to add comment