summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/irc.nim30
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/pure/irc.nim b/lib/pure/irc.nim
index 9e4396869..5a4c815f6 100644
--- a/lib/pure/irc.nim
+++ b/lib/pure/irc.nim
@@ -159,12 +159,26 @@ proc parseMessage(msg: string): TIRCEvent =
   if msg[i] == ':':
     inc(i) # Skip `:`.
     result.params.add(msg[i..msg.len-1])
+
+proc connect*(irc: var TIRC) =
+  ## Connects to an IRC server as specified by ``irc``.
+  assert(irc.address != "")
+  assert(irc.port != TPort(0))
   
+  irc.sock = socket()
+  irc.sock.connect(irc.address, irc.port)
+  
+  # Greet the server :)
+  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
@@ -176,18 +190,7 @@ proc irc*(address: string, port: TPort = 6667.TPort,
   result.lag = -1.0
   result.channelsToJoin = joinChans
 
-proc connect*(irc: var TIRC) =
-  ## Connects to an IRC server as specified by ``irc``.
-  assert(irc.address != "")
-  assert(irc.port != TPort(0))
-  
-  irc.sock = socket()
-  irc.sock.connect(irc.address, irc.port)
-  
-  # Greet the server :)
-  if irc.serverPass != "": irc.send("PASS " & irc.serverPass)
-  irc.send("NICK " & irc.nick)
-  irc.send("USER $1 * 0 :$2" % [irc.user, irc.realname])
+  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):