All pastes #752326 Raw Edit

Mine

public text v1 · immutable
#752326 ·published 2007-10-28 09:37 UTC
rendered paste body
$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 "^:(?<nick>[^!\s]+)(!(?<hostname>\S+))?\s(?<command>\S+)(\s(?<arguments>.+))?")
    {
        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 "^(?<to>.+)\s:(\!say\s(?<message>.+))")
            {
                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 }
}