Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/schwartzblat/wa-minigames

Node.js module that helps creating minigames with whatsapp-web.js
https://github.com/schwartzblat/wa-minigames

Last synced: about 8 hours ago
JSON representation

Node.js module that helps creating minigames with whatsapp-web.js

Awesome Lists containing this project

README

        

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

```console
npm install whatsapp-web.js
npm install wa-minigames
```
## Example Usage
```js
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();

```