Merge pull request #157 from NebulousLabs/update-bots

Update bots
This commit is contained in:
Marcin Jachymiak 2020-04-14 15:32:52 -04:00 committed by GitHub
commit 2715ab1e9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View File

@ -9,7 +9,8 @@ import urllib, json, os, traceback, discord, sys
# sc_precision is the number of hastings per siacoin # sc_precision is the number of hastings per siacoin
sc_precision = 10 ** 24 sc_precision = 10 ** 24
channel_name = "skynet-portal-health-check" CHANNEL_NAME = "skynet-portal-health-check"
ROLE_NAME = "skynet-prod"
# Environment variable globals # Environment variable globals
api_endpoint, port, portal_name, bot_token, password = None, None, None, None, None api_endpoint, port, portal_name, bot_token, password = None, None, None, None, None
@ -50,21 +51,28 @@ async def send_msg(client, msg, force_notify=False, file=None):
await client.wait_until_ready() await client.wait_until_ready()
guild = client.guilds[0] guild = client.guilds[0]
channels = guild.channels
chan = None chan = None
for c in channels: for c in guild.channels:
if c.name == channel_name: if c.name == CHANNEL_NAME:
chan = c chan = c
break
if chan is None: if chan is None:
print("Can't find channel {}".format(channel_name)) print("Can't find channel {}".format(CHANNEL_NAME))
# Get the prod team role
role = None
for r in guild.roles:
if r.name == ROLE_NAME:
role = r
break
# Add the portal name. # Add the portal name.
msg = "`{}`: {}".format(portal_name, msg) msg = "`{}`: {}".format(portal_name, msg)
if force_notify: if force_notify:
msg = "@here: \n{}".format(msg) msg = "{}: \n{}".format(role.mention, msg)
await chan.send(msg, file=file) await chan.send(msg, file=file)

View File

@ -56,12 +56,13 @@ async def check_health():
# Send an alert if there is less than 1 allowance worth of money left. # Send an alert if there is less than 1 allowance worth of money left.
if balance < allowance_funds: if balance < allowance_funds:
await send_msg(client, "Wallet balance running low. \n{}`".format(balance_msg), force_notify=True) await send_msg(client, "Wallet balance running low. \n{}".format(balance_msg), force_notify=True)
return return
# Alert devs when 1/2 the allowance is gone # Alert devs when only a fraction of the allowance is remaining.
if allocated_funds >= unallocated_funds: UNALLOC_THRESHOLD = 0.2
await send_msg(client, "Allowance half spent: \n{}".format(alloc_msg), force_notify=True) if allocated_funds >= UNALLOC_THRESHOLD * allowance_funds :
await send_msg(client, "{} of allowance spent: \n{}".format(UNALLOC_THRESHOLD, alloc_msg), force_notify=True)
return return
# Send an informational heartbeat if all checks passed. # Send an informational heartbeat if all checks passed.