1.1.8 • Published 2 years ago

wa-minigames v1.1.8

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

wa-minigames

A module that helps you to create minigames with whatsapp-web.js.

Installation

npm install whatsapp-web.js
npm install wa-minigames

Example Usage

const { Client } = require('whatsapp-web.js');
const { MiniGames, MiniGame } = require('wa-minigames');
class MyGame extends MiniGame {
    constructor(message, client){
        super();
        this.client = client;
        this.chatId = message._getChatId();
        this.answer = Math.floor(Math.random() * 100).toString();
        this.client.sendMessage(this.chatId, "Game Started! Guess the number!");
    }
    async procMessage(message){
        if (message.body===this.answer){
            await this.client.sendMessage(this.chatId, 'You are right!');
            this.gameOver();
        }else if (!message.fromMe){
            await this.client.sendMessage(this.chatId, 'You are wrong.');
        }
    }
    gameOver(){
        super.gameOver();
    }
}

const client = new Client();
const minigames = new MiniGames();
client.on('qr', (qr) => {
    console.log('QR RECEIVED', qr);
});

client.on('ready', () => {
    console.log('Client is ready!');
});

client.on('message_create', async (msg) => {
    if (msg.body === '!start') {
        await minigames.addGameChat(msg._getChatId(), new MyGame(msg, client));
    }
    minigames.forwardMsg(msg);
});

client.initialize();
1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.0.0

2 years ago