Created
January 9, 2015 12:41
-
-
Save keyle/46337a707c23492c7e11 to your computer and use it in GitHub Desktop.
zxczcx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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