@@ -10,7 +10,7 @@ async function loadCheerio(url) {
10
10
}
11
11
}
12
12
13
- async function getData ( url ) {
13
+ async function getCoinStats ( url ) {
14
14
const $ = await loadCheerio ( url ) ;
15
15
16
16
if ( ! ( typeof $ === 'function' ) ) {
@@ -23,8 +23,8 @@ async function getData(url) {
23
23
. find ( 'tr' ) ;
24
24
const statsArray = [ ] ;
25
25
26
- priceStatistics . each ( function ( ) {
27
- const tr = $ ( this ) ;
26
+ priceStatistics . each ( ( _ , pS ) => {
27
+ const tr = $ ( pS ) ;
28
28
const key = tr . find ( 'th' ) . text ( ) ;
29
29
let value = tr . find ( 'td' ) ;
30
30
@@ -36,7 +36,7 @@ async function getData(url) {
36
36
value = value . text ( ) ;
37
37
}
38
38
39
- if ( value !== 'No Data' || value !== 'Sem Dados' ) {
39
+ if ( value !== 'No Data' ) {
40
40
const object = Object . fromEntries ( [ [ key , value ] ] ) ;
41
41
statsArray . push ( object ) ;
42
42
}
@@ -45,20 +45,10 @@ async function getData(url) {
45
45
return statsArray ;
46
46
}
47
47
48
- function getUrl ( args , text ) {
49
- let baseURL = 'https://coinmarketcap.com/currencies/' ;
50
- const path = text . replace ( / \s / g, '-' ) . toLowerCase ( ) ;
51
-
52
- if ( args . includes ( 'brl' ) ) {
53
- baseURL = 'https://coinmarketcap.com/pt-br/currencies/' ;
54
- }
55
-
56
- return baseURL + path ;
57
- }
58
-
59
48
class Coin {
60
49
constructor ( ) {
61
50
this . name = 'coin' ;
51
+ this . BASE_URL = 'https://coinmarketcap.com/currencies/' ;
62
52
this . defaultMessage = `
63
53
uso: *!coin* [--flag] name
64
54
_--all -> mostra todas as informações disponiveis_
@@ -71,17 +61,18 @@ a flag _all_ pode retornar dados em excesso, sua utilização repetida será con
71
61
const { args, text } = data ;
72
62
73
63
if ( ! text ) {
74
- message . reply ( this . defaultMessage . trim ( ) ) ;
64
+ message . reply ( this . defaultMessage ) ;
75
65
return ;
76
66
}
77
67
78
- const url = getUrl ( args , text ) ;
79
- let coinStats = await getData ( url ) ;
68
+ const url = this . getUrl ( text ) ;
69
+ let coinStats = await getCoinStats ( url ) ;
80
70
81
71
if ( ! coinStats ) {
82
- message . reply ( 'moeda não encontrada' ) ;
72
+ message . reply ( 'Moeda não encontrada. ' ) ;
83
73
return ;
84
74
}
75
+
85
76
if ( ! args . includes ( 'all' ) ) {
86
77
coinStats = coinStats . slice ( 0 , 3 ) ;
87
78
}
@@ -96,6 +87,11 @@ a flag _all_ pode retornar dados em excesso, sua utilização repetida será con
96
87
97
88
message . reply ( output . trim ( ) ) ;
98
89
}
90
+
91
+ getUrl ( text ) {
92
+ const path = text . replace ( / \s / g, '-' ) . toLowerCase ( ) ;
93
+ return this . BASE_URL + path ;
94
+ }
99
95
}
100
96
101
97
module . exports = Coin ;
0 commit comments