-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot - ethermine - multi.py
148 lines (121 loc) · 4.75 KB
/
bot - ethermine - multi.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
import discord
from discord.ext import tasks, commands
import asyncpg
import json
import requests
import imgkit
import GPUtil
from tabulate import tabulate
import numpy as np
import cv2
import pyautogui
import os
# insert your bot key here, get one from discord
key = 'key'
# channel to send updates and notifications to
notification_channel = 825054534044090408
# pool hash check, reboot if hash lower than desired_hash times_to_check times in a row
check_enabled = True
address = "696b18d7e003be5b4d1a66b981313e1959d69066"
desired_hash = 169000000
times_to_check = 3
worker_name = "worker001" # I don't think it's case sensitive
# do not change
low_hash = 0
startup = True
ping_data = {
"id": 1,
"jsonrpc": "2.0",
"method": "miner_getstatdetail"
}
data_json = json.dumps(ping_data)
payload = {'json_payload': data_json}
class MyClient(discord.Client):
async def on_ready(self):
global low_hash
low_hash = 0
print('Logged on as', self.user)
channel = client.get_channel(notification_channel)
await channel.send(f'Reboot Detected!')
async def on_message(self, message):
# don't respond to ourselves
# if message.author == self.user:
# return
if message.content == f'{worker_name} reboot':
print("REBOOTING")
os.system("shutdown -t 0 -r")
return
if message.content == f'{worker_name} force reboot':
print("REBOOTING")
os.system("shutdown -t 0 -r -f")
return
if message.content == f'{worker_name} screenshot':
image = pyautogui.screenshot()
image = cv2.cvtColor(np.array(image),cv2.COLOR_RGB2BGR)
# writing it to the disk using opencv
cv2.imwrite("screen.png", image)
await message.channel.send(file=discord.File('screen.png'))
return
if message.content == f'{worker_name} ping':
r = requests.get('http://127.0.0.1:3333', data=payload)
html_file = open("temp.html", "w")
html_file.write(r.text)
html_file.close()
imgkit.from_file('temp.html', 'out.jpg')
await message.channel.send(file=discord.File('out.jpg'))
# Ethminer API doesn't report temperature for me for some reason
# this is a backup method (only works for nvidia)
await message.channel.send("="*40+"GPU Details"+"="*40)
gpus = GPUtil.getGPUs()
list_gpus = []
for gpu in gpus:
gpu_id = gpu.id
gpu_name = gpu.name
gpu_load = f"{gpu.load*100}%"
gpu_temperature = f"{gpu.temperature} °C"
list_gpus.append([
gpu_name, gpu_temperature, gpu_load])
output = ("```" + "\n\n" + tabulate(list_gpus, tablefmt="plain", headers=["GPU", "Temps","Load"]) + "```")
await message.channel.send(output)
return
@tasks.loop(minutes = 10)
async def check_hashrate():
global low_hash, startup
channel = client.get_channel(notification_channel)
try:
await channel.send("ping")
r = requests.get(f'https://api.ethermine.org/miner/:{address}/workers')
found_worker = False
for worker in r.json()["data"]:
if worker["worker"] == worker_name:
if worker["reportedHashrate"] < desired_hash:
low_hash+=1
current_hash = worker["reportedHashrate"]
print(f"low hash detected: {current_hash}, {low_hash} times")
if low_hash >= times_to_check:
await channel.send(f"@everyone {worker_name} hash too low: {current_hash}, rebooting")
await channel.send("screenshot")
os.system("shutdown -t 10 -r")
return
else:
await channel.send(f"{worker_name} low hash warning: {current_hash}")
else:
low_hash = 0
found_worker = True
startup = False
break
if found_worker == False and startup == False:
await channel.send(f"{worker_name} not found on pool, rebooting")
await channel.send("screenshot")
os.system("shutdown -t 10 -r")
elif startup == True:
startup = False
except requests.ConnectionError:
print("error, no internet")
except AttributeError:
print("not logged on yet")
if check_enabled:
check_hashrate.add_exception_type(asyncpg.PostgresConnectionError)
check_hashrate.start()
client = MyClient()
client.run(key)