Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const prefix = "wsst!";
- const botname = "wsst Memphis: wsst!start";
- const help = "__wsst Memphis Start Menu.__\nweather, snake, maze, clock";
- function sendMsg(msg) {
- setTimeout(() => {
- socket.emit("talk", { text: msg });
- }, 1100);
- }
- setTimeout(() => { socket.emit("command", { list: ["name", "wsst Memphis: wsst!start"] }) }, 1000);
- setTimeout(() => { socket.emit("command", { list: ["name", "wsst Memphis: wsst!start"] }) }, 2100);
- setTimeout(() => { socket.emit("command",{list:["color","https://cdn.discordapp.com/attachments/1147262661281714269/1154779698874810378/scarypeedy.png"]}) }, 3200);
- setTimeout(() => {
- sendMsg("Start To Use wsst By Saying " + prefix + "start");
- setInterval(() => { sendMsg("Start To Use wsst Memphis By Saying " + prefix + "start, if you're bored do wsst!snake play!"); }, 60000);
- }, 4300);
- 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());
- }
- });
- 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 {
- sendMsg("Invalid command. Use `" + prefix + "maze play` to start the game and `" + prefix + "maze up/down/left/right` to control.");
- }
- }
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment