Catch errors during update, print DHT info
This commit is contained in:
parent
b862e5f794
commit
5a6d42f28e
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue