$SERVER = "irc.hackthissite.org" $PORT = 6667 $NICK = "MonadBot" $NICKSERV_PASS = "..." $sock = new-object System.Net.Sockets.TcpClient($SERVER, $PORT); $stream = $sock.GetStream(); $reader = new-object System.IO.StreamReader($stream); $writer = new-object System.IO.StreamWriter($stream); function SendCommand($Command) { echo "--> Command" $writer.WriteLine($Command) $writer.Flush() } function PrivMessage([string] $To, [string] $Message) { SendCommand ("PRIVMSG " + $To + " :" + $Message) } function CheckPing([string] $Line) { if ($Line.StartsWith("PING :")) { SendCommand ("PONG :" + $Line.SubString(6)) [bool] 1 } [bool] 0 } function HandleCommand([string] $Line) { if ($Line -match "^:(?[^!\s]+)(!(?\S+))?\s(?\S+)(\s(?.+))?") { if ($matches["command"] -eq "001") { if ($NICKSERV_PASS -ne "") { SendCommand ("PRIVMSG NickServ IDENTIFY " + $NICKSERV_PASS) SendCommand "PRIVMSG HostServ ON" } SendCommand "JOIN #bots" } elseif ($matches["command"] -eq "PRIVMSG") { $replyTo = $matches["nick"] if ($matches["arguments"] -match "^(?.+)\s:(\!say\s(?.+))") { if (($matches["to"][0]) -eq '#') { $replyTo = $matches["to"] } PrivMessage $replyTo $matches["message"] } } } } SendCommand "USER bla bla bla :bla" SendCommand ("NICK " + $NICK) while (1) { $line = $reader.ReadLine() echo "<-- $line" if (!(CheckPing $line)) { HandleCommand $line } }