Skip to content

Commit 4ef21d2

Browse files
authored
[FEAT] adds and uses Command util
[FEAT] adds and uses Command util
2 parents b3dc7ca + c5987ad commit 4ef21d2

File tree

13 files changed

+209
-154
lines changed

13 files changed

+209
-154
lines changed

src/commands/about.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
const STRINGS = {
2-
help: `
3-
Mostra informações sobre o bot.
4-
5-
*uso:* \`\`\`!about [--args]\`\`\`
1+
const { Command } = require('../utils');
62

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

11-
about: `
12-
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_
10+
about: Command.message`
11+
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_
1312
14-
Não sabe como usar um comando? Use a flag help, ex: \`\`\`!lyric --help\`\`\`. Se não conhece os comandos, use \`\`\`!commands\`\`\`
13+
Não sabe como usar um comando? Use a flag help, ex: \`\`\`!lyric --help\`\`\`. Se não conhece os comandos, use \`\`\`!commands\`\`\`
1514
16-
_Quer contribuir? Então dá uma olhada em https://github.com/Coding-in-community/alice_
17-
`.trim(),
15+
_Quer contribuir? Então dá uma olhada em https://github.com/Coding-in-community/alice_
16+
`,
1817
};
1918

2019
class About {

src/commands/coin.js

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

45
const STRINGS = {
5-
help: `
6-
Retorna dados de uma moeda disponível no CoinMarketCap (https://coinmarketcap.com).
7-
8-
*uso:* \`\`\`!coin [--args] coin_name\`\`\`
9-
10-
*args válidos:*
11-
\`\`\`--all\`\`\` -> _retorna todos os dados disponíveis._
12-
\`\`\`--help\`\`\` -> _mostra essa mensagem._
13-
`.trim(),
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+
}),
1415
};
1516

1617
async function loadCheerio(url) {

src/commands/commands.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
const STRINGS = {
2-
help: `
3-
Lista todos os comandos disponíveis.
4-
5-
*uso:* \`\`\`!commands [--args]\`\`\`
1+
const { Command } = require('../utils');
62

7-
*args válidos:*
8-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
9-
`.trim(),
10-
11-
availableCommands: `
12-
Os seguintes comandos estão disponiveis:
13-
- !about
14-
- !coin
15-
- !commands
16-
- !cron
17-
- !everyone
18-
- !links
19-
- !lyric
20-
- !report
21-
- !search
22-
- !suggest
23-
- !wiki
24-
`.trim(),
3+
const STRINGS = {
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+
}),
11+
12+
availableCommands: Command.message`
13+
Os seguintes comandos estão disponiveis:
14+
- !about
15+
- !coin
16+
- !commands
17+
- !cron
18+
- !everyone
19+
- !links
20+
- !lyric
21+
- !report
22+
- !search
23+
- !suggest
24+
- !wiki
25+
`,
2526
};
2627

2728
class Commands {

src/commands/cron.js

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

44
const STRINGS = {
5-
help: `
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-
`.trim(),
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: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const { chattools } = require('../utils');
1+
const { chattools, Command } = require('../utils');
22

33
const STRINGS = {
4-
help: `
5-
Marca todos os membros do grupo com a mensagem citada.
6-
7-
*uso:* \`\`\`!everyone [--args]\`\`\`
8-
9-
*args válidos:*
10-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
11-
`.trim(),
12-
defaultMessage: '@everyone',
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`,
1313
};
1414

1515
class Everyone {
@@ -37,7 +37,6 @@ class Everyone {
3737

3838
if (message.hasQuotedMsg) {
3939
const quotedMessage = await message.getQuotedMessage();
40-
4140
quotedMessage.reply(this.strings.defaultMessage, undefined, {
4241
mentions: participants,
4342
});

src/commands/links.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
1-
const STRINGS = {
2-
help: `
3-
Lista links para os grupos coding.
4-
5-
*uso:* \`\`\`!links [--args]\`\`\`
1+
const { Command } = require('../utils');
62

7-
*args válidos:*
8-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
9-
`.trim(),
3+
const STRINGS = {
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+
}),
1011

11-
groupsLinks: `
12-
Coding in python:
13-
https://chat.whatsapp.com/I4IpHC0YFPQLUcGHJeqYdF
12+
groupsLinks: Command.message`
13+
Coding in python:
14+
https://chat.whatsapp.com/I4IpHC0YFPQLUcGHJeqYdF
1415
15-
Coding in C/C++:
16-
https://chat.whatsapp.com/Csn56Bpj8hVIQ3FiZoxBKh
16+
Coding in C/C++:
17+
https://chat.whatsapp.com/Csn56Bpj8hVIQ3FiZoxBKh
1718
18-
Coding in Javascript:
19-
https://chat.whatsapp.com/IUXcqbAPdJC2IuNfd7aaF5
19+
Coding in Javascript:
20+
https://chat.whatsapp.com/IUXcqbAPdJC2IuNfd7aaF5
2021
21-
Coding in PHP:
22-
https://chat.whatsapp.com/C6wcXZhyT869Q29PIL1J20
22+
Coding in PHP:
23+
https://chat.whatsapp.com/C6wcXZhyT869Q29PIL1J20
2324
24-
Coding in Java:
25-
https://chat.whatsapp.com/KDjc7IoCAYWAjCAwNEJ5cF
25+
Coding in Java:
26+
https://chat.whatsapp.com/KDjc7IoCAYWAjCAwNEJ5cF
2627
27-
Coding on Linux:
28-
https://chat.whatsapp.com/D37sPPhUsiT5LZ8PQeqg4t
28+
Coding on Linux:
29+
https://chat.whatsapp.com/D37sPPhUsiT5LZ8PQeqg4t
2930
30-
Coding in Taberna:
31-
https://chat.whatsapp.com/GOXnIXSXEFH7wHvO9aTuFs
31+
Coding in Taberna:
32+
https://chat.whatsapp.com/GOXnIXSXEFH7wHvO9aTuFs
3233
33-
Speaking in English:
34-
https://chat.whatsapp.com/EOirNapuFe3CVunBqbwj1Z
35-
`.trim(),
34+
Speaking in English:
35+
https://chat.whatsapp.com/EOirNapuFe3CVunBqbwj1Z
36+
`,
3637
};
3738

3839
class Links {

src/commands/lyric.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
const axios = require('axios');
22
const JSSoup = require('jssoup').default;
3-
const { search } = require('../utils');
3+
const { search, Command } = require('../utils');
44

55
const STRINGS = {
6-
help: `
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-
`.trim(),
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: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
const { chattools } = require('../utils');
1+
const { chattools, Command } = require('../utils');
22

33
const STRINGS = {
4-
help: `
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-
`.trim(),
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

src/commands/search.js

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

33
const STRINGS = {
4-
help: `
5-
Retorna o primeiro resultado de uma pesquisa no google.
6-
7-
*uso:* \`\`\`!cron [--args] ...\`\`\`
8-
9-
*args válidos:*
10-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
11-
\`\`\`--target\`\`\` -> _define um site especifico para pesquisa._
12-
\`\`\`--limit\`\`\` -> _define um limite de resultados. O padrão é 1._
13-
`.trim(),
4+
help: Command.helper({
5+
description: 'Retorna o primeiro resultado de uma pesquisa no google.',
6+
usage: '!cron [--args] ...',
7+
args: {
8+
help: 'mostra esta mensagem.',
9+
target: 'define um site especifico para pesquisa.',
10+
limit: 'define um limite de resultados. O padrão é 1.',
11+
},
12+
}),
1413
};
1514

1615
class Search {

src/commands/suggest.js

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

33
const STRINGS = {
4-
help: `
5-
Sugira algo com este comando.
6-
7-
*uso:* \`\`\`!suggest --args ...\`\`\`
8-
9-
*args válidos:*
10-
\`\`\`--feature\`\`\` -> _sugira algo novo._
11-
\`\`\`--remove\`\`\` -> _sugira remoções._
12-
\`\`\`--change\`\`\` -> _sugira mudanças._
13-
\`\`\`--help\`\`\` -> _mostra esta mensagem._
14-
`.trim(),
4+
help: Command.helper({
5+
description: 'Sugira algo com este comando.',
6+
usage: '!suggest --args ...',
7+
args: {
8+
feature: 'sugira algo novo.',
9+
remove: 'sugira remoções.',
10+
change: 'sugira mudanças.',
11+
help: 'mostra esta mensagem.',
12+
},
13+
}),
1514
};
1615

1716
class Suggest {

0 commit comments

Comments
 (0)