-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev #387
Merged
Dev #387
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
da38a40
rm old testcoins from faucet
smk762 2c6accd
merge master
smk762 a84fb9f
Merge pull request #386 from smk762/master
smk762 53ce4b6
use latest python
smk762 18f6618
add memcached
smk762 999021c
rm sidebar links
smk762 3221787
rename things for clarity
smk762 e097174
rename items in front end
smk762 ad5e107
speed up context data sourcing
smk762 3b7652c
optimise home screen load speed
smk762 651b894
caching
smk762 9bcfa62
Merge branch 'master' into dev
smk762 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,5 @@ | ||
FROM python:3 | ||
|
||
RUN mkdir /alerts | ||
WORKDIR /alerts | ||
COPY ./ /alerts/ |
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,53 @@ | ||
#!/usr/bin/env python3 | ||
import time | ||
import discord | ||
import asyncio | ||
from config import ALERT_INTERVAL, DISCORD_CHANNEL, DISCORD_TOKEN | ||
from models import NotaryMonitor | ||
|
||
class MyClient(discord.Client): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.sauron = NotaryMonitor() | ||
|
||
async def setup_hook(self) -> None: | ||
# create the background task and run it in the background | ||
self.bg_task = self.loop.create_task(self.process_alerts()) | ||
|
||
async def on_ready(self): | ||
print(f'Logged in as {self.user} (ID: {self.user.id})') | ||
print('------') | ||
|
||
async def process_alerts(self): | ||
await self.wait_until_ready() | ||
print('Logged in as') | ||
print(self.user.name) | ||
print(self.user.id) | ||
print('------') | ||
channel = self.get_channel(DISCORD_CHANNEL) | ||
while not self.is_closed(): | ||
|
||
try: | ||
loop = 0 | ||
while True: | ||
msg = self.sauron.alert_slow_miners() | ||
if msg != "": | ||
# await self.channel.send(msg) | ||
print(msg) | ||
break | ||
|
||
if loop > 12: | ||
await channel.send(f"<@448777271701143562> Mining endpoint not responding!\n") | ||
break | ||
time.sleep(60) | ||
loop += 1 | ||
|
||
except Exception as e: | ||
await channel.send(f"<@448777271701143562> Mining endpoint not responding!\n{e}") | ||
await asyncio.sleep(ALERT_INTERVAL) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
client = MyClient(intents=discord.Intents.default()) | ||
client.run(DISCORD_TOKEN) |
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,13 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
load_dotenv() | ||
|
||
ALERT_INTERVAL = 60*60*8 # 8 hours | ||
try: | ||
DISCORD_CHANNEL = int(os.getenv('DISCORD_CHANNEL')) | ||
except: | ||
print("You need to add 'DISCORD_CHANNEL' to .env file") | ||
|
||
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN') | ||
if DISCORD_TOKEN is None: | ||
print("You need to add 'DISCORD_TOKEN' to .env file") |
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,66 @@ | ||
NN_DISCORD_IDS = { | ||
"colmapol_EU": "", | ||
"alien_NA": "412323938782150658", | ||
"alien_EU": "412323938782150658", | ||
"alien_SH": "412323938782150658", | ||
"alienx_NA": "412323938782150658", | ||
"alright_EU": "405011811511828481", | ||
"alright_DEV": "405011811511828481", | ||
"artem.pikulin_AR": "457121878465708043", | ||
"batman_AR": "407288940148555786", | ||
"blackice2_AR": "345544724167524352", | ||
"blackice_AR": "345544724167524352", | ||
"blackice_EU": "345544724167524352", | ||
"blackice_NA": "345544724167524352", | ||
"blackice_DEV": "345544724167524352", | ||
"ca333_EU": "375074477756645386", | ||
"caglarkaya_EU": "689469673343156323", | ||
"mcrypt_SH": "458507065178980353", | ||
"chmex2_SH": "420119978138664961", | ||
"chmex_AR": "420119978138664961", | ||
"chmex_EU": "420119978138664961", | ||
"chmex_NA": "420119978138664961", | ||
"chmex_SH": "420119978138664961", | ||
"cipi_AR": "419964976397156352", | ||
"cipi_EU": "419964976397156352", | ||
"cipi_NA": "419964976397156352", | ||
"computergenie2_NA": "474206298427097099", | ||
"computergenie_EU": "474206298427097099", | ||
"computergenie_NA": "474206298427097099", | ||
"dimxy_AR": "507209916449292303", | ||
"dimxy_DEV": "507209916449292303", | ||
"dragonhound_AR": "448777271701143562", | ||
"dragonhound_EU": "448777271701143562", | ||
"dragonhound_NA": "448777271701143562", | ||
"dragonhound_DEV": "448777271701143562", | ||
"emmaccen_DEV": "933467505886904370", | ||
"fediakash_AR": "803217186792800326", | ||
"gcharang_AR": "423176312354635779", | ||
"gcharang_SH": "423176312354635779", | ||
"gcharang_DEV": "423176312354635779", | ||
"kmdude_SH": "829743507433979904", | ||
"marmara_AR": "409990217047474176", | ||
"marmara_EU": "409990217047474176", | ||
"nodeone2_NA": "474206298427097099", | ||
"nodeone_NA": "474206298427097099", | ||
"ozkanonur_NA": "147806685015179267", | ||
"pbca26_NA": "403229823834521616", | ||
"pbca26_SH": "403229823834521616", | ||
"phit_SH": "352577127494713345", | ||
"ptyx_SH": "303794669945618442", | ||
"shamardy_SH": "729091988565131295", | ||
"sheeba2_SH": "288941564263268353", | ||
"sheeba_SH": "288941564263268353", | ||
"smdmitry2_AR": "486144655369437184", | ||
"smdmitry_AR": "486144655369437184", | ||
"smdmitry_EU": "486144655369437184", | ||
"smdmitry_SH": "486144655369437184", | ||
"strob_SH": "278565047113089025", | ||
"tonyl_AR": "272003866906722306", | ||
"tonyl_DEV": "272003866906722306", | ||
"van_EU": "", | ||
"webworker01_EU": "300741339279130624", | ||
"webworker01_NA": "300741339279130624", | ||
"who-biz_NA": "402649850241482752", | ||
"yurri-khi_DEV": "668742126992883714" | ||
} |
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,40 @@ | ||
import time | ||
import datetime | ||
import requests | ||
from contacts import NN_DISCORD_IDS | ||
|
||
class NotaryMonitor(): | ||
def __init__(self): | ||
pass | ||
|
||
def get_last_mined(self): | ||
try: | ||
r = requests.get("https://stats.kmd.io/api/mining/notary_last_mined_table/") | ||
return r.json()["results"] | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
print(f"Response: {r.content}") | ||
return {} | ||
|
||
def alert_slow_miners(self): | ||
msg = "" | ||
data = self.get_last_mined() | ||
now = int(time.time()) | ||
threshold = now - 4 * 60 * 60 # 4 hours | ||
slow_miners = {} | ||
[ | ||
slow_miners.update({ | ||
i["name"]: datetime.timedelta(seconds=now - i["blocktime"]) | ||
}) | ||
for i in data | ||
if i["blocktime"] < threshold | ||
] | ||
|
||
if len(slow_miners) > 1: | ||
msg = "**The following Notaries have not mined a block recently...**\n" | ||
for notary in slow_miners: | ||
if NN_DISCORD_IDS[notary] == "": | ||
msg += f"{notary} (last mined {slow_miners[notary]} ago)\n" | ||
else: | ||
msg += f"{NN_DISCORD_IDS[notary]} ({notary} last mined {slow_miners[notary]} ago)\n" | ||
return msg |
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 @@ | ||
discord.py==2.3.2 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f-string is unnecessary here. This can just be a string. More.