Skip to content

Commit 8813093

Browse files
authored
Merge pull request #41 from carlos3g/master
[FEAT] implements some kwargs and methods in !search and !cron
2 parents 60abd51 + 8825834 commit 8813093

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/commands/cron.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Repete uma mensagem em um determinado período de tempo. Cada mensagem é repres
1313
\`\`\`--stop\`\`\` -> _para uma thread._
1414
\`\`\`--start\`\`\` -> _inicia uma thread._
1515
\`\`\`--log\`\`\` -> _mostra as threads existentes._
16+
\`\`\`--killall\`\`\` -> _para e apaga todas as threads._
1617
\`\`\`--help\`\`\` -> _mostra esta mensagem._
1718
1819
*kwargs válidos:*
@@ -124,6 +125,14 @@ class Cron {
124125
return output.trim();
125126
}
126127

128+
killall() {
129+
this.threads.forEach((t) => {
130+
this.destroy(t.id);
131+
});
132+
133+
return 'Todas as threads foram destruidas.';
134+
}
135+
127136
runs(data, message) {
128137
const methods = {
129138
log: () => this.log(),
@@ -132,6 +141,7 @@ class Cron {
132141
start: () => this.start(data.text),
133142
stop: () => this.stop(data.text),
134143
help: () => this.strings.help,
144+
killall: () => this.killall(),
135145
};
136146

137147
if (methods[data.args[0]]) {

src/commands/lyric.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class Lyric {
3434
this.strings = STRINGS;
3535
}
3636

37-
// eslint-disable-next-line
3837
async execute(data, message) {
3938
const { text, args } = data;
4039

@@ -47,7 +46,7 @@ class Lyric {
4746
throw new Error('Nenhum nome foi passado');
4847
}
4948

50-
const results = await search.google(text, 'https://www.letras.mus.br');
49+
const results = await search(text, 'https://www.letras.mus.br');
5150
const { link } = results[0];
5251
const soup = await makeSoup(link);
5352
const title = soup.find('div', { class: 'cnt-head_title' }).find('h1');

src/commands/search.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Retorna o primeiro resultado de uma pesquisa no google.
88
99
*args válidos:*
1010
\`\`\`--help\`\`\` -> _mostra esta mensagem._
11+
\`\`\`--target\`\`\` -> _define um site especifico para pesquisa._
12+
\`\`\`--limit\`\`\` -> _define um limite de resultados. O padrão é 1._
1113
`.trim(),
1214
};
1315

@@ -18,7 +20,7 @@ class Search {
1820
}
1921

2022
async execute(data, message) {
21-
const { args, text } = data;
23+
const { args, text, kwargs } = data;
2224

2325
if (args.includes('help')) {
2426
message.reply(this.strings.help);
@@ -29,12 +31,12 @@ class Search {
2931
throw new Error('Nenhum texto para pesquisa foi especificado.');
3032
}
3133

32-
const results = await search.google(text, undefined, 1);
34+
const results = await search(text, kwargs.target, kwargs.limit);
3335

3436
if (results.length > 0) {
3537
const stringResult = results
3638
.map((r) => Search.formatResult(r))
37-
.join('\n\n');
39+
.join('\n\n🔹🔹🔹\n\n');
3840
message.reply(stringResult);
3941
return;
4042
}

src/utils/search.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ const googleIt = require('google-it');
77
* @param {number} [limit=0] Max number of results that must be returned.
88
* @returns {object[]} Array of results found.
99
*/
10-
async function google(query, target = '', limit = 0) {
10+
async function search(query, target = '', limit = 1) {
1111
const result = await googleIt({
1212
query,
1313
includeSites: target,
14+
disableConsole: true,
1415
});
1516

1617
if (limit) {
@@ -20,6 +21,4 @@ async function google(query, target = '', limit = 0) {
2021
return result;
2122
}
2223

23-
module.exports = {
24-
google,
25-
};
24+
module.exports = search;

0 commit comments

Comments
 (0)