Migrated from tutorial-sockets v3
This commit is contained in:
parent
bec1d30c93
commit
4cc3d25850
|
@ -6,7 +6,8 @@ After that you can use <code>s.connect("addr", TPort(80))</code> to connect to a
|
|||
Once you connect to a server, you can send and receive messages to/from the server by using <code>s.send("Message")</code> to send, and <code>s.recv()</code> to receive.
|
||||
== Examples ==
|
||||
=== IRC Bot ===
|
||||
<pre><nowiki>import sockets, strutils
|
||||
<pre><nowiki>
|
||||
import sockets, strutils
|
||||
|
||||
when not defined(strutils.toStringSep):
|
||||
proc toStringSep(x: int64): string =
|
||||
|
@ -53,18 +54,19 @@ while True:
|
|||
s.send("JOIN #nimrod\c\L")
|
||||
if data.split()[1] == "PRIVMSG":
|
||||
if data.split()[3] == ":!about":
|
||||
var msg: string = "NimrodBot 0.1 compiled on " & CompileDate & " " & CompileTime
|
||||
msg = msg & " running on " & hostOS
|
||||
var msg = "NimrodBot 0.1 compiled on " & CompileDate & " " & CompileTime
|
||||
msg.add(" running on " & hostOS)
|
||||
s.send("PRIVMSG " & data.split()[2] & " :" & msg & "\c\L")
|
||||
|
||||
elif data.split()[3] == ":!mem":
|
||||
var msg: string = "Occupied memory: " & formatSize(int64(getOccupiedMem()))
|
||||
var msg = "Occupied memory: " & formatSize(int64(getOccupiedMem()))
|
||||
s.send("PRIVMSG " & data.split()[2] & " :" & msg & "\c\L")
|
||||
|
||||
elif data.split()[3] == ":!freemem":
|
||||
var msg: string = "Free memory: " & formatSize(int64(getFreeMem()))
|
||||
var msg = "Free memory: " & formatSize(int64(getFreeMem()))
|
||||
s.send("PRIVMSG " & data.split()[2] & " :" & msg & "\c\L")
|
||||
|
||||
elif data.split()[3] == ":!totalmem":
|
||||
var msg: string = "Total memory: " & formatSize(int64(getTotalMem()))
|
||||
s.send("PRIVMSG " & data.split()[2] & " :" & msg & "\c\L")</nowiki></pre>
|
||||
var msg = "Total memory: " & formatSize(int64(getTotalMem()))
|
||||
s.send("PRIVMSG " & data.split()[2] & " :" & msg & "\c\L")
|
||||
</nowiki></pre>
|
||||
|
|
Loading…
Reference in New Issue