IAMNEW322432

wsstbot

Sep 24th, 2023 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.35 KB | None | 0 0
  1. const prefix = "wsst!";
  2. const botname = "wsst Memphis: wsst!start";
  3. const help = "__wsst Memphis Start Menu.__\nweather, snake, maze, clock";
  4.  
  5. function sendMsg(msg) {
  6. setTimeout(() => {
  7. socket.emit("talk", { text: msg });
  8. }, 1100);
  9. }
  10.  
  11. setTimeout(() => { socket.emit("command", { list: ["name", "wsst Memphis: wsst!start"] }) }, 1000);
  12. setTimeout(() => { socket.emit("command", { list: ["name", "wsst Memphis: wsst!start"] }) }, 2100);
  13. setTimeout(() => { socket.emit("command",{list:["color","https://cdn.discordapp.com/attachments/1147262661281714269/1154779698874810378/scarypeedy.png"]}) }, 3200);
  14. setTimeout(() => {
  15. sendMsg("Start To Use wsst By Saying " + prefix + "start");
  16. setInterval(() => { sendMsg("Start To Use wsst Memphis By Saying " + prefix + "start, if you're bored do wsst!snake play!"); }, 60000);
  17. }, 4300);
  18.  
  19. socket.on("talk", function (message) {
  20. if (message.text === prefix + "start") {
  21. sendMsg(help);
  22. } else if (message.text.startsWith(prefix + "weather")) {
  23. const location = message.text.substring(prefix.length + 8);
  24. getWeather(location);
  25. } else if (message.text.startsWith(prefix + "snake")) {
  26. const command = message.text.substring(prefix.length + 6).trim();
  27. handleSnakeCommand(command);
  28. } else if (message.text.startsWith(prefix + "maze")) {
  29. const command = message.text.substring(prefix.length + 5).trim();
  30. handleMazeCommand(command);
  31. } else if (message.text === prefix + "clock") {
  32. sendMsg(getCurrentTime());
  33. }
  34. });
  35.  
  36. function getCurrentTime() {
  37. const now = new Date();
  38. const timeString = now.toLocaleTimeString("en-US", { hour12: true });
  39. return "Current time is: " + timeString;
  40. }
  41.  
  42. function handleSnakeCommand(command) {
  43. if (command === "play") {
  44. startSnakeGame();
  45. } else if (command === "up" || command === "down" || command === "left" || command === "right") {
  46. updateSnakeDirection(command);
  47. moveSnake();
  48. if (checkCollision()) {
  49. sendMsg("Game Over. You collided with the wall or yourself!");
  50. return;
  51. }
  52. checkFoodEaten();
  53. sendMsg(renderSnakeGame());
  54. } else {
  55. sendMsg("Invalid command. Use `" + prefix + "snake play` to start the game and `" + prefix + "snake up/down/left/right` to control.");
  56. }
  57. }
  58.  
  59. function getWeather(location) {
  60. const apiKey = "dcc6b2a3fa3d4fe58d9193316232905";
  61. const apiUrl = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${encodeURIComponent(location)}`;
  62.  
  63. fetch(apiUrl)
  64. .then((response) => response.json())
  65. .then((data) => {
  66. if (data.error) {
  67. sendMsg("Unable to retrieve weather information. Please check the location.");
  68. } else {
  69. const weather = data.current;
  70. const weatherInfo = `Weather in ${data.location.name}, ${data.location.country}:\nCondition: ${weather.condition.text}\nTemperature: ${weather.temp_c}°C\nHumidity: ${weather.humidity}%\nWind Speed: ${weather.wind_kph} km/h\n`;
  71. sendMsg(weatherInfo);
  72. }
  73. })
  74. .catch((error) => {
  75. console.error("Error:", error);
  76. sendMsg("An error occurred while retrieving weather information.");
  77. });
  78. }
  79.  
  80. // New snake game functions...
  81. let snake = [{ x: 0, y: 0 }]; // Snake's initial position (assuming the top-left corner as [0, 0])
  82. let food = { x: 5, y: 5 }; // Food's initial position
  83. let direction = "right"; // Initial direction of the snake
  84.  
  85. function startSnakeGame() {
  86. // Initialize the snake game state
  87. snake = [{ x: 0, y: 0 }];
  88. food = { x: 5, y: 5 };
  89. direction = "right";
  90.  
  91. sendMsg(renderSnakeGame());
  92. }
  93.  
  94. function updateSnakeDirection(command) {
  95. // Update the snake's direction based on the command received
  96. if (command === "up" && direction !== "down") {
  97. direction = "up";
  98. } else if (command === "down" && direction !== "up") {
  99. direction = "down";
  100. } else if (command === "left" && direction !== "right") {
  101. direction = "left";
  102. } else if (command === "right" && direction !== "left") {
  103. direction = "right";
  104. }
  105. }
  106.  
  107. function moveSnake() {
  108. // Move the snake in the current direction
  109. const head = { ...snake[0] };
  110.  
  111. if (direction === "up") {
  112. head.y--;
  113. } else if (direction === "down") {
  114. head.y++;
  115. } else if (direction === "left") {
  116. head.x--;
  117. } else if (direction === "right") {
  118. head.x++;
  119. }
  120.  
  121. // Add the new head to the snake
  122. snake.unshift(head);
  123. }
  124.  
  125. function checkCollision() {
  126. // Check if the snake collides with the game boundaries or itself
  127. const head = snake[0];
  128.  
  129. if (head.x < 0 || head.x >= 14 || head.y < 0 || head.y >= 6) {
  130. return true; // Collision with the game boundaries
  131. }
  132.  
  133. for (let i = 1; i < snake.length; i++) {
  134. if (snake[i].x === head.x && snake[i].y === head.y) {
  135. return true; // Collision with itself
  136. }
  137. }
  138.  
  139. return false;
  140. }
  141.  
  142. function checkFoodEaten() {
  143. // Check if the snake eats the food
  144. const head = snake[0];
  145.  
  146. if (head.x === food.x && head.y === food.y) {
  147. // Generate new food at a random position
  148. food = {
  149. x: Math.floor(Math.random() * 14),
  150. y: Math.floor(Math.random() * 6)
  151. };
  152.  
  153. // Do not remove the tail, so the snake grows
  154. } else {
  155. // Remove the tail to maintain the snake's length
  156. snake.pop();
  157. }
  158. }
  159.  
  160. function renderSnakeGame() {
  161. // Render the game as numbers
  162. let gameBoard = [];
  163.  
  164. for (let y = 0; y < 6; y++) {
  165. gameBoard.push([]);
  166. for (let x = 0; x < 14; x++) {
  167. gameBoard[y].push(0); // Initialize with 0 (empty space)
  168. }
  169. }
  170.  
  171. // Set snake segments
  172. for (const segment of snake) {
  173. const { x, y } = segment;
  174. gameBoard[y][x] = 1;
  175. }
  176.  
  177. // Set food position
  178. gameBoard[food.y][food.x] = 2;
  179.  
  180. return gameBoard.map(row => row.join(" ")).join("\n");
  181. }
  182.  
  183. // New maze game functions...
  184. const mazeRows = 6;
  185. const mazeColumns = 14;
  186. const wallChance = 0.3; // Adjust this value to control the density of walls in the maze
  187. let maze;
  188. let playerPosition;
  189. let previousPosition;
  190. let goalPosition;
  191.  
  192. function handleMazeCommand(command) {
  193. if (command === "play") {
  194. startMazeGame();
  195. } else if (command === "up" || command === "down" || command === "left" || command === "right") {
  196. movePlayer(command);
  197. } else {
  198. sendMsg("Invalid command. Use `" + prefix + "maze play` to start the game and `" + prefix + "maze up/down/left/right` to control.");
  199. }
  200. }
  201.  
  202. function startMazeGame() {
  203. // Generate a custom maze layout
  204. maze = generateRandomMaze();
  205. playerPosition = { x: Math.floor(mazeColumns / 2), y: mazeRows - 1 };
  206. maze[playerPosition.y][playerPosition.x] = 9;
  207. goalPosition = generateRandomGoalPosition();
  208. maze[goalPosition.y][goalPosition.x] = 3;
  209.  
  210. sendMsg(renderMaze());
  211. }
  212.  
  213. function generateRandomMaze() {
  214. // Generate a maze with random walls based on the wallChance
  215. const newMaze = [];
  216. for (let y = 0; y < mazeRows; y++) {
  217. const newRow = [];
  218. for (let x = 0; x < mazeColumns; x++) {
  219. newRow.push(Math.random() < wallChance ? 1 : 0);
  220. }
  221. newMaze.push(newRow);
  222. }
  223. return newMaze;
  224. }
  225.  
  226. function generateRandomGoalPosition() {
  227. // Generate a random goal position that is not occupied by a wall or player
  228. let x, y;
  229. do {
  230. x = Math.floor(Math.random() * mazeColumns);
  231. y = Math.floor(Math.random() * mazeRows);
  232. } while (maze[y][x] !== 0);
  233. return { x, y };
  234. }
  235.  
  236. function movePlayer(command) {
  237. const { x, y } = playerPosition;
  238. let newX = x;
  239. let newY = y;
  240.  
  241. if (command === "up") {
  242. newY = Math.max(0, y - 1);
  243. } else if (command === "down") {
  244. newY = Math.min(mazeRows - 1, y + 1);
  245. } else if (command === "left") {
  246. newX = Math.max(0, x - 1);
  247. } else if (command === "right") {
  248. newX = Math.min(mazeColumns - 1, x + 1);
  249. }
  250.  
  251. // Check if the new position is not a wall (1)
  252. if (maze[newY][newX] !== 1) {
  253. // Move the player to the new position
  254. previousPosition = { ...playerPosition };
  255. maze[y][x] = 0;
  256. maze[newY][newX] = 9;
  257. playerPosition = { x: newX, y: newY };
  258.  
  259. // Check if the player reached the goal
  260. if (newX === goalPosition.x && newY === goalPosition.y) {
  261. sendMsg("You reached the goal!\n");
  262. goalPosition = generateRandomGoalPosition();
  263. maze[goalPosition.y][goalPosition.x] = 3;
  264. } else {
  265. sendMsg(renderMaze());
  266. }
  267. } else {
  268. // Player cannot move to the new position (collision with a wall)
  269. sendMsg("You cannot move in that direction.\n" + renderMaze());
  270. }
  271.  
  272. // Check if the player is stuck in the maze
  273. const possibleMoves = ["up", "down", "left", "right"].filter(cmd => canMove(cmd));
  274. if (possibleMoves.length === 0) {
  275. // Player is stuck, move back to the previous position
  276. moveBackToPreviousPosition();
  277. }
  278. }
  279.  
  280. function canMove(command) {
  281. const { x, y } = playerPosition;
  282. let newX = x;
  283. let newY = y;
  284.  
  285. if (command === "up") {
  286. newY = Math.max(0, y - 1);
  287. } else if (command === "down") {
  288. newY = Math.min(mazeRows - 1, y + 1);
  289. } else if (command === "left") {
  290. newX = Math.max(0, x - 1);
  291. } else if (command === "right") {
  292. newX = Math.min(mazeColumns - 1, x + 1);
  293. }
  294.  
  295. return maze[newY][newX] !== 1;
  296. }
  297.  
  298. function moveBackToPreviousPosition() {
  299. // Move the player back to the previous position
  300. const { x, y } = previousPosition;
  301. maze[playerPosition.y][playerPosition.x] = 0;
  302. maze[y][x] = 9;
  303. playerPosition = { x, y };
  304.  
  305. sendMsg("You are stuck! Moving back to the previous position.\n" + renderMaze());
  306. }
  307.  
  308. function renderMaze() {
  309. // Render the maze as a formatted string with numbers
  310. let formattedMaze = "";
  311.  
  312. for (let y = 0; y < mazeRows; y++) {
  313. for (let x = 0; x < mazeColumns; x++) {
  314. formattedMaze += maze[y][x] + " ";
  315. }
  316. formattedMaze += "\n";
  317. }
  318.  
  319. return formattedMaze;
  320. }
Advertisement
Add Comment
Please, Sign In to add comment