From f497c429b5748ffa4b64b5edfc60a19de79a7f60 Mon Sep 17 00:00:00 2001 From: Caio Agiani Date: Sat, 18 Jun 2022 12:52:38 -0300 Subject: [PATCH] chore(packages): update and refact commands (#85) * chore(package): update * chore(commands): refact * chore(version): bump version 0.6.5 --- .github/workflows/lint.yml | 2 +- package.json | 24 ++++++++++++------------ src/app/commands/CepCommand.ts | 2 +- src/app/commands/ProfileCommand.ts | 1 + src/app/commands/QuoteCommand.ts | 30 ++++++++++++++---------------- src/app/commands/SmsCommand.ts | 1 + src/app/commands/index.ts | 1 - 7 files changed, 30 insertions(+), 31 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f73a609..556ff07 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,7 +9,7 @@ jobs: name: eslint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: install node v12 uses: actions/setup-node@v3 with: diff --git a/package.json b/package.json index 8abe4c6..22e3d89 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "whatsapp-web-bot", "main": "src/index.ts", "description": "WhatsApp Bot", - "version": "0.6.1", + "version": "0.6.5", "license": "MIT", "keywords": [ "whatsapp", @@ -50,25 +50,25 @@ "dev": "tsnd --respawn --transpile-only --ignore-watch node_modules -r dotenv/config src/index.ts" }, "dependencies": { - "axios": "^0.26.0", - "mobizon-node": "^0.4.3", + "axios": "^0.27.0", + "mobizon-node": "^0.5.0", "node-base64-image": "^2.0.1", "qrcode-terminal": "^0.12.0", - "whatsapp-web.js": "^1.16.1" + "whatsapp-web.js": "^1.16.7" }, "devDependencies": { - "@types/node": "16.11.26", + "@types/node": "16.11.41", "@types/qrcode": "1.4.2", "@types/qrcode-terminal": "0.12.0", - "@typescript-eslint/eslint-plugin": "5.12.1", - "@typescript-eslint/parser": "5.12.1", - "dotenv": "16.0.0", - "eslint": "8.10.0", - "eslint-config-prettier": "8.4.0", + "@typescript-eslint/eslint-plugin": "5.28.0", + "@typescript-eslint/parser": "5.28.0", + "dotenv": "16.0.1", + "eslint": "8.18.0", + "eslint-config-prettier": "8.5.0", "eslint-loader": "4.0.2", "eslint-plugin-prettier": "4.0.0", - "prettier": "2.5.1", + "prettier": "2.7.1", "ts-node-dev": "1.1.8", - "typescript": "4.5.5" + "typescript": "4.7.4" } } diff --git a/src/app/commands/CepCommand.ts b/src/app/commands/CepCommand.ts index e81d458..d5edca2 100644 --- a/src/app/commands/CepCommand.ts +++ b/src/app/commands/CepCommand.ts @@ -4,13 +4,13 @@ import type { Message } from 'whatsapp-web.js'; export default class EconomyCommand { cep: string; + constructor(cep: string) { this.cep = cep; } async execute(msg: Message): Promise { const [_, setCep] = this.cep.split(' '); - const chat = await msg.getChat(); await chat.sendStateTyping(); diff --git a/src/app/commands/ProfileCommand.ts b/src/app/commands/ProfileCommand.ts index a1ba523..fd9248e 100644 --- a/src/app/commands/ProfileCommand.ts +++ b/src/app/commands/ProfileCommand.ts @@ -4,6 +4,7 @@ import type { Message } from 'whatsapp-web.js'; export default class ProfileCommand { mention: string; + constructor(mention: string) { this.mention = mention; } diff --git a/src/app/commands/QuoteCommand.ts b/src/app/commands/QuoteCommand.ts index ef41aba..2db7fb6 100644 --- a/src/app/commands/QuoteCommand.ts +++ b/src/app/commands/QuoteCommand.ts @@ -15,26 +15,24 @@ export const QuoteCommand = { return msg.reply('Comando apenas para grupos!'); } - company.forEach(async ({ numero, admin }): Promise => { - if (numero !== contato) return; + const allowPermissions = company.filter( + ({ numero, admin }) => numero === contato && admin, + ); - if (!admin) { - return msg.reply( - 'Ops, você não tem permissão para executar este comando!', - ); - } + if (!allowPermissions.length) { + return msg.reply('Você não tem permissão para usar este comando!'); + } + + const mentions = []; - let text = ''; - const mentions = []; + for (const participant of chat.participants) { + const contact = await client.getContactById(participant.id._serialized); - for (const participant of chat.participants) { - const contact = await client.getContactById(participant.id._serialized); + mentions.push(contact); + } - mentions.push(contact); - text += `@${participant.id.user} `; - } + const names = mentions.map((mention) => `@${mention.number}`).join(' '); - return chat.sendMessage(text, { mentions }); - }); + return chat.sendMessage(names, { mentions }); }, }; diff --git a/src/app/commands/SmsCommand.ts b/src/app/commands/SmsCommand.ts index d9abc57..c9458f7 100644 --- a/src/app/commands/SmsCommand.ts +++ b/src/app/commands/SmsCommand.ts @@ -3,6 +3,7 @@ import mobizon from '../../services/mobizon'; export default class ProfileCommand { mention: string; + constructor(mention: string) { this.mention = mention; } diff --git a/src/app/commands/index.ts b/src/app/commands/index.ts index 97a9928..6203a9f 100644 --- a/src/app/commands/index.ts +++ b/src/app/commands/index.ts @@ -1,6 +1,5 @@ import { commandDispatcher } from '../utils/CommandDispatcher'; import { Message } from 'whatsapp-web.js'; - import { EconomyCommand } from './EconomyCommand'; import { QuoteCommand } from './QuoteCommand'; import CepCommand from './CepCommand';