PHPDaemon\Examples\ExampleIRCBot::connect PHP Method

connect() public method

public connect ( )
    public function connect()
    {
        $app = $this;
        $r = $this->client->getConnection($this->config->url->value, function ($conn) use($app) {
            $app->conn = $conn;
            if ($conn->connected) {
                \PHPDaemon\Core\Daemon::log('IRC bot connected at ' . $this->config->url->value);
                $conn->join('#botwar_phpdaemon');
                $conn->bind('motd', function ($conn) {
                    //\PHPDaemon\Daemon::log($conn->motd);
                });
                $conn->bind('privateMsg', function ($conn, $msg) {
                    \PHPDaemon\Core\Daemon::log('IRCBot: got private message \'' . $msg['body'] . '\' from \'' . $msg['from']['orig'] . '\'');
                    $conn->message($msg['from']['nick'], 'You just wrote: ' . $msg['body']);
                    // send the message back
                });
                $conn->bind('disconnect', function () use($app) {
                    $app->connect();
                });
            } else {
                \PHPDaemon\Core\Daemon::log('IRCBot: unable to connect (' . $this->config->url->value . ')');
            }
        });
    }