|
1 | 1 | const axios = require('axios');
|
2 | 2 | const cheerio = require('cheerio');
|
3 | 3 |
|
4 |
| -const defaultMessage = ` |
5 |
| -uso: *!coin* [--flag] name |
6 |
| -_--all -> mostra todas as informações disponiveis_ |
7 |
| -
|
8 |
| -a flag _all_ pode retornar dados em excesso, sua utilização repetida será considera spam |
9 |
| -`; |
10 |
| - |
11 | 4 | async function loadCheerio(url) {
|
12 | 5 | try {
|
13 | 6 | const { data } = await axios.get(url);
|
@@ -63,30 +56,46 @@ function getUrl(args, text) {
|
63 | 56 | return baseURL + path;
|
64 | 57 | }
|
65 | 58 |
|
66 |
| -module.exports = async (data) => { |
67 |
| - const { args, text } = data; |
| 59 | +class Coin { |
| 60 | + constructor() { |
| 61 | + this.name = 'coin'; |
| 62 | + this.defaultMessage = ` |
| 63 | +uso: *!coin* [--flag] name |
| 64 | +_--all -> mostra todas as informações disponiveis_ |
68 | 65 |
|
69 |
| - if (!text) { |
70 |
| - return defaultMessage.trim(); |
| 66 | +a flag _all_ pode retornar dados em excesso, sua utilização repetida será considera spam |
| 67 | + `.trim(); |
71 | 68 | }
|
72 | 69 |
|
73 |
| - const url = getUrl(args, text); |
74 |
| - let coinStats = await getData(url); |
| 70 | + async execute(data, message) { |
| 71 | + const { args, text } = data; |
75 | 72 |
|
76 |
| - if (!coinStats) { |
77 |
| - return 'moeda não encontrada'; |
78 |
| - } |
79 |
| - if (!args.includes('all')) { |
80 |
| - coinStats = coinStats.slice(0, 3); |
81 |
| - } |
| 73 | + if (!text) { |
| 74 | + message.reply(this.defaultMessage.trim()); |
| 75 | + return; |
| 76 | + } |
82 | 77 |
|
83 |
| - let output = ''; |
| 78 | + const url = getUrl(args, text); |
| 79 | + let coinStats = await getData(url); |
84 | 80 |
|
85 |
| - coinStats.forEach((s) => { |
86 |
| - const [key, value] = Object.entries(s)[0]; |
87 |
| - const string = `*_${key}_*:\n - ${value}\n\n`; |
88 |
| - output += string; |
89 |
| - }); |
| 81 | + if (!coinStats) { |
| 82 | + message.reply('moeda não encontrada'); |
| 83 | + return; |
| 84 | + } |
| 85 | + if (!args.includes('all')) { |
| 86 | + coinStats = coinStats.slice(0, 3); |
| 87 | + } |
| 88 | + |
| 89 | + let output = ''; |
| 90 | + |
| 91 | + coinStats.forEach((s) => { |
| 92 | + const [key, value] = Object.entries(s)[0]; |
| 93 | + const string = `*_${key}_*:\n - ${value}\n\n`; |
| 94 | + output += string; |
| 95 | + }); |
| 96 | + |
| 97 | + message.reply(output.trim()); |
| 98 | + } |
| 99 | +} |
90 | 100 |
|
91 |
| - return output.trim(); |
92 |
| -}; |
| 101 | +module.exports = Coin; |
0 commit comments