@@ -10,7 +10,7 @@ async function loadCheerio(url) {
1010 }
1111}
1212
13- async function getData ( url ) {
13+ async function getCoinStats ( url ) {
1414 const $ = await loadCheerio ( url ) ;
1515
1616 if ( ! ( typeof $ === 'function' ) ) {
@@ -23,8 +23,8 @@ async function getData(url) {
2323 . find ( 'tr' ) ;
2424 const statsArray = [ ] ;
2525
26- priceStatistics . each ( function ( ) {
27- const tr = $ ( this ) ;
26+ priceStatistics . each ( ( _ , pS ) => {
27+ const tr = $ ( pS ) ;
2828 const key = tr . find ( 'th' ) . text ( ) ;
2929 let value = tr . find ( 'td' ) ;
3030
@@ -36,7 +36,7 @@ async function getData(url) {
3636 value = value . text ( ) ;
3737 }
3838
39- if ( value !== 'No Data' || value !== 'Sem Dados' ) {
39+ if ( value !== 'No Data' ) {
4040 const object = Object . fromEntries ( [ [ key , value ] ] ) ;
4141 statsArray . push ( object ) ;
4242 }
@@ -45,20 +45,10 @@ async function getData(url) {
4545 return statsArray ;
4646}
4747
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-
5948class Coin {
6049 constructor ( ) {
6150 this . name = 'coin' ;
51+ this . BASE_URL = 'https://coinmarketcap.com/currencies/' ;
6252 this . defaultMessage = `
6353uso: *!coin* [--flag] name
6454_--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
7161 const { args, text } = data ;
7262
7363 if ( ! text ) {
74- message . reply ( this . defaultMessage . trim ( ) ) ;
64+ message . reply ( this . defaultMessage ) ;
7565 return ;
7666 }
7767
78- const url = getUrl ( args , text ) ;
79- let coinStats = await getData ( url ) ;
68+ const url = this . getUrl ( text ) ;
69+ let coinStats = await getCoinStats ( url ) ;
8070
8171 if ( ! coinStats ) {
82- message . reply ( 'moeda não encontrada' ) ;
72+ message . reply ( 'Moeda não encontrada. ' ) ;
8373 return ;
8474 }
75+
8576 if ( ! args . includes ( 'all' ) ) {
8677 coinStats = coinStats . slice ( 0 , 3 ) ;
8778 }
@@ -96,6 +87,11 @@ a flag _all_ pode retornar dados em excesso, sua utilização repetida será con
9687
9788 message . reply ( output . trim ( ) ) ;
9889 }
90+
91+ getUrl ( text ) {
92+ const path = text . replace ( / \s / g, '-' ) . toLowerCase ( ) ;
93+ return this . BASE_URL + path ;
94+ }
9995}
10096
10197module . exports = Coin ;
0 commit comments