forked from RafaMunoz/Ethereum_Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminafacilbot.py
239 lines (206 loc) · 10.3 KB
/
minafacilbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import json
import telebot
import requests
from time import sleep
from telebot import types
# -------------------- SETTINGS --------------------
# Telegram bot Token.
token = "2145088618:AAGnOYyZ_OrBdfreClJzUwe4JdnaaCPUhLxo"
# List with the telegram id of the allowed users.
id_admins = [-100168323453230]
# Your Pool. 0 = Minafacil
pool = 0
# Tiempo en segundos de consulta
tiempo_consulta = 60
# --------------------------------------------------
list_pools = ["http://pool.minafacil.com/api"]
web = ["https://pool.minafacil.com"]
def estado_wallet(id_user, wallet):
url = list_pools[pool] + "/wallet?address=" + wallet
response = requests.get(url)
if response.status_code == 200:
try:
response_json = response.json()
currency = response_json["currency"]
unsold = round(float(response_json["unsold"]), 4)
balance = round(float(response_json["balance"]) , 4)
unpaid = round(float(response_json["unpaid"]) , 4)
paid24h = round(float(response_json["paid24h"]), 4)
total = round(float(response_json["total"]) , 4)
text_send = "ESTADO WALLET (ult 24h) \n\n" + "*Wallet :* ``` " + str(
wallet) + " ```\n" + "*Moneda :* ``` " + str(
currency) + " ```\n" + "*Inmaduro :* ``` " + str(
unsold) + " ```\n" + "*Balance :* ``` " + str(
balance) + " ```\n" + "*Sin pagar :* ``` " + str(
unpaid) + "```\n" + "*Pagado 24h :* ```" + str(
paid24h) + "```\n" + "*Total 24h :* ```" + str(
total) + "```\n"
bot.send_message(chat_id=id_user, text=text_send, parse_mode="Markdown")
except:
text_send = u"\u26A0 Sin respuesta de " + web[pool]
bot.send_message(chat_id=id_user, text=text_send, parse_mode="Markdown")
# muestra los datos del estado de la pool
def estado_pool(id_user):
url = list_pools[pool] + "/status"
response = requests.get(url)
if response.status_code == 200:
try:
response_json = response.json()
port = response_json["gr"]["port"]
fees = response_json["gr"]["fees"]
fees_solo = response_json["gr"]["fees_solo"]
hash_rate = round(float(response_json["gr"]["hashrate"]) / (10 ** 6), 2)
workers = response_json["gr"]["workers"]
workers_shared = response_json["gr"]["workers_shared"]
workers_solo = response_json["gr"]["workers_solo"]
hashrate_last24h = round(float(response_json["gr"]["hashrate_last24h"]) / (10 ** 6), 2)
text_send = "ESTADO DE LA POOL \n\n" + "*Url :* ``` " + str(
web) + " ```\n" + "*Puerto :* ``` " + str(
port) + " ```\n" + "*Fees :* ``` " + str(
fees) + "% ```\n" + "*Fees solo :* ``` " + str(
fees_solo) + "% ```\n" + "*Hashrate:* ``` " + str(
hash_rate) + " MH/s```\n" + "*Mineros :* ```" + str(
workers) + "```\n" + "*Mineros activos:* ```" + str(
workers_shared) + "```\n" + "*Mineros solo:* ```" + str(
workers_solo) + "```\n" + "*Hashrate 24h:* ``` " + str(
hashrate_last24h) + " MH/s```\n"
bot.send_message(chat_id=id_user, text=text_send, parse_mode="Markdown")
except:
text_send = u"\u26A0 Sin respuesta de " + web[pool]
bot.send_message(chat_id=id_user, text=text_send, parse_mode="Markdown")
def bloque_info(id_user):
url = list_pools[pool] + "/currencies"
response = requests.get(url)
if response.status_code == 200:
try:
response_json = response.json()
hash_rate = round(float(response_json["RTM"]["hashrate"]) / (10 ** 6), 2)
workers_shared = response_json["RTM"]["workers_shared"]
time_last_block = response_json["RTM"]["timesincelast"]
last_block = response_json["RTM"]["lastblock"]
last24_block = response_json["RTM"]["24h_blocks"]
difficulty = response_json["RTM"]["difficulty"]
reward = response_json["RTM"]["reward"]
height = response_json["RTM"]["height"]
timesincelast = round(float(response_json["RTM"]["timesincelast"]) / 60, 2)
text_send = "INFO ULTIMO BLOQUE \n\n" + "*Bloque :* ``` " + str(
last_block) + " ```\n" + "*Dificultad :* ``` " + str(
difficulty) + " ```\n" + "*Recompensa :* ``` " + str(
reward) + " ```\n" + "*Altura :* ``` " + str(
height) + " ```\n" + "*Hashrate:* ``` " + str(
hash_rate) + " MH/s```\n" + "*Mineros Activos:* ```" + str(
workers_shared) + "```\n" + "*# de bloques en 24h:* ```" + str(
last24_block) + "```\n" + "*Ult. bloque hace :* ```" + str(
timesincelast) + "```\n"
bot.send_message(chat_id=id_user, text=text_send, parse_mode="Markdown")
except:
text_send = u"\u26A0 Sin respuesta de " + web[pool]
bot.send_message(chat_id=id_user, text=text_send, parse_mode="Markdown")
# muestra datos del bloque encontrado
def bloque_encontrado(id_user):
url = list_pools[pool] + "/currencies"
response = requests.get(url)
if response.status_code == 200:
try:
response_json = response.json()
hash_rate = round(float(response_json["RTM"]["hashrate"]) / (10 ** 6), 2)
workers_shared = response_json["RTM"]["workers_shared"]
time_last_block = response_json["RTM"]["timesincelast"]
last_block = response_json["RTM"]["lastblock"]
last24_block = response_json["RTM"]["24h_blocks"]
difficulty = response_json["RTM"]["difficulty"]
reward = response_json["RTM"]["reward"]
height = response_json["RTM"]["height"]
text_send = "\U0001F4A5 *BLOQUE CONSEGUIDO* \U0001F4A5 \n \U0001F4B0 \U0001F4B0 \U0001F4B0 \U0001F4B2 \U0001F4B2 \U0001F4B2 \U0001F4B2 \U0001F60A \U0001F60A \U0001F60A\n" + "*Bloque :* ``` " + str(
last_block) + " ```\n" + "*Dificultad :* ``` " + str(
difficulty) + " ```\n" + "*Recompensa :* ``` " + str(
reward) + " ```\n" + "*Altura :* ``` " + str(
height) + " ```\n" + "*Hashrate:* ``` " + str(
hash_rate) + " MH/s```\n" + "*Mineros Activos:* ```" + str(
workers_shared) + "```\n" + "*# de bloques en 24h:* ```" + str(
last24_block) + "```\n"
bot.send_message(chat_id=id_user, text=text_send, parse_mode="Markdown")
print(text_send)
except:
text_send = u"\u26A0 Sin respuesta de " + web[pool]
bot.send_message(chat_id=id_user, text=text_send, parse_mode="Markdown")
# We check if the user has permission.
def check_admin(id_user):
check = id_user in id_admins
return check
# Keyboard Telegram Bot
def keyboard(chat_id, textoEnvio):
r1 = ["Pool", "Bloque"]
keyboard = [r1]
news_keyboard = {'keyboard': keyboard, 'resize_keyboard': True}
bot.send_message(chat_id, textoEnvio, None, None, json.dumps(news_keyboard))
if __name__ == "__main__":
print('Iniciando script bot minafacil\n')
print('-----------------------------------------------------------\n')
print('Token : ' + token + '\n')
print('id_admins : '+ str(id_admins[0]) + '\n')
print('Intervalo de consulta : '+ str(tiempo_consulta) +'\n')
print('Pools : ' + str(list_pools) + '\n')
print('-----------------------------------------------------------\n\n')
print('Esperando mensaje start...\n')
bot = telebot.TeleBot(token)
# Welcome message.
@bot.message_handler(commands=['start'])
def send_welcome(message):
print('mensaje start Recibido. Validando usuario...\n')
id_user = message.chat.id
permitted = check_admin(id_user)
if (permitted == True):
print('Usuario ' + str(id_user) + ' Validado. Consultando API ' + str(list_pools) + '...\n')
url = list_pools[pool] + "/currencies"
response = requests.get(url)
if response.status_code == 200:
response_json = response.json()
last_block_ini = response_json["RTM"]["lastblock"]
text_send = "\U0001F50E *Iniciando busqueda de bloque* \U0001F50D \n" + "*Ultimo Bloque :* ``` " + str(last_block_ini) + " ```\n"
print('Iniciando busqueda de bloque \n' + ' Ultimo Bloque : ' + str(last_block_ini) + '\n')
bot.send_message(chat_id=id_user, text=text_send, parse_mode="Markdown")
while 1:
sleep(tiempo_consulta)
print('Consultando API. Ultimo Bloque : ' + str(last_block_ini) + '\n')
response = requests.get(url)
if response.status_code == 200:
response_json = response.json()
last_block = response_json["RTM"]["lastblock"]
print(' comparando bloque actual con ult. bloque (' + str(last_block)+ ', ' + str(last_block_ini) + ')\n')
if last_block != last_block_ini :
bloque_encontrado(id_user)
last_block_ini = last_block
else:
print('No encontrado. Ultimo bloque '+ str(last_block) + ' - sigue la busqueda...\n')
else:
print('No hubo respuesta de ' + str(list_pools) + '\n')
else:
print('No hubo respuesta de ' + str(list_pools) + '\n')
else:
print('Usuario ' + str(id_user) + ' No autorizado.\n')
@bot.message_handler()
def main(message):
id_user = message.chat.id
id_chat_group = id_user
permitted = check_admin(id_user)
if (permitted == True):
text = message.text
print('Mensaje recibido : ' + str(text) + ' Validando comandos...')
# if text.find('=') > 0 :
# text1 = text.split('=')
# comando = text1[0]
# parametro1 = text1[1]
# else:
# comando = text
# parametro1 = ""
# Mine button.
# if comando == "Pool":
# estado_pool(id_user)
# if comando == "Wallet":
# estado_wallet(id_user, parametro1)
# if comando == "Bloque":
# bloque_info(id_user)
bot.polling(none_stop=True)