Advertisement
nonogamer9

Project Memphis Legacy Source Code

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