~ehmry/nim_tox

C Tox core wrapper
Add sugar for sendChunk
Use Tox header for all imports, especially enums
Add foreignDeps metadata

refs

master
browse log
v0.2.0
release notes

clone

read-only
https://git.sr.ht/~ehmry/nim_tox
read/write
git@git.sr.ht:~ehmry/nim_tox

You can also use your local clone with git send-email.

Nim wrapper over the Toxcore library

import toxcore

from std/os import sleep

const
  bootstrapHost = "tox.neuland.technology"
  bootstrapKey = "15E9C309CFCB79FDDF0EBA057DABB49FE15F3803B1BFF06536AE2E5BA5E4690E".toPublicKey

proc setupCallbacks(bot: Tox) =
  var echoCount = 0
    # bind a value for callback closure magic

  bot.onFriendRequest do (pk: PublicKey; msg: string):
    discard bot.addFriendNoRequest(pk)

  bot.onFriendMessage do (f: Friend; msg: string; kind: TOX_MESSAGE_TYPE):
    discard bot.send(f, msg, kind)
    inc echoCount
    bot.statusMessage = $echoCount & " echos served "

proc newEchoBot(name: string): Tox =
  result = newTox()
  result.name = name
  result.setupCallbacks()
  result.bootstrap(bootstrapHost, bootstrapKey)
  echo result.name, " echos messages to ", result.address
  echo result.name, " joins DHT with port ", result.udpPort, " address ", result.dhtId

let
  a = newEchoBot "alice"
  b = newEchoBot "bob"
while true:
  iterate a
  iterate b
  sleep min(a.iterationInterval, b.iterationInterval)