Advertisement
nonogamer9

Project Memphis Source Code

Jul 30th, 2023 (edited)
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const prefix = "mem!";
  2. const botname = "Project Memphis: mem!start";
  3. const help = "__Project Memphis Start Menu.__\nweather, snake, maze, notepad, calculator, google, translate, clock";
  4. let notepads = [];
  5. let notepadCounter = 1;
  6. let notepadState = 'idle'; // Initial state
  7.  
  8. function sendMsg(msg) {
  9.     setTimeout(() => {
  10.          socket.emit("talk", msg);
  11.     }, 1100);
  12. }
  13.  
  14. // Emitting initial commands
  15. setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 1000);
  16. setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 2100);
  17. setTimeout(() => { socket.emit("command", { command: "color", param: "https://cdn.discordapp.com/attachments/731430123571642390/1247905229395984424/i-tools.png?ex=6661b9cf&is=6660684f&hm=b65c7ea572401a00ac121caccb75e6c65ebd67616a097d45fe2c4755244a6a17&" }) }, 3200);
  18. setTimeout(() => {
  19.     sendMsg("Start To Use Project Memphis By Saying " + prefix + "start");
  20.     setInterval(() => { sendMsg("Start To Use Project Memphis By Saying " + prefix + "start"); }, 60000);
  21. }, 4300);
  22.  
  23. // Handling incoming messages
  24. socket.on("talk", function (message) {
  25.     if (message.text === prefix + "start") {
  26.         sendMsg(help);
  27.     } else if (message.text.startsWith(prefix + "weather")) {
  28.         const location = message.text.substring(prefix.length + 8);
  29.         getWeather(location);
  30.     } else if (message.text.startsWith(prefix + "snake")) {
  31.         const command = message.text.substring(prefix.length + 6).trim();
  32.         handleSnakeCommand(command);
  33.     } else if (message.text.startsWith(prefix + "maze")) {
  34.         const command = message.text.substring(prefix.length + 5).trim();
  35.         handleMazeCommand(command);
  36.     } else if (message.text === prefix + "clock") {
  37.         sendMsg(getCurrentTime());
  38.     } else if (message.text.startsWith(prefix + "calculator")) {
  39.         const operation = message.text.substring(prefix.length + 11).trim();
  40.         calculator(operation);
  41.     } else if (message.text.startsWith(prefix + "notepad")) {
  42.         const command = message.text.substring(prefix.length + 7).trim();
  43.         handleNotepadCommand(command);
  44.     } else if (message.text.startsWith(prefix + "google")) {
  45.         const searchQuery = message.text.substring(prefix.length + 7);
  46.         googleSearch(searchQuery);
  47.     } else if (message.text.startsWith(prefix + "translate")) {
  48.         const translationQuery = message.text.substring(prefix.length + 10).trim();
  49.         translateText(translationQuery);
  50.     }
  51. });
  52.  
  53. function getCurrentTime() {
  54.     const now = new Date();
  55.     const timeString = now.toLocaleTimeString("en-US", { hour12: true });
  56.     return "Current time is: " + timeString;
  57. }
  58.  
  59. function handleSnakeCommand(command) {
  60.     if (command === "play") {
  61.         startSnakeGame();
  62.     } else if (command === "up" || command === "down" || command === "left" || command === "right") {
  63.         updateSnakeDirection(command);
  64.         moveSnake();
  65.         if (checkCollision()) {
  66.             sendMsg("Game Over. You collided with the wall or yourself!");
  67.             return;
  68.         }
  69.         checkFoodEaten();
  70.         sendMsg(renderSnakeGame());
  71.     } else {
  72.         sendMsg("Invalid command. Use `" + prefix + "snake play` to start the game and `" + prefix + "snake up/down/left/right` to control.");
  73.     }
  74. }
  75.  
  76. function getWeather(location) {
  77.     const apiKey = "dcc6b2a3fa3d4fe58d9193316232905";
  78.     const apiUrl = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${encodeURIComponent(location)}`;
  79.  
  80.     fetch(apiUrl)
  81.         .then((response) => response.json())
  82.         .then((data) => {
  83.             if (data.error) {
  84.                 sendMsg("Unable to retrieve weather information. Please check the location.");
  85.             } else {
  86.                 const weather = data.current;
  87.                 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`;
  88.                 sendMsg(weatherInfo);
  89.             }
  90.         })
  91.         .catch((error) => {
  92.             console.error("Error:", error);
  93.             sendMsg("An error occurred while retrieving weather information.");
  94.         });
  95. }
  96.  
  97. // New snake game functions...
  98. let snake = [{ x: 0, y: 0 }]; // Snake's initial position (assuming the top-left corner as [0, 0])
  99. let food = { x: 5, y: 5 }; // Food's initial position
  100. let direction = "right"; // Initial direction of the snake
  101.  
  102. function startSnakeGame() {
  103.     // Initialize the snake game state
  104.     snake = [{ x: 0, y: 0 }];
  105.     food = { x: 5, y: 5 };
  106.     direction = "right";
  107.  
  108.     sendMsg(renderSnakeGame());
  109. }
  110.  
  111. function updateSnakeDirection(command) {
  112.     // Update the snake's direction based on the command received
  113.     if (command === "up" && direction !== "down") {
  114.         direction = "up";
  115.     } else if (command === "down" && direction !== "up") {
  116.         direction = "down";
  117.     } else if (command === "left" && direction !== "right") {
  118.         direction = "left";
  119.     } else if (command === "right" && direction !== "left") {
  120.         direction = "right";
  121.     }
  122. }
  123.  
  124. function moveSnake() {
  125.     // Move the snake in the current direction
  126.     const head = { ...snake[0] };
  127.  
  128.     if (direction === "up") {
  129.         head.y--;
  130.     } else if (direction === "down") {
  131.         head.y++;
  132.     } else if (direction === "left") {
  133.         head.x--;
  134.     } else if (direction === "right") {
  135.         head.x++;
  136.     }
  137.  
  138.     // Add the new head to the snake
  139.     snake.unshift(head);
  140. }
  141.  
  142. function checkCollision() {
  143.     // Check if the snake collides with the game boundaries or itself
  144.     const head = snake[0];
  145.  
  146.     if (head.x < 0 || head.x >= 14 || head.y < 0 || head.y >= 6) {
  147.         return true; // Collision with the game boundaries
  148.     }
  149.  
  150.     for (let i = 1; i < snake.length; i++) {
  151.         if (snake[i].x === head.x && snake[i].y === head.y) {
  152.             return true; // Collision with itself
  153.         }
  154.     }
  155.  
  156.     return false;
  157. }
  158.  
  159. function checkFoodEaten() {
  160.     // Check if the snake eats the food
  161.     const head = snake[0];
  162.  
  163.     if (head.x === food.x && head.y === food.y) {
  164.         // Generate new food at a random position
  165.         food = {
  166.             x: Math.floor(Math.random() * 14),
  167.             y: Math.floor(Math.random() * 6)
  168.         };
  169.  
  170.         // Do not remove the tail, so the snake grows
  171.     } else {
  172.         // Remove the tail to maintain the snake's length
  173.         snake.pop();
  174.     }
  175. }
  176.  
  177. function renderSnakeGame() {
  178.     // Render the game as numbers
  179.     let gameBoard = [];
  180.  
  181.     for (let y = 0; y < 6; y++) {
  182.         gameBoard.push([]);
  183.         for (let x = 0; x < 14; x++) {
  184.             gameBoard[y].push(0); // Initialize with 0 (empty space)
  185.         }
  186.     }
  187.  
  188.     // Set snake segments
  189.     for (const segment of snake) {
  190.         const { x, y } = segment;
  191.         gameBoard[y][x] = 1;
  192.     }
  193.  
  194.     // Set food position
  195.     gameBoard[food.y][food.x] = 2;
  196.  
  197.     return gameBoard.map(row => row.join(" ")).join("\n");
  198. }
  199.  
  200. // New maze game functions...
  201. const mazeRows = 6;
  202. const mazeColumns = 14;
  203. const wallChance = 0.3; // Adjust this value to control the density of walls in the maze
  204. let maze;
  205. let playerPosition;
  206. let previousPosition;
  207. let goalPosition;
  208.  
  209. function handleMazeCommand(command) {
  210.     if (command === "play") {
  211.         startMazeGame();
  212.     } else if (command === "up" || command === "down" || command === "left" || command === "right") {
  213.         movePlayer(command);
  214.     } else if (command === "guide") {
  215.         sendMsg("Welcome to mem!maze!\n\n"
  216.           + "You are represented by the number 9, and your goal is to reach the number 3.\n"
  217.           + "Use `" + prefix + "maze up/down/left/right` to move in the maze.\n"
  218.           + "Good luck!");
  219.     } else {
  220.         sendMsg("Invalid command. Use `" + prefix + "maze play` to start the game, `" + prefix + "maze up/down/left/right` to control, or `" + prefix + "maze guide` for instructions.");
  221.     }
  222. }
  223.  
  224. function startMazeGame() {
  225.     // Generate a custom maze layout
  226.     maze = generateRandomMaze();
  227.     playerPosition = { x: Math.floor(mazeColumns / 2), y: mazeRows - 1 };
  228.     maze[playerPosition.y][playerPosition.x] = 9;
  229.     goalPosition = generateRandomGoalPosition();
  230.     maze[goalPosition.y][goalPosition.x] = 3;
  231.  
  232.     sendMsg(renderMaze());
  233. }
  234.  
  235. function generateRandomMaze() {
  236.     // Generate a maze with random walls based on the wallChance
  237.     const newMaze = [];
  238.     for (let y = 0; y < mazeRows; y++) {
  239.         const newRow = [];
  240.         for (let x = 0; x < mazeColumns; x++) {
  241.             newRow.push(Math.random() < wallChance ? 1 : 0);
  242.         }
  243.         newMaze.push(newRow);
  244.     }
  245.     return newMaze;
  246. }
  247.  
  248. function generateRandomGoalPosition() {
  249.     // Generate a random goal position that is not occupied by a wall or player
  250.     let x, y;
  251.     do {
  252.         x = Math.floor(Math.random() * mazeColumns);
  253.         y = Math.floor(Math.random() * mazeRows);
  254.     } while (maze[y][x] !== 0);
  255.     return { x, y };
  256. }
  257.  
  258. function movePlayer(command) {
  259.     const { x, y } = playerPosition;
  260.     let newX = x;
  261.     let newY = y;
  262.  
  263.     if (command === "up") {
  264.         newY = Math.max(0, y - 1);
  265.     } else if (command === "down") {
  266.         newY = Math.min(mazeRows - 1, y + 1);
  267.     } else if (command === "left") {
  268.         newX = Math.max(0, x - 1);
  269.     } else if (command === "right") {
  270.         newX = Math.min(mazeColumns - 1, x + 1);
  271.     }
  272.  
  273.     // Check if the new position is not a wall (1)
  274.     if (maze[newY][newX] !== 1) {
  275.         // Move the player to the new position
  276.         previousPosition = { ...playerPosition };
  277.         maze[y][x] = 0;
  278.         maze[newY][newX] = 9;
  279.         playerPosition = { x: newX, y: newY };
  280.  
  281.         // Check if the player reached the goal
  282.         if (newX === goalPosition.x && newY === goalPosition.y) {
  283.             sendMsg("You reached the goal!\n");
  284.             goalPosition = generateRandomGoalPosition();
  285.             maze[goalPosition.y][goalPosition.x] = 3;
  286.         } else {
  287.             sendMsg(renderMaze());
  288.         }
  289.     } else {
  290.         // Player cannot move to the new position (collision with a wall)
  291.         sendMsg("You cannot move in that direction.\n" + renderMaze());
  292.     }
  293.    
  294.     // Check if the player is stuck in the maze
  295.     const possibleMoves = ["up", "down", "left", "right"].filter(cmd => canMove(cmd));
  296.     if (possibleMoves.length === 0) {
  297.         // Player is stuck, move back to the previous position
  298.         moveBackToPreviousPosition();
  299.     }
  300. }
  301.  
  302. function canMove(command) {
  303.     const { x, y } = playerPosition;
  304.     let newX = x;
  305.     let newY = y;
  306.  
  307.     if (command === "up") {
  308.         newY = Math.max(0, y - 1);
  309.     } else if (command === "down") {
  310.         newY = Math.min(mazeRows - 1, y + 1);
  311.     } else if (command === "left") {
  312.         newX = Math.max(0, x - 1);
  313.     } else if (command === "right") {
  314.         newX = Math.min(mazeColumns - 1, x + 1);
  315.     }
  316.  
  317.     return maze[newY][newX] !== 1;
  318. }
  319.  
  320. function moveBackToPreviousPosition() {
  321.     // Move the player back to the previous position
  322.     const { x, y } = previousPosition;
  323.     maze[playerPosition.y][playerPosition.x] = 0;
  324.     maze[y][x] = 9;
  325.     playerPosition = { x, y };
  326.  
  327.     sendMsg("You are stuck! Moving back to the previous position.\n" + renderMaze());
  328. }
  329.  
  330. function renderMaze() {
  331.     // Render the maze as a formatted string with numbers
  332.     let formattedMaze = "";
  333.  
  334.     for (let y = 0; y < mazeRows; y++) {
  335.         for (let x = 0; x < mazeColumns; x++) {
  336.             formattedMaze += maze[y][x] + " ";
  337.         }
  338.         formattedMaze += "\n";
  339.     }
  340.  
  341.     return formattedMaze;
  342. }
  343.  
  344. function handleNotepadCommand(command) {
  345.     if (command.startsWith("create")) {
  346.         if (notepadState === 'idle') {
  347.             createNotepad();
  348.             notepadState = 'created';
  349.         } else {
  350.             sendMsg("A notepad is already in use. Please save or cancel the current notepad before creating a new one.");
  351.         }
  352.     } else if (command.startsWith("write")) {
  353.         if (notepadState === 'created' || notepadState === 'modified') {
  354.             const content = command.substring(6).trim();
  355.             writeOnNotepad(content);
  356.         } else {
  357.             sendMsg("No notepad in progress. Please create or modify a notepad before writing.");
  358.         }
  359.     } else if (command.startsWith("save")) {
  360.         if (notepadState === 'created' || notepadState === 'modified') {
  361.             saveNotepad();
  362.             notepadState = 'idle';
  363.         } else {
  364.             sendMsg("No notepad in progress. Please create or modify a notepad before saving.");
  365.         }
  366.     } else if (command.startsWith("list")) {
  367.         listNotepads();
  368.     } else if (command.startsWith("delete")) {
  369.         const notepadNumber = command.substring(7).trim();
  370.         deleteNotepad(notepadNumber);
  371.     } else if (command.startsWith("modify")) {
  372.         const notepadNumber = command.substring(7).trim();
  373.         if (notepadState === 'idle') {
  374.             modifyNotepad(notepadNumber);
  375.             notepadState = 'modified';
  376.         } else {
  377.             sendMsg("A notepad is already in use. Please save or cancel the current notepad before modifying another one.");
  378.         }
  379.     } else if (command.startsWith("read")) {
  380.         const notepadNumber = command.substring(5).trim();
  381.         readNotepad(notepadNumber);
  382.     } else {
  383.         sendMsg("Invalid command. Use `" + prefix + "notepad create` to create a notepad, `" + prefix + "notepad write` to write on the notepad, `" + prefix + "notepad save` to save the notepad, `" + prefix + "notepad delete` to delete a notepad, `" + prefix + "notepad list` to list all notepads, `" + prefix + "notepad modify` to modify a notepad, or `" + prefix + "notepad read` to read a notepad.");
  384.     }
  385. }
  386.  
  387. function createNotepad() {
  388.     const newNotepad = { id: notepadCounter, content: "", created: new Date() };
  389.     notepads.push(newNotepad);
  390.     notepadCounter++;
  391.     sendMsg("Notepad created. ID: " + (notepadCounter - 1));
  392. }
  393.  
  394. function writeOnNotepad(content) {
  395.     const currentNotepad = notepads[notepads.length - 1];
  396.     currentNotepad.content += content + "\n";
  397.     sendMsg("Content added to the notepad.");
  398. }
  399.  
  400. function saveNotepad() {
  401.     const currentNotepad = notepads[notepads.length - 1];
  402.     sendMsg("Notepad saved.");
  403.     // Save the notepad content to a database or file here
  404.     console.log(`Saved content on notepad ID: ${currentNotepad.id}: ${currentNotepad.content}`);
  405.     currentNotepad.content = ""; // Clear the current notepad content after saving
  406. }
  407.  
  408. function deleteNotepad(notepadNumber) {
  409.     const index = parseInt(notepadNumber, 10) - 1;
  410.     if (index >= 0 && index < notepads.length) {
  411.         notepads.splice(index, 1);
  412.         sendMsg("Notepad deleted.");
  413.     } else {
  414.         sendMsg("Notepad not found. Please provide a valid notepad number.");
  415.     }
  416. }
  417.  
  418. function listNotepads() {
  419.     if (notepads.length === 0) {
  420.         sendMsg("No notepads created yet.");
  421.     } else {
  422.         let notepadList = "";
  423.         notepads.forEach((notepad, index) => {
  424.             notepadList += `${index + 1} note created on ${notepad.created.toLocaleDateString()}\n`;
  425.         });
  426.         sendMsg(notepadList);
  427.     }
  428. }
  429.  
  430. function modifyNotepad(notepadNumber) {
  431.     const index = parseInt(notepadNumber, 10) - 1;
  432.     if (index >= 0 && index < notepads.length) {
  433.         const selectedNotepad = notepads[index];
  434.         notepads.pop(); // Remove the current notepad to edit
  435.         notepads.push(selectedNotepad);
  436.         sendMsg("Notepad opened for modification.");
  437.     } else {
  438.         sendMsg("Notepad not found. Please provide a valid notepad number.");
  439.     }
  440. }
  441.  
  442. function readNotepad(notepadNumber) {
  443.     const index = parseInt(notepadNumber, 10) - 1;
  444.     if (index >= 0 && index < notepads.length) {
  445.         const selectedNotepad = notepads[index];
  446.         if (selectedNotepad.content.trim() === "") {
  447.             sendMsg(`Notepad ID: ${selectedNotepad.id} is empty.`);
  448.         } else {
  449.             sendMsg(`Content on notepad ID: ${selectedNotepad.id}: ${selectedNotepad.content}`);
  450.         }
  451.     } else {
  452.         sendMsg("Notepad not found. Please provide a valid notepad number.");
  453.     }
  454. }
  455.  
  456. // New calculator function
  457. function calculator(operation) {
  458.     const parts = operation.split(" ");
  459.     const operator = parts[1];
  460.     const a = parseFloat(parts[0]);
  461.     const b = parseFloat(parts[2]);
  462.  
  463.     let result;
  464.     switch (operator) {
  465.         case "+":
  466.             result = a + b;
  467.             break;
  468.         case "-":
  469.             result = a - b;
  470.             break;
  471.         case "*":
  472.             result = a * b;
  473.             break;
  474.         case "/":
  475.             result = a / b;
  476.             break;
  477.         default:
  478.             sendMsg("Invalid operation. Please use the format: 'num1 operator num2'. Supported operators are +, -, *, /.");
  479.             return;
  480.     }
  481.  
  482.     sendMsg(`Result: ${result}`);
  483. }
  484.  
  485. function googleSearch(searchQuery) {
  486.     // Replace 'YOUR_API_KEY' with your actual Google Search API key
  487.     const apiKey = 'AIzaSyDQJ7SjasKcPq_bJhCyxuaoWiVydYTGDK0';
  488.     const cx = 'c3619c6476b78442f'; // Replace with your custom search engine ID
  489.     const apiUrl = `https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(searchQuery)}&key=${apiKey}&cx=${cx}`;
  490.  
  491.     const xhr = new XMLHttpRequest();
  492.     xhr.open('GET', apiUrl, true);
  493.  
  494.     xhr.onload = function () {
  495.         if (xhr.status >= 200 && xhr.status < 300) {
  496.             try {
  497.                 const response = JSON.parse(xhr.responseText);
  498.  
  499.                 if (response.items && response.items.length > 0) {
  500.                     // Limit the results to the first two items
  501.                     const limitedResults = response.items.slice(0, 2);
  502.                     const searchResultsText = limitedResults.map((item, index) => `${index + 1}. ${item.title}\n   ${item.link}`).join("\n");
  503.                     try {
  504.                         sendMsg(`Google Search Results for '${searchQuery}':\n${searchResultsText}`);
  505.                     } catch (error) {
  506.                         console.error("Error sending message:", error);
  507.                         sendMsg(`An error occurred while sending Google Search results: ${error.message}`);
  508.                     }
  509.                 } else {
  510.                     try {
  511.                         sendMsg(`No results found for '${searchQuery}'.`);
  512.                     } catch (error) {
  513.                         console.error("Error sending message:", error);
  514.                         sendMsg(`An error occurred while sending no results message: ${error.message}`);
  515.                     }
  516.                 }
  517.             } catch (error) {
  518.                 console.error("Error parsing Google Search API response:", error);
  519.                 try {
  520.                     sendMsg(`An error occurred while processing Google Search results: ${error.message}`);
  521.                 } catch (sendError) {
  522.                     console.error("Error sending message:", sendError);
  523.                     sendMsg(`An error occurred while sending error message: ${sendError.message}`);
  524.                 }
  525.             }
  526.         } else {
  527.             console.error("Error fetching Google Search API:", xhr.statusText);
  528.             sendMsg(`Error fetching Google Search API: ${xhr.status} (${xhr.statusText})`);
  529.         }
  530.     };
  531.  
  532.     xhr.onerror = function () {
  533.         console.error("Network error occurred while fetching Google Search API.");
  534.         try {
  535.             sendMsg("An error occurred while fetching Google Search results due to a network error.");
  536.         } catch (error) {
  537.             console.error("Error sending message:", error);
  538.             sendMsg(`An error occurred while sending network error message: ${error.message}`);
  539.         }
  540.     };
  541.  
  542.     xhr.send();
  543. }
  544.  
  545. function translateText(translationQuery) {
  546.     const languages = {
  547.         english: 'en',
  548.         french: 'fr',
  549.         japanese: 'ja',
  550.         spanish: 'es',
  551.         german: 'de',
  552.         chinese: 'zh',
  553.         russian: 'ru',
  554.         italian: 'it',
  555.         portuguese: 'pt',
  556.         dutch: 'nl',
  557.         korean: 'ko',
  558.         arabic: 'ar',
  559.         hindi: 'hi',
  560.         greek: 'el',
  561.         swedish: 'sv',
  562.         turkish: 'tr',
  563.         vietnamese: 'vi',
  564.         thai: 'th',
  565.         hebrew: 'he',
  566.         polish: 'pl',
  567.         danish: 'da',
  568.         finnish: 'fi',
  569.         norwegian: 'no',
  570.         czech: 'cs',
  571.         hungarian: 'hu',
  572.         indonesian: 'id',
  573.         malay: 'ms',
  574.         romanian: 'ro',
  575.         bulgarian: 'bg',
  576.         croatian: 'hr',
  577.         slovak: 'sk',
  578.         ukrainian: 'uk'
  579.     };
  580.  
  581.     if (translationQuery.trim().toLowerCase() === 'list languages') {
  582.         sendMsg("Supported languages are: " + Object.keys(languages).join(', ') + ".");
  583.         return;
  584.     }
  585.  
  586.     const [text, targetLanguage] = translationQuery.split(' to ');
  587.  
  588.     if (!text || !targetLanguage) {
  589.         sendMsg("Invalid format. Use `mem!translate <text> to <target language>`.");
  590.         return;
  591.     }
  592.  
  593.     const targetLangCode = languages[targetLanguage.trim().toLowerCase()];
  594.  
  595.     if (!targetLangCode) {
  596.         sendMsg("Invalid target language. Use `mem!translate list languages` to see supported languages.");
  597.         return;
  598.     }
  599.  
  600.     const apiUrl = 'https://deep-translate1.p.rapidapi.com/language/translate/v2';
  601.     const apiKey = '4a4725a769msh10c74bc91185a85p182f25jsn9a1a93fbbb77';
  602.  
  603.     const data = {
  604.         q: text.trim(),
  605.         target: targetLangCode
  606.     };
  607.  
  608.     fetch(apiUrl, {
  609.         method: 'POST',
  610.         headers: {
  611.             'Content-Type': 'application/json',
  612.             'X-RapidAPI-Host': 'deep-translate1.p.rapidapi.com',
  613.             'X-RapidAPI-Key': apiKey
  614.         },
  615.         body: JSON.stringify(data)
  616.     })
  617.     .then(response => response.json())
  618.     .then(data => {
  619.         if (data.data && data.data.translations) {
  620.             sendMsg(`Translation: ${data.data.translations.translatedText}`);
  621.         } else {
  622.             sendMsg("Translation error. Please check the input and target language.");
  623.         }
  624.     })
  625.     .catch(error => {
  626.         console.error("Error:", error);
  627.         sendMsg("An error occurred while translating the text.");
  628.     });
  629. }
  630.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement