Skip to content

Commit 683756a

Browse files
authored
Merge pull request #12 from Coding-in-community/BearingMe-master
[REFACTOR] resolve Bearing-me master conflicts
2 parents d57706c + aea4d3b commit 683756a

33 files changed

+937
-1372
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
node_modules/
2-
alice/system/auth/session.json
2+
alice/src/auth/session.json

Procfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

alice/future/plans.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- novos métodos:
2+
- !doc --<componente> || FEITO:
3+
- documentação das funções
4+
- !command || FEITO:
5+
- resumo dos comandos
6+
- !quotation --<from> --<to>:
7+
- cotas monetárias
8+
- !music --<download>:
9+
- procura uma musica no youtube, e baixa caso requerido
10+
11+
12+
- novas funcionalidades
13+
- escope || IMPORTANTE
14+
- conjunto de wrappers para criar escopo de funções no whatsapp
15+
- context
16+
- api de contexto para lembrar de cada membro individualmente
17+
- scheduler || FEITO
18+
- ativa métodos em determinadas horas do dia
19+
- action
20+
- ativa métodos de acordo com eventos

alice/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// imports
2+
let src = require('./src')
3+
let build = require('./src/build')
4+
5+
// instance
6+
let path = new build.Path(__dirname)
7+
8+
let alice = new src.Alice([
9+
path.create('scripts/bot', alias='bot'),
10+
path.create('scripts/coin', alias='coin'),
11+
path.create('scripts/commands', alias='commands'),
12+
path.create('scripts/cron', alias='cron'),
13+
path.create('scripts/dice', alias='dice'),
14+
path.create('scripts/doc', alias='doc'),
15+
path.create('scripts/doc', alias='help'),
16+
path.create('scripts/github', alias='github'),
17+
path.create('scripts/links', alias='links'),
18+
path.create('scripts/lyric', alias='lyric'),
19+
path.create('scripts/report', alias='report'),
20+
path.create('scripts/search', alias='search'),
21+
path.create('scripts/suggest', alias='suggest'),
22+
path.create('scripts/wiki', alias='wiki')
23+
])
24+
25+
alice.initialize()

alice/scripts/bot.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

alice/scripts/coin.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
const axios = require('axios')
2+
const cheerio = require('cheerio')
3+
4+
5+
async function loadCheerio(url) {
6+
try {
7+
let response = await axios.get(url)
8+
let html = response.data
9+
10+
return cheerio.load(html)
11+
}
12+
13+
catch (err) {
14+
console.log('error', err.response.status)
15+
16+
return null
17+
}
18+
}
19+
20+
async function getData(url) {
21+
let $ = await loadCheerio(url)
22+
if (typeof $ === 'function') {
23+
let priceStatistics = $('.sc-AxhCb.gsRRvB.container___E9axz')
24+
let priceStatisticsTable = priceStatistics.find('table')
25+
let priceStatisticsTableBody = priceStatisticsTable.find('tbody')
26+
let priceStatisticsTableRow = priceStatisticsTableBody.find('tr')
27+
28+
let data = []
29+
priceStatisticsTableRow.each(function() {
30+
let elem = $(this)
31+
32+
let key = elem.find('th').text()
33+
34+
let value = elem.find('td')
35+
if (value.find('span.sc-1v2ivon-0.gClTFY').text()) {
36+
value = value.find('span').first().text()
37+
+ ' || ' +
38+
value.find('span.sc-1v2ivon-0.gClTFY').text()
39+
}
40+
41+
else {
42+
value = value.text()
43+
}
44+
45+
console.log(value)
46+
47+
if (value !== 'No Data' || value !== 'Sem Dados') {
48+
let object = Object.fromEntries([[key, value]])
49+
data.push(object)
50+
}
51+
})
52+
53+
return data
54+
}
55+
56+
return null
57+
}
58+
59+
let _default = `
60+
uso: *!coin* [--flag] name
61+
_--all -> mostra todas as informações disponiveis_
62+
63+
a flag _all_ pode retornar dados em excesso, sua utilização repetida será considera spam
64+
`
65+
66+
module.exports = async function(data) {
67+
let BASE_URL = 'https://coinmarketcap.com/currencies/'
68+
69+
if (data.args.includes('brl')) {
70+
BASE_URL = 'https://coinmarketcap.com/pt-br/currencies/'
71+
}
72+
73+
if (data.text) {
74+
let text = data.text.replace(/\s/g, '-').toLowerCase()
75+
let url = BASE_URL + text
76+
let coinData = await getData(url)
77+
78+
if (coinData) {
79+
if (!data.args.includes('all'))
80+
coinData = coinData.slice(0, 3)
81+
82+
let coinDataString = ''
83+
coinData.forEach(elem => {
84+
let [key, value] = Object.entries(elem)[0]
85+
86+
let string = `*_${key}_*:\n - ${value}\n\n`
87+
coinDataString += string
88+
})
89+
90+
return coinDataString.trim()
91+
}
92+
93+
else {
94+
return 'moeda não encontrada'
95+
}
96+
}
97+
98+
else {
99+
return _default.trim()
100+
}
101+
}

alice/scripts/commands.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = function () {
2+
let string_output = `
3+
Os seguintes comandos estão disponiveis:
4+
- !bot
5+
- !commands
6+
- !cron
7+
- !doc
8+
- !dice
9+
- !github
10+
- !links
11+
- !lyric
12+
- !report
13+
- !search
14+
- !suggest
15+
- !wiki
16+
`
17+
18+
return string_output.trim()
19+
}

0 commit comments

Comments
 (0)