forked from andrecrjr/CoinGecko-Telegram-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mega refactor now using coingecko api to fetch and now BAT has come t…
…o us
- Loading branch information
Showing
9 changed files
with
368 additions
and
623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"program": "${workspaceFolder}\\bot.js" | ||
} | ||
] | ||
} | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"program": "${workspaceFolder}\\bot.js" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
const TeleBot = require('telebot'); | ||
if(process.env.NODE_ENV !== 'prd'){ | ||
require('dotenv').config(); | ||
bot = new TeleBot(process.env.TOKEN_BTC) | ||
}else{ | ||
bot = new TeleBot({ | ||
token:process.env.TOKEN_BTC, | ||
usePlugins: ['commandButton'], | ||
}) | ||
const TeleBot = require("telebot"); | ||
if (process.env.NODE_ENV !== "prd") { | ||
require("dotenv").config(); | ||
bot = new TeleBot({ | ||
token: process.env.TOKEN_BTC, | ||
usePlugins: ["commandButton"], | ||
}); | ||
} else { | ||
bot = new TeleBot({ | ||
token: process.env.TOKEN_BTC, | ||
usePlugins: ["commandButton"], | ||
}); | ||
} | ||
|
||
module.exports = bot | ||
module.exports = bot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Bot GeckCripto</title> | ||
</head> | ||
<body> | ||
<h1>GeckoCripto Bot Updated!</h1> | ||
<a href="https://brave.com/eel072">Use brave browser</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
require('./server'); | ||
let express = require("express"); | ||
let path = require("path"); | ||
let app = express(); | ||
|
||
app.get("/", function (req, res) { | ||
require("./src/routes/bot")(); | ||
|
||
res.sendFile(path.join(__dirname + "/index.html")); | ||
}); | ||
|
||
let port = process.env.PORT || 3000; | ||
|
||
let server = app.listen(port, "0.0.0.0", function () { | ||
console.log( | ||
`Funcionando ${server.address().address}:${server.address().port}` | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,72 @@ | ||
const axios = require('axios') | ||
const {convertDate, float} = require('../utils/timeUtils') | ||
|
||
class mercadobitcoinApi{ | ||
constructor(coin=undefined){ | ||
this._endpoint = 'https://www.mercadobitcoin.net/api/'; | ||
this._coin = coin; | ||
this.endpointCoin = this.endpoint+this.coin | ||
this._realNameCoin = this.discoverName() | ||
} | ||
const axios = require("axios"); | ||
const { convertDate, float } = require("../utils/timeUtils"); | ||
|
||
get endpoint(){ | ||
return this._endpoint; | ||
} | ||
class criptoApi { | ||
constructor(coin = undefined) { | ||
this._endpoint = | ||
"https://api.coingecko.com/api/v3/coins/markets?vs_currency=brl&ids="; | ||
this._coin = coin; | ||
this.endpointCoin = `${this.endpoint}${this.discoverName()}`; | ||
} | ||
|
||
get coin(){ | ||
return this._coin.toUpperCase(); | ||
} | ||
get endpoint() { | ||
return this._endpoint; | ||
} | ||
|
||
set coin(newCoin){ | ||
this._coin = newCoin | ||
} | ||
get coin() { | ||
return this._coin.toUpperCase(); | ||
} | ||
|
||
discoverName(){ | ||
switch(this.coin){ | ||
case "LTC": | ||
return "Litecoin" | ||
case "BTC": | ||
return "Bitcoin" | ||
case "XRP": | ||
return "Ripple" | ||
} | ||
} | ||
set coin(newCoin) { | ||
this._coin = newCoin; | ||
} | ||
|
||
async requestTickerCoin() { | ||
try{ | ||
const response = await axios.get(this.endpointCoin+`/ticker`) | ||
return response.data | ||
}catch(err){ | ||
return err | ||
console.log('error') | ||
} | ||
discoverName() { | ||
switch (this.coin) { | ||
case "LTC": | ||
return "litecoin"; | ||
case "BTC": | ||
return "bitcoin"; | ||
case "XRP": | ||
return "ripple"; | ||
case "BAT": | ||
return "basic-attention-token"; | ||
} | ||
} | ||
|
||
async requestTickerCoin() { | ||
try { | ||
const response = await axios.get(this.endpointCoin); | ||
return response.data; | ||
} catch (err) { | ||
console.log(err); | ||
|
||
renderCoin(data){ | ||
let date = convertDate() | ||
let ultimoValor = float(data.ticker.last).toFixed(2) | ||
let maxValor24 = float(data.ticker.high).toFixed(2) | ||
let highValue = `\nMaior valor nas ultimas 24h: <b>R$${maxValor24}</b>` | ||
let atualValue = `\nValor atual: <b>R$${ultimoValor}</b>` | ||
let textOperation = `$${this.coin} <b>${this.discoverName()} --- ${date}</b>${highValue}${atualValue}` | ||
return textOperation | ||
return err; | ||
} | ||
} | ||
|
||
async renderCoin(bot, msg) { | ||
const data = await this.requestTickerCoin(); | ||
const { high_24h, current_price, image, low_24h } = data[0]; | ||
let date = convertDate(); | ||
let highValue = `\nMaior valor nas ultimas 24h: <b>R$${float( | ||
high_24h | ||
).toFixed(2)}</b>`; | ||
let lowValue = `\nMenor valor nas ultimas 24h: <b>R$${float( | ||
low_24h | ||
).toFixed(2)}</b>`; | ||
let currentValue = `\nValor atual: <b>R$${float(current_price).toFixed( | ||
2 | ||
)}</b>`; | ||
let nowTime = `Hora: ${date}\n`; | ||
let textOperation = `${nowTime}${currentValue}${highValue}${lowValue}`; | ||
|
||
bot.sendPhoto(msg.from.id, image, { | ||
caption: `${this.coin}${textOperation}`, | ||
parseMode: "html", | ||
replyToMessage: true, | ||
}); | ||
} | ||
} | ||
|
||
module.exports = mercadobitcoinApi | ||
module.exports = criptoApi; |
Oops, something went wrong.