From 4896f631297f49a38749cf4bb76df749967be370 Mon Sep 17 00:00:00 2001 From: dom96 Date: Sun, 4 Sep 2011 20:28:32 +0100 Subject: [PATCH] Some improvements relating to the IRC module. --- doc/lib.txt | 4 +++- lib/pure/irc.nim | 38 ++++++++++++++++++++------------------ web/news.txt | 1 + web/nimrod.ini | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/doc/lib.txt b/doc/lib.txt index ddfaaf46cf..0b30056ee7 100755 --- a/doc/lib.txt +++ b/doc/lib.txt @@ -177,7 +177,9 @@ Internet Protocols and Support * `smtp `_ This module implement a simple SMTP client. - + +* `irc `_ + This module implements an asynchronous IRC client. Parsers ------- diff --git a/lib/pure/irc.nim b/lib/pure/irc.nim index 9e43968691..5a4c815f6c 100644 --- a/lib/pure/irc.nim +++ b/lib/pure/irc.nim @@ -159,22 +159,6 @@ proc parseMessage(msg: string): TIRCEvent = if msg[i] == ':': inc(i) # Skip `:`. result.params.add(msg[i..msg.len-1]) - -proc irc*(address: string, port: TPort = 6667.TPort, - nick = "NimrodBot", - user = "NimrodBot", - realname = "NimrodBot", serverPass = "", - joinChans: seq[string] = @[]): TIRC = - result.address = address - result.port = port - result.nick = nick - result.user = user - result.realname = realname - result.serverPass = serverPass - result.lastPing = epochTime() - result.lastPong = -1.0 - result.lag = -1.0 - result.channelsToJoin = joinChans proc connect*(irc: var TIRC) = ## Connects to an IRC server as specified by ``irc``. @@ -188,6 +172,25 @@ proc connect*(irc: var TIRC) = if irc.serverPass != "": irc.send("PASS " & irc.serverPass) irc.send("NICK " & irc.nick) irc.send("USER $1 * 0 :$2" % [irc.user, irc.realname]) + +proc irc*(address: string, port: TPort = 6667.TPort, + nick = "NimrodBot", + user = "NimrodBot", + realname = "NimrodBot", serverPass = "", + joinChans: seq[string] = @[]): TIRC = + ## This function calls `connect`, so you don't need to. + result.address = address + result.port = port + result.nick = nick + result.user = user + result.realname = realname + result.serverPass = serverPass + result.lastPing = epochTime() + result.lastPong = -1.0 + result.lag = -1.0 + result.channelsToJoin = joinChans + + result.connect() proc poll*(irc: var TIRC, ev: var TIRCEvent, timeout: int = 500): bool = @@ -236,8 +239,7 @@ proc getLastPong*(irc: var TIRC): float = return irc.lastPong when isMainModule: - var client = irc("irc.freenode.net",joinChans = @["#nimrod"]) - client.connect() + var client = irc("irc.freenode.net", nick="TestBot", joinChans = @["#nimrod"]) while True: var event: TIRCEvent if client.poll(event): diff --git a/web/news.txt b/web/news.txt index bb1bbec493..bd2d970d21 100755 --- a/web/news.txt +++ b/web/news.txt @@ -73,6 +73,7 @@ Library Additions - Added ``xmltree.innerText``. - Added ``os.isAbsolute``. - Added ``locks`` core module for more flexible locking support. +- Added ``irc`` module. 2011-07-10 Version 0.8.12 released diff --git a/web/nimrod.ini b/web/nimrod.ini index c56b8bb843..93fa0bfc2b 100755 --- a/web/nimrod.ini +++ b/web/nimrod.ini @@ -41,7 +41,7 @@ srcdoc: "pure/json;pure/base64;pure/scgi;pure/redis;impure/graphics" srcdoc: "impure/rdstdin;wrappers/zmq;wrappers/sphinx" srcdoc: "pure/collections/tables;pure/collections/sets;pure/collections/lists" srcdoc: "pure/collections/intsets;pure/collections/queues;pure/encodings" -srcdoc: "pure/events;pure/collections/sequtils" +srcdoc: "pure/events;pure/collections/sequtils;pure/irc" webdoc: "wrappers/libcurl;pure/md5;wrappers/mysql;wrappers/iup" webdoc: "wrappers/sqlite3;wrappers/postgres;wrappers/tinyc"