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
|
echo result.name, " is at ", result.address
|
||||||
|
|
||||||
proc updateStatus(bot: Tox; http: AsyncHttpClient) {.async.} =
|
proc updateStatus(bot: Tox; http: AsyncHttpClient) {.async.} =
|
||||||
let
|
try:
|
||||||
rsp = await http.get(spaceApiUrl)
|
let
|
||||||
body = await rsp.body
|
rsp = await http.get(spaceApiUrl)
|
||||||
space = parseJson body
|
body = await rsp.body
|
||||||
status = $(space["status"])
|
space = parseJson body
|
||||||
if bot.statusMessage != status:
|
status = $(space["status"])
|
||||||
bot.statusMessage = $(space["status"])
|
if bot.statusMessage != status:
|
||||||
|
echo "change status to ", status
|
||||||
|
bot.statusMessage = $(space["status"])
|
||||||
|
except:
|
||||||
|
echo "status update failed"
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
let
|
let
|
||||||
bot = newBot("HQ Bot")
|
bot = newBot("HQ Bot")
|
||||||
http = newAsyncHttpClient()
|
http = newAsyncHttpClient()
|
||||||
|
|
||||||
|
echo "DHT port and key: ", bot.udpPort, " ", bot.dhtId
|
||||||
|
|
||||||
|
waitFor updateStatus(bot, http)
|
||||||
|
|
||||||
addTimer(20*1000, oneshot=false) do (fd: AsyncFD) -> bool:
|
addTimer(20*1000, oneshot=false) do (fd: AsyncFD) -> bool:
|
||||||
asyncCheck updateStatus(bot, http)
|
asyncCheck updateStatus(bot, http)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue