Skip to content

Commit c5987ad

Browse files
committed
[FEAT] creates and uses Command.helper util
2 parents 2d6d281 + b3dc7ca commit c5987ad

File tree

14 files changed

+177
-100
lines changed

14 files changed

+177
-100
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
Coin,
66
Commands,
77
Cron,
8+
Everyone,
89
Links,
910
Lyric,
1011
Report,
@@ -18,6 +19,7 @@ const alice = new Alice([
1819
new Coin(),
1920
new Commands(),
2021
new Cron(),
22+
new Everyone(),
2123
new Links(),
2224
new Lyric(),
2325
new Report(),

src/commands/about.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
const { Command } = require('../utils');
22

33
const STRINGS = {
4-
help: Command.message`
5-
Mostra informações sobre o bot.
6-
7-
*uso:* \`\`\`!about [--args]\`\`\`
8-
9-
*args válidos:*
10-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
11-
`,
4+
help: Command.helper({
5+
description: 'Mostra informações sobre o bot.',
6+
usage: '!about [--args]',
7+
args: { help: 'mostra esta mensagem.' },
8+
}),
129

1310
about: Command.message`
1411
Alice foi criada utilizando a biblioteca \`\`\`whatsapp-web.js\`\`\` como base sob licença Apache 2.0. Saiba mais em _https://github.com/pedroslopez/whatsapp-web.js_

src/commands/coin.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const cheerio = require('cheerio');
33
const { Command } = require('../utils');
44

55
const STRINGS = {
6-
help: Command.message`
7-
Retorna dados de uma moeda disponível no CoinMarketCap (https://coinmarketcap.com).
8-
9-
*uso:* \`\`\`!coin [--args] coin_name\`\`\`
10-
11-
*args válidos:*
12-
\`\`\`--all\`\`\` -> _retorna todos os dados disponíveis._
13-
\`\`\`--help\`\`\` -> _mostra essa mensagem._
14-
`,
6+
help: Command.helper({
7+
description:
8+
'Retorna dados de uma moeda disponível no CoinMarketCap (https://coinmarketcap.com).',
9+
usage: '!coin [--args] coin_name',
10+
args: {
11+
all: 'retorna todos os dados disponíveis.',
12+
help: 'mostra esta mensagem.',
13+
},
14+
}),
1515
};
1616

1717
async function loadCheerio(url) {

src/commands/commands.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
const { Command } = require('../utils');
22

33
const STRINGS = {
4-
help: Command.message`
5-
Lista todos os comandos disponíveis.
6-
7-
*uso:* \`\`\`!commands [--args]\`\`\`
8-
9-
*args válidos:*
10-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
11-
`,
4+
help: Command.helper({
5+
description: 'Lista todos os comandos disponíveis.',
6+
usage: '!commands [--args]',
7+
args: {
8+
help: 'mostra esta mensagem.',
9+
},
10+
}),
1211

1312
availableCommands: Command.message`
1413
Os seguintes comandos estão disponiveis:
1514
- !about
1615
- !coin
1716
- !commands
1817
- !cron
18+
- !everyone
1919
- !links
2020
- !lyric
2121
- !report

src/commands/cron.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ const events = require('events');
22
const { chattools, Time, Command } = require('../utils');
33

44
const STRINGS = {
5-
help: Command.message`
6-
Repete uma mensagem em um determinado período de tempo. Cada mensagem é representada por uma thread.
7-
8-
*uso:* \`\`\`!cron --args [--kwargs=<type>] ...\`\`\`
9-
10-
*args válidos:*
11-
\`\`\`--create\`\`\` -> _cria uma nova thread._
12-
\`\`\`--destroy\`\`\` -> _para e apaga uma thread._
13-
\`\`\`--stop\`\`\` -> _para uma thread._
14-
\`\`\`--start\`\`\` -> _inicia uma thread._
15-
\`\`\`--log\`\`\` -> _mostra as threads existentes._
16-
\`\`\`--killall\`\`\` -> _para e apaga todas as threads._
17-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
18-
19-
*kwargs válidos:*
20-
\`\`\`--s=<int>\`\`\` -> _define um periodo em segundos._
21-
\`\`\`--m=<int>\`\`\` -> _define um periodo em minutos._
22-
\`\`\`--h=<int>\`\`\` -> _define um periodo em horas._
23-
\`\`\`--d=<int>\`\`\` -> _define um periodo em dias._
24-
`,
5+
help: Command.helper({
6+
description:
7+
'Repete uma mensagem em um determinado período de tempo. Cada mensagem é representada por uma thread.',
8+
usage: '!cron --args [--kwargs=<type>] ...',
9+
args: {
10+
create: 'cria uma nova thread.',
11+
destroy: 'para e apaga uma thread.',
12+
stop: 'para uma thread.',
13+
start: 'inicia uma thread.',
14+
log: 'mostra as threads existentes.',
15+
killall: 'para e apaga todas as threads.',
16+
help: 'mostra esta mensagem.',
17+
},
18+
kwargs: {
19+
's=<int>': 'define um periodo em segundos.',
20+
'm=<int>': 'define um periodo em minutos.',
21+
'h=<int>': 'define um periodo em horas.',
22+
'd=<int>': 'define um periodo em dias.',
23+
},
24+
}),
2525
};
2626
const emitter = new events.EventEmitter();
2727

src/commands/everyone.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { chattools, Command } = require('../utils');
2+
3+
const STRINGS = {
4+
help: Command.helper({
5+
description: 'Marca todos os membros do grupo com a mensagem citada.',
6+
usage: '!everyone [--args]',
7+
args: {
8+
help: 'mostra esta mensagem.',
9+
},
10+
}),
11+
12+
defaultMessage: Command.message`@everyone`,
13+
};
14+
15+
class Everyone {
16+
constructor() {
17+
this.name = 'everyone';
18+
this.strings = STRINGS;
19+
}
20+
21+
async execute(data, message) {
22+
const { args } = data;
23+
const isAdm = await chattools.isAdm(message);
24+
25+
if (!isAdm) {
26+
message.reply('staff only.');
27+
return;
28+
}
29+
30+
if (args.includes('help')) {
31+
message.reply(this.strings.help);
32+
return;
33+
}
34+
35+
const chat = await message.getChat();
36+
const { participants } = chat;
37+
38+
if (message.hasQuotedMsg) {
39+
const quotedMessage = await message.getQuotedMessage();
40+
quotedMessage.reply(this.strings.defaultMessage, undefined, {
41+
mentions: participants,
42+
});
43+
return;
44+
}
45+
46+
throw new Error('No message was replied.');
47+
}
48+
}
49+
50+
module.exports = Everyone;

src/commands/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
Coin: require('./coin'),
66
Commands: require('./commands'),
77
Cron: require('./cron'),
8+
Everyone: require('./everyone'),
89
Links: require('./links'),
910
Lyric: require('./lyric'),
1011
Report: require('./report'),

src/commands/links.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
const { Command } = require('../utils');
22

33
const STRINGS = {
4-
help: Command.message`
5-
Lista links para os grupos coding.
6-
7-
*uso:* \`\`\`!links [--args]\`\`\`
8-
9-
*args válidos:*
10-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
11-
`,
4+
help: Command.helper({
5+
description: 'Lista links para os grupos coding.',
6+
usage: '!links [--args]',
7+
args: {
8+
help: 'mostra esta mensagem.',
9+
},
10+
}),
1211

1312
groupsLinks: Command.message`
1413
Coding in python:

src/commands/lyric.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ const JSSoup = require('jssoup').default;
33
const { search, Command } = require('../utils');
44

55
const STRINGS = {
6-
help: Command.message`
7-
Retorna a letra de uma música.
8-
9-
*uso:* \`\`\`!lyric [--args] music_name\`\`\`
10-
11-
*args válidos:*
12-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
13-
`,
6+
help: Command.helper({
7+
description: 'Retorna a letra de uma música.',
8+
usage: '!lyric [--args] music_name',
9+
args: {
10+
help: 'mostra esta mensagem.',
11+
},
12+
}),
1413
};
1514

1615
async function makeSoup(url) {

src/commands/report.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
const { chattools, Command } = require('../utils');
22

33
const STRINGS = {
4-
help: Command.message`
5-
Reporte problemas no bot ou um usuário.
4+
help: Command.helper({
5+
description: 'Reporte problemas no bot ou um usuário.',
6+
usage: '!report --args ...',
7+
args: {
8+
bug: 'reporta um bug.',
9+
user: 'reporta um usuário.',
10+
help: 'mostra esta mensagem.',
11+
},
12+
}),
613

7-
*uso:* \`\`\`!report --args ...\`\`\`
8-
9-
*args válidos:*
10-
\`\`\`--bug\`\`\` -> _reporta um bug._
11-
\`\`\`--user\`\`\` -> reporta um usuário._
12-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
13-
`,
1414
bug: 'sua solicitação será analisada. caso confirmada, abriremos uma issue',
15+
1516
user: 'o usuário foi reportado a administração',
1617
};
1718

0 commit comments

Comments
 (0)