Skip to content

Commit

Permalink
now periodically pings
Browse files Browse the repository at this point in the history
also fixed AttributeError bug that occurs when the checker tries to send a warning before the bot has logged on
  • Loading branch information
o4ugDF54PlqU committed May 9, 2021
1 parent ace884b commit 4ce0c74
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions bot - ethermine - multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ 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

Expand All @@ -114,9 +115,8 @@ async def check_hashrate():
current_hash = worker["reportedHashrate"]
print(f"low hash detected: {current_hash}, {low_hash} times")
if low_hash >= times_to_check:
await channel.send(f"{worker_name} hash too low: {current_hash}")
await channel.send(f"@everyone {worker_name} hash too low: {current_hash}, rebooting")
await channel.send("screenshot")
await channel.send("ping")
os.system("shutdown -t 10 -r")
return
else:
Expand All @@ -130,13 +130,14 @@ async def check_hashrate():
if found_worker == False and startup == False:
await channel.send(f"{worker_name} not found on pool, rebooting")
await channel.send("screenshot")
await channel.send("ping")
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)
Expand Down
7 changes: 4 additions & 3 deletions bot - ethermine.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ 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

Expand All @@ -114,9 +115,8 @@ async def check_hashrate():
current_hash = worker["reportedHashrate"]
print(f"low hash detected: {current_hash}, {low_hash} times")
if low_hash >= times_to_check:
await channel.send(f"hash too low: {current_hash}")
await channel.send(f"@everyone hash too low: {current_hash}, rebooting")
await channel.send("screenshot")
await channel.send("ping")
os.system("shutdown -t 10 -r")
return
else:
Expand All @@ -130,13 +130,14 @@ async def check_hashrate():
if found_worker == False and startup == False:
await channel.send("worker not found on pool, rebooting")
await channel.send("screenshot")
await channel.send("ping")
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)
Expand Down
7 changes: 4 additions & 3 deletions bot - hiveon - multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async def check_hashrate():
global low_hash, startup
channel = client.get_channel(notification_channel)
try:
await channel.send("ping")
r = requests.get(f'https://hiveon.net/api/v1/stats/miner/{address}/ETH/workers')
worker_data = r.json()["workers"][worker_name]

Expand All @@ -109,9 +110,8 @@ async def check_hashrate():
current_hash = r.json()["reportedHashrate"]
print(f"low hash detected: {current_hash}, {low_hash} times")
if low_hash >= times_to_check:
await channel.send(f"{worker_name} hash too low: {current_hash}")
await channel.send(f"@everyone {worker_name} hash too low: {current_hash}, rebooting")
await channel.send("screenshot")
await channel.send("ping")
os.system("shutdown -t 10 -r")
return
else:
Expand All @@ -131,8 +131,9 @@ async def check_hashrate():
print("not in pool")
await channel.send(f"{worker_name} worker not found on pool, rebooting")
await channel.send("screenshot")
await channel.send("ping")
os.system("shutdown -t 10 -r")
except AttributeError:
print("not logged on yet")

if check_enabled:
check_hashrate.add_exception_type(asyncpg.PostgresConnectionError)
Expand Down
7 changes: 4 additions & 3 deletions bot - hiveon.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async def check_hashrate():
global low_hash, startup
channel = client.get_channel(notification_channel)
try:
await channel.send("ping")
r = requests.get(f'https://hiveon.net/api/v1/stats/miner/{address}/ETH/workers')
worker_data = r.json()["workers"][worker_name]

Expand All @@ -109,9 +110,8 @@ async def check_hashrate():
current_hash = r.json()["reportedHashrate"]
print(f"low hash detected: {current_hash}, {low_hash} times")
if low_hash >= times_to_check:
await channel.send(f"hash too low: {current_hash}")
await channel.send(f"@everyone hash too low: {current_hash}, rebooting")
await channel.send("screenshot")
await channel.send("ping")
os.system("shutdown -t 10 -r")
return
else:
Expand All @@ -131,8 +131,9 @@ async def check_hashrate():
print("not in pool")
await channel.send("worker not found on pool, rebooting")
await channel.send("screenshot")
await channel.send("ping")
os.system("shutdown -t 10 -r")
except AttributeError:
print("not logged on yet")

if check_enabled:
check_hashrate.add_exception_type(asyncpg.PostgresConnectionError)
Expand Down

0 comments on commit 4ce0c74

Please sign in to comment.