Skip to content

Instantly share code, notes, and snippets.

@KOULIKS94
Created April 6, 2025 07:59
Show Gist options
  • Select an option

  • Save KOULIKS94/4d0ea5ebbdbc595139b5ed2c046fb667 to your computer and use it in GitHub Desktop.

Select an option

Save KOULIKS94/4d0ea5ebbdbc595139b5ed2c046fb667 to your computer and use it in GitHub Desktop.
const { bot, getRandom } = require('../lib/');
bot(
{
pattern: 'gamebattle ?(.*)',
fromMe: true,
desc: 'Fun game + score for 2 or 4 players',
type: 'fun',
},
async (message, match) => {
if (!message.isGroup) return message.send('*This command only works in group chats.*');
let groupMeta;
try {
groupMeta = await message.groupMetadata(message.jid);
} catch (e) {
return message.send('*Error fetching group data. Is the bot admin?*');
}
const allParticipants = groupMeta?.participants?.map(p => p.id);
if (!allParticipants || allParticipants.length < 2) {
return message.send('*Not enough group members to play.*');
}
// Filter out bot itself
const players = allParticipants.filter(id => id !== message.participant);
const playerCount = match.includes('4') ? 4 : 2;
const picked = [];
while (picked.length < playerCount && players.length > 0) {
const random = getRandom(players);
picked.push(random);
players.splice(players.indexOf(random), 1);
}
const challengeList = [
'Emoji Speed Typing!',
'Dance Like an Anime Character!',
'Voice Imitation Battle!',
'Most Creative “I love bot” message!',
'Fastest Reaction Time!',
'Guess the Anime Opening!',
];
const challenge = getRandom(challengeList);
const result = picked.map(p => ({
id: p,
score: Math.floor(Math.random() * 101),
})).sort((a, b) => b.score - a.score);
const scoreboard = result.map((r, i) =>
`${i + 1}. @${r.id.split('@')[0]} — *${r.score}* pts`
).join('\n');
const caption = `🎮 *GAME BATTLE* 🎮\n\n*Challenge:* ${challenge}\n\n🏆 *Results:*\n${scoreboard}`;
return await message.send(caption, {
contextInfo: { mentionedJid: result.map(r => r.id) }
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment