Spaces:
Paused
Paused
Frank Kaumba
commited on
Update plugins
Browse files- plugins/hangman.js +87 -0
plugins/hangman.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cmd({
|
| 2 |
+
pattern: "hangman",
|
| 3 |
+
react: "🛸",
|
| 4 |
+
alias: ["hm"],
|
| 5 |
+
desc: "Play a game of Hangman",
|
| 6 |
+
category: "games",
|
| 7 |
+
filename: __filename
|
| 8 |
+
}, async (conn, mek, m, {
|
| 9 |
+
from,
|
| 10 |
+
quoted,
|
| 11 |
+
body,
|
| 12 |
+
isCmd,
|
| 13 |
+
command,
|
| 14 |
+
args,
|
| 15 |
+
q,
|
| 16 |
+
isGroup,
|
| 17 |
+
sender,
|
| 18 |
+
senderNumber,
|
| 19 |
+
botNumber2,
|
| 20 |
+
botNumber,
|
| 21 |
+
pushname,
|
| 22 |
+
isMe,
|
| 23 |
+
isOwner,
|
| 24 |
+
groupMetadata,
|
| 25 |
+
groupName,
|
| 26 |
+
participants,
|
| 27 |
+
groupAdmins,
|
| 28 |
+
isBotAdmins,
|
| 29 |
+
isAdmins,
|
| 30 |
+
reply
|
| 31 |
+
}) => {
|
| 32 |
+
try {
|
| 33 |
+
const words = [
|
| 34 |
+
"apple", "banana", "cherry", "date", "elderberry",
|
| 35 |
+
"facebook", "google", "instagram", "youtube", "twitter",
|
| 36 |
+
"javascript", "python", "java", "c++", "ruby",
|
| 37 |
+
"america", "canada", "mexico", "england", "france",
|
| 38 |
+
"applewatch", "samsung", "googlepixel", "oneplus", "huawei"
|
| 39 |
+
];
|
| 40 |
+
const word = words[Math.floor(Math.random() * words.length)];
|
| 41 |
+
const guesses = 6;
|
| 42 |
+
let guessedWord = Array(word.length).fill("_");
|
| 43 |
+
let guessedLetters = [];
|
| 44 |
+
|
| 45 |
+
reply(`Let's play Hangman! I'm thinking of a word that is ${word.length} letters long. You have ${guesses} guesses.\n\n${guessedWord.join(" ")}`);
|
| 46 |
+
|
| 47 |
+
const hangmanGame = async (guess) => {
|
| 48 |
+
if (guessedLetters.includes(guess)) {
|
| 49 |
+
reply("You already guessed that letter!");
|
| 50 |
+
return;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
guessedLetters.push(guess);
|
| 54 |
+
|
| 55 |
+
let correctGuess = false;
|
| 56 |
+
for (let i = 0; i < word.length; i++) {
|
| 57 |
+
if (word[i] === guess) {
|
| 58 |
+
guessedWord[i] = guess;
|
| 59 |
+
correctGuess = true;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
if (!correctGuess) {
|
| 64 |
+
guesses--;
|
| 65 |
+
reply(`Incorrect guess! You have ${guesses} guesses left.\n\n${guessedWord.join(" ")}`);
|
| 66 |
+
} else {
|
| 67 |
+
reply(`Correct guess!\n\n${guessedWord.join(" ")}`);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if (guesses === 0) {
|
| 71 |
+
reply(`Game over! The word was ${word}.`);
|
| 72 |
+
} else if (!guessedWord.includes("_")) {
|
| 73 |
+
reply(`Congratulations! You guessed the word ${word}.`);
|
| 74 |
+
}
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
conn.on("message", async (msg) => {
|
| 78 |
+
if (msg.key.remoteJid === from && msg.message.conversation) {
|
| 79 |
+
const guess = msg.message.conversation.toLowerCase();
|
| 80 |
+
await hangmanGame(guess);
|
| 81 |
+
}
|
| 82 |
+
});
|
| 83 |
+
} catch (e) {
|
| 84 |
+
console.error('Hangman command error:', e);
|
| 85 |
+
reply(`Error: ${e.message}`);
|
| 86 |
+
}
|
| 87 |
+
});
|