Skip to content

Instantly share code, notes, and snippets.

@keyle
Created January 9, 2015 12:41
Show Gist options
  • Select an option

  • Save keyle/46337a707c23492c7e11 to your computer and use it in GitHub Desktop.

Select an option

Save keyle/46337a707c23492c7e11 to your computer and use it in GitHub Desktop.
zxczcx
import irc, asyncdispatch, strutils, os, threadpool
proc onIrcEvent(client: PAsyncIrc, event: TIrcEvent) {.async.} =
case event.typ
of EvConnected:
discard
of EvDisconnected, EvTimeout:
await client.reconnect()
of EvMsg:
if event.cmd == MPrivMsg:
let msg = event.params[event.params.high]
if msg == "!quit":
quit()
if msg == "!test":
await client.privmsg(event.origin, "hey")
if msg == "!lag":
await client.privmsg(event.origin, formatFloat(client.getLag))
if msg == "!users":
await client.privmsg(event.origin, "Users: " & client.getUserList(event.origin).join(", "))
if msg == "!excessFlood":
for i in 0..10:
await client.privmsg(event.origin, "TEST" & $i)
echo(event.raw)
elif event.cmd == MPing:
discard
elif event.cmd == MPong:
discard
else:
echo(event.raw)
proc launchClient() {.async.} =
var client = newAsyncIrc(address = "roddenberry.freenode.net", nick = "Blend0r", user = "test", realname = "Mr. Test", joinChans = @["#teasdst"], callback = onIrcEvent)
asyncCheck client.run()
var t = spawn launchClient()
while true:
echo "~ " & readLine(stdin)
#runForever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment