Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/schwartzblat/wa-minigames
- Owner: Schwartzblat
- Created: 2022-01-27T16:41:56.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-02-06T14:29:48.000Z (over 2 years ago)
- Last Synced: 2024-09-24T11:03:43.562Z (about 23 hours ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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();
```