Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const prefix = "mem!";
- const botname = "Project Memphis: mem!start";
- const help = "__Project Memphis Start Menu.__\nweather, snake, maze, notepad, calculator, google, translate, clock";
- let notepads = [];
- let notepadCounter = 1;
- let notepadState = 'idle'; // Initial state
- function sendMsg(msg){
- setTimeout(() => {
- socket.emit("talk",{text: msg});
- },1100);
- }
- // Emitting initial commands
- setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 1000);
- setTimeout(() => { socket.emit("command", { command: "name", param: botname }) }, 2100);
- setTimeout(() => { socket.emit("command", { command: "color", param: "https://cdn.discordapp.com/attachments/731430123571642390/1247905229395984424/i-tools.png?ex=6661b9cf&is=6660684f&hm=b65c7ea572401a00ac121caccb75e6c65ebd67616a097d45fe2c4755244a6a17&" }) }, 3200);
- setTimeout(() => {
- sendMsg("Start To Use Project Memphis By Saying " + prefix + "start");
- setInterval(() => { sendMsg("Start To Use Project Memphis By Saying " + prefix + "start"); }, 60000);
- }, 4300);
- // Handling incoming messages
- socket.on("talk", function (message) {
- if (message.text === prefix + "start") {
- sendMsg(help);
- } else if (message.text.startsWith(prefix + "weather")) {
- const location = message.text.substring(prefix.length + 8);
- getWeather(location);
- } else if (message.text.startsWith(prefix + "snake")) {
- const command = message.text.substring(prefix.length + 6).trim();
- handleSnakeCommand(command);
- } else if (message.text.startsWith(prefix + "maze")) {
- const command = message.text.substring(prefix.length + 5).trim();
- handleMazeCommand(command);
- } else if (message.text === prefix + "clock") {
- sendMsg(getCurrentTime());
- } else if (message.text.startsWith(prefix + "calculator")) {
- const operation = message.text.substring(prefix.length + 11).trim();
- calculator(operation);
- } else if (message.text.startsWith(prefix + "notepad")) {
- const command = message.text.substring(prefix.length + 7).trim();
- handleNotepadCommand(command);
- } else if (message.text.startsWith(prefix + "google")) {
- const searchQuery = message.text.substring(prefix.length + 7);
- googleSearch(searchQuery);
- } else if (message.text.startsWith(prefix + "translate")) {
- const translationQuery = message.text.substring(prefix.length + 10).trim();
- translateText(translationQuery);
- }
- });
- function getCurrentTime() {
- const now = new Date();
- const timeString = now.toLocaleTimeString("en-US", { hour12: true });
- return "Current time is: " + timeString;
- }
- function handleSnakeCommand(command) {
- if (command === "play") {
- startSnakeGame();
- } else if (command === "up" || command === "down" || command === "left" || command === "right") {
- updateSnakeDirection(command);
- moveSnake();
- if (checkCollision()) {
- sendMsg("Game Over. You collided with the wall or yourself!");
- return;
- }
- checkFoodEaten();
- sendMsg(renderSnakeGame());
- } else {
- sendMsg("Invalid command. Use `" + prefix + "snake play` to start the game and `" + prefix + "snake up/down/left/right` to control.");
- }
- }
- function getWeather(location) {
- const apiKey = "dcc6b2a3fa3d4fe58d9193316232905";
- const apiUrl = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${encodeURIComponent(location)}`;
- fetch(apiUrl)
- .then((response) => response.json())
- .then((data) => {
- if (data.error) {
- sendMsg("Unable to retrieve weather information. Please check the location.");
- } else {
- const weather = data.current;
- 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`;
- sendMsg(weatherInfo);
- }
- })
- .catch((error) => {
- console.error("Error:", error);
- sendMsg("An error occurred while retrieving weather information.");
- });
- }
- // New snake game functions...
- let snake = [{ x: 0, y: 0 }]; // Snake's initial position (assuming the top-left corner as [0, 0])
- let food = { x: 5, y: 5 }; // Food's initial position
- let direction = "right"; // Initial direction of the snake
- function startSnakeGame() {
- // Initialize the snake game state
- snake = [{ x: 0, y: 0 }];
- food = { x: 5, y: 5 };
- direction = "right";
- sendMsg(renderSnakeGame());
- }
- function updateSnakeDirection(command) {
- // Update the snake's direction based on the command received
- if (command === "up" && direction !== "down") {
- direction = "up";
- } else if (command === "down" && direction !== "up") {
- direction = "down";
- } else if (command === "left" && direction !== "right") {
- direction = "left";
- } else if (command === "right" && direction !== "left") {
- direction = "right";
- }
- }
- function moveSnake() {
- // Move the snake in the current direction
- const head = { ...snake[0] };
- if (direction === "up") {
- head.y--;
- } else if (direction === "down") {
- head.y++;
- } else if (direction === "left") {
- head.x--;
- } else if (direction === "right") {
- head.x++;
- }
- // Add the new head to the snake
- snake.unshift(head);
- }
- function checkCollision() {
- // Check if the snake collides with the game boundaries or itself
- const head = snake[0];
- if (head.x < 0 || head.x >= 14 || head.y < 0 || head.y >= 6) {
- return true; // Collision with the game boundaries
- }
- for (let i = 1; i < snake.length; i++) {
- if (snake[i].x === head.x && snake[i].y === head.y) {
- return true; // Collision with itself
- }
- }
- return false;
- }
- function checkFoodEaten() {
- // Check if the snake eats the food
- const head = snake[0];
- if (head.x === food.x && head.y === food.y) {
- // Generate new food at a random position
- food = {
- x: Math.floor(Math.random() * 14),
- y: Math.floor(Math.random() * 6)
- };
- // Do not remove the tail, so the snake grows
- } else {
- // Remove the tail to maintain the snake's length
- snake.pop();
- }
- }
- function renderSnakeGame() {
- // Render the game as numbers
- let gameBoard = [];
- for (let y = 0; y < 6; y++) {
- gameBoard.push([]);
- for (let x = 0; x < 14; x++) {
- gameBoard[y].push(0); // Initialize with 0 (empty space)
- }
- }
- // Set snake segments
- for (const segment of snake) {
- const { x, y } = segment;
- gameBoard[y][x] = 1;
- }
- // Set food position
- gameBoard[food.y][food.x] = 2;
- return gameBoard.map(row => row.join(" ")).join("\n");
- }
- // New maze game functions...
- const mazeRows = 6;
- const mazeColumns = 14;
- const wallChance = 0.3; // Adjust this value to control the density of walls in the maze
- let maze;
- let playerPosition;
- let previousPosition;
- let goalPosition;
- function handleMazeCommand(command) {
- if (command === "play") {
- startMazeGame();
- } else if (command === "up" || command === "down" || command === "left" || command === "right") {
- movePlayer(command);
- } else if (command === "guide") {
- sendMsg("Welcome to mem!maze!\n\n"
- + "You are represented by the number 9, and your goal is to reach the number 3.\n"
- + "Use `" + prefix + "maze up/down/left/right` to move in the maze.\n"
- + "Good luck!");
- } else {
- 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.");
- }
- }
- function startMazeGame() {
- // Generate a custom maze layout
- maze = generateRandomMaze();
- playerPosition = { x: Math.floor(mazeColumns / 2), y: mazeRows - 1 };
- maze[playerPosition.y][playerPosition.x] = 9;
- goalPosition = generateRandomGoalPosition();
- maze[goalPosition.y][goalPosition.x] = 3;
- sendMsg(renderMaze());
- }
- function generateRandomMaze() {
- // Generate a maze with random walls based on the wallChance
- const newMaze = [];
- for (let y = 0; y < mazeRows; y++) {
- const newRow = [];
- for (let x = 0; x < mazeColumns; x++) {
- newRow.push(Math.random() < wallChance ? 1 : 0);
- }
- newMaze.push(newRow);
- }
- return newMaze;
- }
- function generateRandomGoalPosition() {
- // Generate a random goal position that is not occupied by a wall or player
- let x, y;
- do {
- x = Math.floor(Math.random() * mazeColumns);
- y = Math.floor(Math.random() * mazeRows);
- } while (maze[y][x] !== 0);
- return { x, y };
- }
- function movePlayer(command) {
- const { x, y } = playerPosition;
- let newX = x;
- let newY = y;
- if (command === "up") {
- newY = Math.max(0, y - 1);
- } else if (command === "down") {
- newY = Math.min(mazeRows - 1, y + 1);
- } else if (command === "left") {
- newX = Math.max(0, x - 1);
- } else if (command === "right") {
- newX = Math.min(mazeColumns - 1, x + 1);
- }
- // Check if the new position is not a wall (1)
- if (maze[newY][newX] !== 1) {
- // Move the player to the new position
- previousPosition = { ...playerPosition };
- maze[y][x] = 0;
- maze[newY][newX] = 9;
- playerPosition = { x: newX, y: newY };
- // Check if the player reached the goal
- if (newX === goalPosition.x && newY === goalPosition.y) {
- sendMsg("You reached the goal!\n");
- goalPosition = generateRandomGoalPosition();
- maze[goalPosition.y][goalPosition.x] = 3;
- } else {
- sendMsg(renderMaze());
- }
- } else {
- // Player cannot move to the new position (collision with a wall)
- sendMsg("You cannot move in that direction.\n" + renderMaze());
- }
- // Check if the player is stuck in the maze
- const possibleMoves = ["up", "down", "left", "right"].filter(cmd => canMove(cmd));
- if (possibleMoves.length === 0) {
- // Player is stuck, move back to the previous position
- moveBackToPreviousPosition();
- }
- }
- function canMove(command) {
- const { x, y } = playerPosition;
- let newX = x;
- let newY = y;
- if (command === "up") {
- newY = Math.max(0, y - 1);
- } else if (command === "down") {
- newY = Math.min(mazeRows - 1, y + 1);
- } else if (command === "left") {
- newX = Math.max(0, x - 1);
- } else if (command === "right") {
- newX = Math.min(mazeColumns - 1, x + 1);
- }
- return maze[newY][newX] !== 1;
- }
- function moveBackToPreviousPosition() {
- // Move the player back to the previous position
- const { x, y } = previousPosition;
- maze[playerPosition.y][playerPosition.x] = 0;
- maze[y][x] = 9;
- playerPosition = { x, y };
- sendMsg("You are stuck! Moving back to the previous position.\n" + renderMaze());
- }
- function renderMaze() {
- // Render the maze as a formatted string with numbers
- let formattedMaze = "";
- for (let y = 0; y < mazeRows; y++) {
- for (let x = 0; x < mazeColumns; x++) {
- formattedMaze += maze[y][x] + " ";
- }
- formattedMaze += "\n";
- }
- return formattedMaze;
- }
- function handleNotepadCommand(command) {
- if (command.startsWith("create")) {
- if (notepadState === 'idle') {
- createNotepad();
- notepadState = 'created';
- } else {
- sendMsg("A notepad is already in use. Please save or cancel the current notepad before creating a new one.");
- }
- } else if (command.startsWith("write")) {
- if (notepadState === 'created' || notepadState === 'modified') {
- const content = command.substring(6).trim();
- writeOnNotepad(content);
- } else {
- sendMsg("No notepad in progress. Please create or modify a notepad before writing.");
- }
- } else if (command.startsWith("save")) {
- if (notepadState === 'created' || notepadState === 'modified') {
- saveNotepad();
- notepadState = 'idle';
- } else {
- sendMsg("No notepad in progress. Please create or modify a notepad before saving.");
- }
- } else if (command.startsWith("list")) {
- listNotepads();
- } else if (command.startsWith("delete")) {
- const notepadNumber = command.substring(7).trim();
- deleteNotepad(notepadNumber);
- } else if (command.startsWith("modify")) {
- const notepadNumber = command.substring(7).trim();
- if (notepadState === 'idle') {
- modifyNotepad(notepadNumber);
- notepadState = 'modified';
- } else {
- sendMsg("A notepad is already in use. Please save or cancel the current notepad before modifying another one.");
- }
- } else if (command.startsWith("read")) {
- const notepadNumber = command.substring(5).trim();
- readNotepad(notepadNumber);
- } else {
- 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.");
- }
- }
- function createNotepad() {
- const newNotepad = { id: notepadCounter, content: "", created: new Date() };
- notepads.push(newNotepad);
- notepadCounter++;
- sendMsg("Notepad created. ID: " + (notepadCounter - 1));
- }
- function writeOnNotepad(content) {
- const currentNotepad = notepads[notepads.length - 1];
- currentNotepad.content += content + "\n";
- sendMsg("Content added to the notepad.");
- }
- function saveNotepad() {
- const currentNotepad = notepads[notepads.length - 1];
- sendMsg("Notepad saved.");
- // Save the notepad content to a database or file here
- console.log(`Saved content on notepad ID: ${currentNotepad.id}: ${currentNotepad.content}`);
- currentNotepad.content = ""; // Clear the current notepad content after saving
- }
- function deleteNotepad(notepadNumber) {
- const index = parseInt(notepadNumber, 10) - 1;
- if (index >= 0 && index < notepads.length) {
- notepads.splice(index, 1);
- sendMsg("Notepad deleted.");
- } else {
- sendMsg("Notepad not found. Please provide a valid notepad number.");
- }
- }
- function listNotepads() {
- if (notepads.length === 0) {
- sendMsg("No notepads created yet.");
- } else {
- let notepadList = "";
- notepads.forEach((notepad, index) => {
- notepadList += `${index + 1} note created on ${notepad.created.toLocaleDateString()}\n`;
- });
- sendMsg(notepadList);
- }
- }
- function modifyNotepad(notepadNumber) {
- const index = parseInt(notepadNumber, 10) - 1;
- if (index >= 0 && index < notepads.length) {
- const selectedNotepad = notepads[index];
- notepads.pop(); // Remove the current notepad to edit
- notepads.push(selectedNotepad);
- sendMsg("Notepad opened for modification.");
- } else {
- sendMsg("Notepad not found. Please provide a valid notepad number.");
- }
- }
- function readNotepad(notepadNumber) {
- const index = parseInt(notepadNumber, 10) - 1;
- if (index >= 0 && index < notepads.length) {
- const selectedNotepad = notepads[index];
- if (selectedNotepad.content.trim() === "") {
- sendMsg(`Notepad ID: ${selectedNotepad.id} is empty.`);
- } else {
- sendMsg(`Content on notepad ID: ${selectedNotepad.id}: ${selectedNotepad.content}`);
- }
- } else {
- sendMsg("Notepad not found. Please provide a valid notepad number.");
- }
- }
- // New calculator function
- function calculator(operation) {
- const parts = operation.split(" ");
- const operator = parts[1];
- const a = parseFloat(parts[0]);
- const b = parseFloat(parts[2]);
- let result;
- switch (operator) {
- case "+":
- result = a + b;
- break;
- case "-":
- result = a - b;
- break;
- case "*":
- result = a * b;
- break;
- case "/":
- result = a / b;
- break;
- default:
- sendMsg("Invalid operation. Please use the format: 'num1 operator num2'. Supported operators are +, -, *, /.");
- return;
- }
- sendMsg(`Result: ${result}`);
- }
- function googleSearch(searchQuery) {
- // Replace 'YOUR_API_KEY' with your actual Google Search API key
- const apiKey = 'AIzaSyDQJ7SjasKcPq_bJhCyxuaoWiVydYTGDK0';
- const cx = 'c3619c6476b78442f'; // Replace with your custom search engine ID
- const apiUrl = `https://www.googleapis.com/customsearch/v1?q=${encodeURIComponent(searchQuery)}&key=${apiKey}&cx=${cx}`;
- const xhr = new XMLHttpRequest();
- xhr.open('GET', apiUrl, true);
- xhr.onload = function () {
- if (xhr.status >= 200 && xhr.status < 300) {
- try {
- const response = JSON.parse(xhr.responseText);
- if (response.items && response.items.length > 0) {
- // Limit the results to the first two items
- const limitedResults = response.items.slice(0, 2);
- const searchResultsText = limitedResults.map((item, index) => `${index + 1}. ${item.title}\n ${item.link}`).join("\n");
- try {
- sendMsg(`Google Search Results for '${searchQuery}':\n${searchResultsText}`);
- } catch (error) {
- console.error("Error sending message:", error);
- sendMsg(`An error occurred while sending Google Search results: ${error.message}`);
- }
- } else {
- try {
- sendMsg(`No results found for '${searchQuery}'.`);
- } catch (error) {
- console.error("Error sending message:", error);
- sendMsg(`An error occurred while sending no results message: ${error.message}`);
- }
- }
- } catch (error) {
- console.error("Error parsing Google Search API response:", error);
- try {
- sendMsg(`An error occurred while processing Google Search results: ${error.message}`);
- } catch (sendError) {
- console.error("Error sending message:", sendError);
- sendMsg(`An error occurred while sending error message: ${sendError.message}`);
- }
- }
- } else {
- console.error("Error fetching Google Search API:", xhr.statusText);
- sendMsg(`Error fetching Google Search API: ${xhr.status} (${xhr.statusText})`);
- }
- };
- xhr.onerror = function () {
- console.error("Network error occurred while fetching Google Search API.");
- try {
- sendMsg("An error occurred while fetching Google Search results due to a network error.");
- } catch (error) {
- console.error("Error sending message:", error);
- sendMsg(`An error occurred while sending network error message: ${error.message}`);
- }
- };
- xhr.send();
- }
- function translateText(translationQuery) {
- const languages = {
- english: 'en',
- french: 'fr',
- japanese: 'ja',
- spanish: 'es',
- german: 'de',
- chinese: 'zh',
- russian: 'ru',
- italian: 'it',
- portuguese: 'pt',
- dutch: 'nl',
- korean: 'ko',
- arabic: 'ar',
- hindi: 'hi',
- greek: 'el',
- swedish: 'sv',
- turkish: 'tr',
- vietnamese: 'vi',
- thai: 'th',
- hebrew: 'he',
- polish: 'pl',
- danish: 'da',
- finnish: 'fi',
- norwegian: 'no',
- czech: 'cs',
- hungarian: 'hu',
- indonesian: 'id',
- malay: 'ms',
- romanian: 'ro',
- bulgarian: 'bg',
- croatian: 'hr',
- slovak: 'sk',
- ukrainian: 'uk'
- };
- if (translationQuery.trim().toLowerCase() === 'list languages') {
- sendMsg("Supported languages are: " + Object.keys(languages).join(', ') + ".");
- return;
- }
- const [text, targetLanguage] = translationQuery.split(' to ');
- if (!text || !targetLanguage) {
- sendMsg("Invalid format. Use `mem!translate <text> to <target language>`.");
- return;
- }
- const targetLangCode = languages[targetLanguage.trim().toLowerCase()];
- if (!targetLangCode) {
- sendMsg("Invalid target language. Use `mem!translate list languages` to see supported languages.");
- return;
- }
- const apiUrl = 'https://deep-translate1.p.rapidapi.com/language/translate/v2';
- const apiKey = '4a4725a769msh10c74bc91185a85p182f25jsn9a1a93fbbb77';
- const data = {
- q: text.trim(),
- target: targetLangCode
- };
- fetch(apiUrl, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'X-RapidAPI-Host': 'deep-translate1.p.rapidapi.com',
- 'X-RapidAPI-Key': apiKey
- },
- body: JSON.stringify(data)
- })
- .then(response => response.json())
- .then(data => {
- if (data.data && data.data.translations) {
- sendMsg(`Translation: ${data.data.translations.translatedText}`);
- } else {
- sendMsg("Translation error. Please check the input and target language.");
- }
- })
- .catch(error => {
- console.error("Error:", error);
- sendMsg("An error occurred while translating the text.");
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement