Catch errors during update, print DHT info

This commit is contained in:
Ehmry - 2019-12-18 04:07:36 +00:00
parent b862e5f794
commit 5a6d42f28e
1 changed files with 15 additions and 7 deletions

View File

@ -42,19 +42,27 @@ proc newBot(name: string): Tox =
echo result.name, " is at ", result.address
proc updateStatus(bot: Tox; http: AsyncHttpClient) {.async.} =
let
rsp = await http.get(spaceApiUrl)
body = await rsp.body
space = parseJson body
status = $(space["status"])
if bot.statusMessage != status:
bot.statusMessage = $(space["status"])
try:
let
rsp = await http.get(spaceApiUrl)
body = await rsp.body
space = parseJson body
status = $(space["status"])
if bot.statusMessage != status:
echo "change status to ", status
bot.statusMessage = $(space["status"])
except:
echo "status update failed"
proc main() =
let
bot = newBot("HQ Bot")
http = newAsyncHttpClient()
echo "DHT port and key: ", bot.udpPort, " ", bot.dhtId
waitFor updateStatus(bot, http)
addTimer(20*1000, oneshot=false) do (fd: AsyncFD) -> bool:
asyncCheck updateStatus(bot, http)