Skip to content

Commit 9a710a0

Browse files
committed
[REFACTOR] uses whitespace correctly
1 parent 9a569ff commit 9a710a0

File tree

16 files changed

+40
-44
lines changed

16 files changed

+40
-44
lines changed

alice/scripts/coin.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ async function loadCheerio(url) {
1919

2020
async function getData(url) {
2121
const $ = await loadCheerio(url);
22+
2223
if (!(typeof $ === 'function')) {
2324
return null;
2425
}
@@ -32,8 +33,8 @@ async function getData(url) {
3233
priceStatistics.each(function () {
3334
const tr = $(this);
3435
const key = tr.find('th').text();
35-
3636
let value = tr.find('td');
37+
3738
if (value.find('.sc-15yy2pl-0.hzgCfk').text()) {
3839
const valueInCash = value.find('span').first().text();
3940
const valueInPerc = value.find('.sc-15yy2pl-0.hzgCfk').text();
@@ -47,36 +48,40 @@ async function getData(url) {
4748
statsArray.push(object);
4849
}
4950
});
51+
5052
return statsArray;
5153
}
5254

5355
function getUrl(args, text) {
5456
let baseURL = 'https://coinmarketcap.com/currencies/';
57+
const path = text.replace(/\s/g, '-').toLowerCase();
58+
5559
if (args.includes('brl')) {
5660
baseURL = 'https://coinmarketcap.com/pt-br/currencies/';
5761
}
5862

59-
const path = text.replace(/\s/g, '-').toLowerCase();
6063
return baseURL + path;
6164
}
6265

6366
module.exports = async (data) => {
6467
const { args, text } = data;
68+
6569
if (!text) {
6670
return defaultMessage.trim();
6771
}
6872

6973
const url = getUrl(args, text);
7074
let coinStats = await getData(url);
75+
7176
if (!coinStats) {
7277
return 'moeda não encontrada';
7378
}
74-
7579
if (!args.includes('all')) {
7680
coinStats = coinStats.slice(0, 3);
7781
}
7882

7983
let output = '';
84+
8085
coinStats.forEach((s) => {
8186
const [key, value] = Object.entries(s)[0];
8287
const string = `*_${key}_*:\n - ${value}\n\n`;

alice/scripts/commands.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ module.exports = () => {
1313
- !report
1414
- !search
1515
- !suggest
16-
- !wiki
17-
`;
18-
16+
- !wiki`;
1917
return output.trim();
2018
};

alice/scripts/cron.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function toPositiveNumber(value) {
2929
if (Number.isNaN(number)) {
3030
return 0;
3131
}
32+
3233
return -number;
3334
}
3435

@@ -53,16 +54,17 @@ class Cron {
5354
if (isAdm) {
5455
return this.runsArg(args);
5556
}
56-
return this.runsArg(args); // 'staff only.'
57+
58+
return 'staff only.';
5759
}
5860

5961
create() {
6062
if (!(this.timer > 0)) {
6163
return 'you must add a valid time';
6264
}
63-
const { message, text, timer } = this;
64-
counter++;
6565

66+
counter++;
67+
const { message, text, timer } = this;
6668
const thread = new Thread(counter, text, message, timer);
6769
threads.push(thread);
6870

@@ -73,14 +75,14 @@ class Cron {
7375
if (!Cron.isIdValid(this.text)) {
7476
return 'thread not found';
7577
}
78+
7679
const thread = threads.find((t) => t.id === Number(this.text));
7780
this.stop();
7881

7982
emitter.removeAllListeners(`start-cron${this.text}`, thread.start);
8083
emitter.removeAllListeners(`stop-cron${this.text}`, thread.stop);
8184

8285
threads = threads.filter((t) => !(t.id === Number(this.text)));
83-
8486
return 'thread destroyed successfully';
8587
}
8688

@@ -89,6 +91,7 @@ class Cron {
8991
emitter.emit(`start-cron${this.text}`);
9092
return `starting thread ${this.text}`;
9193
}
94+
9295
return 'thread not found';
9396
}
9497

@@ -97,6 +100,7 @@ class Cron {
97100
emitter.emit(`stop-cron${this.text}`);
98101
return `stopping thread ${this.text}`;
99102
}
103+
100104
return 'thread not found';
101105
}
102106

@@ -135,6 +139,7 @@ class Cron {
135139
if (seila[args[0]]) {
136140
return seila[args[0]]();
137141
}
142+
138143
return Cron.default();
139144
}
140145

alice/scripts/dice.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ module.exports = (data) => {
1515
const multiplier = Number(match[1]);
1616
const value = Math.ceil(Math.random() * Number(match[2]));
1717
const adder = Number(match[3]) || 0;
18-
19-
const result = `Resultado: ${value}\nMultiplicador: ${multiplier}\nAdicional: ${adder}\nTotal: ${
20-
multiplier * value + adder
21-
}\n`;
22-
18+
const total = multiplier * value + adder;
19+
const result = `Resultado: ${value}\nMultiplicador: ${multiplier}\nAdicional: ${adder}\nTotal: ${total}\n`;
2320
return result;
2421
}
2522
if (text) {
2623
return 'Não foi possivel achar o valor, use !dice para mais informações.';
2724
}
25+
2826
return help;
2927
};

alice/scripts/doc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ module.exports = (data) => {
6464
if (strings[args[0]]) {
6565
return strings[args[0]].trim();
6666
}
67+
6768
return strings.defaultMessage.trim();
6869
};

alice/scripts/lyric.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ async function makeSoup(url) {
88
}
99

1010
function removeBr(raw) {
11-
let html = raw.prettify();
12-
13-
let htmlArray = html.split('\n');
14-
htmlArray = htmlArray.filter((e) => !e.match(/<br[\s]*[\/]?>/));
15-
htmlArray = htmlArray.map((e) => e.trim());
16-
html = htmlArray.join('\n');
17-
11+
const html = raw
12+
.prettify()
13+
.split('\n')
14+
.filter((e) => !e.match(/<br[\s]*[\/]?>/))
15+
.map((e) => e.trim())
16+
.join('\n');
1817
return new JSSoup(html);
1918
}
2019

@@ -28,11 +27,9 @@ module.exports = async (data, message) => {
2827
const results = await search.google(text, 'https://www.letras.mus.br');
2928
const { link } = results[0];
3029
const soup = await makeSoup(link);
31-
3230
const title = soup.find('div', { class: 'cnt-head_title' }).find('h1');
3331
const lyricsDiv = soup.find('div', { class: 'cnt-letra' });
3432
const pArray = lyricsDiv.findAll('p');
35-
3633
const output = `\
3734
*${title.text}*
3835

alice/scripts/report.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const parse = require('./utils/parse');
22

33
const myID = parse.userID('+55 11 96734-3809');
4-
54
const strings = {
65
defaultMessage: `
76
uso: _!report [--flag] [descrição]_
@@ -31,5 +30,6 @@ module.exports = (data, message, client) => {
3130
client.sendMessage(myID, reportMsg);
3231
return strings[args[0]];
3332
}
33+
3434
return strings.defaultMessage.trim();
3535
};

alice/scripts/search.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const search = require('./utils/search');
22

33
function callback(object) {
44
const { title, link, snippet } = object;
5-
65
return `
76
*${title}*
87
@@ -26,8 +25,8 @@ module.exports = async (data) => {
2625
.map((r) => callback(r))
2726
.join('\n\n')
2827
.trim();
29-
3028
return stringResult;
3129
}
30+
3231
return `Nenhum resultado foi encontrado para: _${text}_`;
3332
};

alice/scripts/suggest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ module.exports = (data, msg, client) => {
3131
client.sendMessage(myID, reportMsg);
3232
return 'obrigado pela colaboração';
3333
}
34+
3435
return defaultMessage.trim();
3536
};

alice/scripts/utils/chattools.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
*/
66
function getSerialList(idList) {
77
// eslint-disable-next-line no-underscore-dangle
8-
const serialList = idList.map((elem) => elem.id._serialized);
9-
8+
const serialList = idList.map((id) => id.id._serialized);
109
return serialList;
1110
}
1211

@@ -17,9 +16,7 @@ function getSerialList(idList) {
1716
*/
1817
async function getMembersList(chat) {
1918
const members = await chat.participants;
20-
2119
const membersSerialList = getSerialList(members);
22-
2320
return membersSerialList;
2421
}
2522

@@ -30,10 +27,8 @@ async function getMembersList(chat) {
3027
*/
3128
async function getAdmsList(chat) {
3229
const members = await chat.participants;
33-
34-
const admsIdList = members.filter((elem) => elem.isAdmin);
30+
const admsIdList = members.filter((id) => id.isAdmin);
3531
const admsSerialList = getSerialList(admsIdList);
36-
3732
return admsSerialList;
3833
}
3934

@@ -44,10 +39,8 @@ async function getAdmsList(chat) {
4439
*/
4540
async function isAdm(message) {
4641
const chat = await message.getChat();
47-
4842
const admList = await getAdmsList(chat);
4943
const { author } = message;
50-
5144
return admList.includes(author);
5245
}
5346

0 commit comments

Comments
 (0)