Advertisement
nonogamer9

GensokyoRadio BOT source code

Jan 22nd, 2024 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const prefix = "gr!";
  2. const botname = "GensokyoRadioBOT (" + prefix + "help)";
  3. const version = "1.0";
  4. var help = "- __GensokyoRadioBOT Commands__\ngr!help, gr!genradio1, gr!genradio2, gr!genradio3, gr!radioskyrock gr!radiomaritima, gr!radioBBN, gr!snake"
  5. var botinfo = "GensokyoRadioBOT " + version + ". Find GensokyoRadioBOT at: https://pastebin.com/unfdr1YZ";
  6.  
  7. function sendMsg(msg) {
  8.     setTimeout(() => {
  9.          socket.emit("talk", msg);
  10.     }, 1100);
  11. }
  12.  
  13. setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 1000);
  14. setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 2100);
  15. setTimeout(() => { socket.emit("command", { command: "color", param: "https://cdn.discordapp.com/attachments/1177634999873314878/1198925870404997150/i-tools.png" }) }, 3200);
  16. setTimeout(() => {
  17.     sendMsg("GensokyoRadioBOT is online. Type " + prefix + "help To See Commands.");
  18. }, 4300);
  19.  
  20. socket.on("talk", (message) => {
  21.     if (message.text == prefix + "botinfo") {
  22.         sendMsg(botinfo);
  23.     }
  24.     if (message.text == prefix + "help") {
  25.         sendMsg(help);
  26.     }
  27.     // Handling specific radio commands
  28.     if (message.text.startsWith(prefix + "genradio3")) {
  29.         const imgUrl = message.text.substring(prefix.length + 10);
  30.         setTimeout(() => { socket.emit("command", { command: "video", param: "https://stream.gensokyoradio.net/3" }) }, 1100);
  31.     }
  32.     if (message.text.startsWith(prefix + "genradio2")) {
  33.         const imgUrl = message.text.substring(prefix.length + 10);
  34.         setTimeout(() => { socket.emit("command", { command: "video", param: "https://stream.gensokyoradio.net/2" }) }, 1100);
  35.     }
  36.     if (message.text.startsWith(prefix + "genradio1")) {
  37.         const imgUrl = message.text.substring(prefix.length + 10);
  38.         setTimeout(() => { socket.emit("command", { command: "video", param: "https://stream.gensokyoradio.net/1" }) }, 1100);
  39.     }
  40.     if (message.text.startsWith(prefix + "radioskyrock")) {
  41.         const imgUrl = message.text.substring(prefix.length + 12);
  42.         setTimeout(() => { socket.emit("command", { command: "video", param: "https://icecast.skyrock.net/s/marseille_aac_96k" }) }, 1100);
  43.     }
  44.     if (message.text.startsWith(prefix + "radiomaritima")) {
  45.         const imgUrl = message.text.substring(prefix.length + 14);
  46.         setTimeout(() => { socket.emit("command", { command: "video", param: "https://maritima1072.ice.infomaniak.ch/maritima1072-128.mp3" }) }, 1100);
  47.     }
  48.     if (message.text.startsWith(prefix + "radioBBN")) {
  49.         const imgUrl = message.text.substring(prefix.length + 9);
  50.         setTimeout(() => { socket.emit("command", { command: "video", param: "https://audio-edge-ey5nr.ams.s.radiomast.io/a622d414-52a6-4426-b3b8-ed2a4dbb704b" }) }, 1100);
  51.     }
  52.     if (message.text.startsWith(prefix + "snake")) {
  53.         const command = message.text.substring(prefix.length + 6).trim();
  54.         handleSnakeCommand(command);
  55.     }
  56. });
  57.  
  58. function getCurrentTime() {
  59.     const now = new Date();
  60.     const timeString = now.toLocaleTimeString("en-US", { hour12: true });
  61.     return "Current time is: " + timeString;
  62. }
  63.  
  64. function handleSnakeCommand(command) {
  65.     if (command === "play") {
  66.         startSnakeGame();
  67.     } else if (command === "up" || command === "down" || command === "left" || command === "right") {
  68.         updateSnakeDirection(command);
  69.         moveSnake();
  70.         if (checkCollision()) {
  71.             sendMsg("Game Over. You collided with the wall or yourself!");
  72.             return;
  73.         }
  74.         checkFoodEaten();
  75.         sendMsg(renderSnakeGame());
  76.     } else {
  77.         sendMsg("Invalid command. Use `" + prefix + "snake play` to start the game and `" + prefix + "snake up/down/left/right` to control.");
  78.     }
  79. }
  80.  
  81. // New snake game functions...
  82. let snake = [{ x: 0, y: 0 }]; // Snake's initial position (assuming the top-left corner as [0, 0])
  83. let food = { x: 5, y: 5 }; // Food's initial position
  84. let direction = "right"; // Initial direction of the snake
  85.  
  86. function startSnakeGame() {
  87.     // Initialize the snake game state
  88.     snake = [{ x: 0, y: 0 }];
  89.     food = { x: 5, y: 5 };
  90.     direction = "right";
  91.  
  92.     sendMsg(renderSnakeGame());
  93. }
  94.  
  95. function updateSnakeDirection(command) {
  96.     // Update the snake's direction based on the command received
  97.     if (command === "up" && direction !== "down") {
  98.         direction = "up";
  99.     } else if (command === "down" && direction !== "up") {
  100.         direction = "down";
  101.     } else if (command === "left" && direction !== "right") {
  102.         direction = "left";
  103.     } else if (command === "right" && direction !== "left") {
  104.         direction = "right";
  105.     }
  106. }
  107.  
  108. function moveSnake() {
  109.     // Move the snake in the current direction
  110.     const head = { ...snake[0] };
  111.  
  112.     if (direction === "up") {
  113.         head.y--;
  114.     } else if (direction === "down") {
  115.         head.y++;
  116.     } else if (direction === "left") {
  117.         head.x--;
  118.     } else if (direction === "right") {
  119.         head.x++;
  120.     }
  121.  
  122.     // Add the new head to the snake
  123.     snake.unshift(head);
  124. }
  125.  
  126. function checkCollision() {
  127.     // Check if the snake collides with the game boundaries or itself
  128.     const head = snake[0];
  129.  
  130.     if (head.x < 0 || head.x >= 14 || head.y < 0 || head.y >= 6) {
  131.         return true; // Collision with the game boundaries
  132.     }
  133.  
  134.     for (let i = 1; i < snake.length; i++) {
  135.         if (snake[i].x === head.x && snake[i].y === head.y) {
  136.             return true; // Collision with itself
  137.         }
  138.     }
  139.  
  140.     return false;
  141. }
  142.  
  143. function checkFoodEaten() {
  144.     // Check if the snake eats the food
  145.     const head = snake[0];
  146.  
  147.     if (head.x === food.x && head.y === food.y) {
  148.         // Generate new food at a random position
  149.         food = {
  150.             x: Math.floor(Math.random() * 14),
  151.             y: Math.floor(Math.random() * 6)
  152.         };
  153.  
  154.         // Do not remove the tail, so the snake grows
  155.     } else {
  156.         // Remove the tail to maintain the snake's length
  157.         snake.pop();
  158.     }
  159. }
  160.  
  161. function renderSnakeGame() {
  162.     // Render the game as numbers
  163.     let gameBoard = [];
  164.  
  165.     for (let y = 0; y < 6; y++) {
  166.         gameBoard.push([]);
  167.         for (let x = 0; x < 14; x++) {
  168.             gameBoard[y].push(0); // Initialize with 0 (empty space)
  169.         }
  170.     }
  171.  
  172.     // Set snake segments
  173.     for (const segment of snake) {
  174.         const { x, y } = segment;
  175.         gameBoard[y][x] = 1;
  176.     }
  177.  
  178.     // Set food position
  179.     gameBoard[food.y][food.x] = 2;
  180.  
  181.     return gameBoard.map(row => row.join(" ")).join("\n");
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement