From 5a6d42f28e91386d277b6e4cad3bae1d400df57c Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 18 Dec 2019 04:07:36 +0000 Subject: [PATCH] Catch errors during update, print DHT info --- src/hqtoxbot.nim | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/hqtoxbot.nim b/src/hqtoxbot.nim index c9678cb..ab81871 100644 --- a/src/hqtoxbot.nim +++ b/src/hqtoxbot.nim @@ -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)