Twitch IRC with PHP Socket

Hiya,

I’m working on creating a Twitch chatbot within PHP and I’ve hit a hurdle with receiving any responses from the Twitch IRC.

As far as I am aware I am connecting successfully with the Twitch IRC server and sending some PASS/NICK commands. However, I’m receiving no data back from the IRC server, not even the MOTD that I should get after PASS/NICK commands.

I am developing this on my local environment using Docker. This app is also a fresh Laravel app.

Below is my workflow to initialise the PHP socket.

public function connect()
    {
        $tcpConnector = new TcpConnector($this->loop);
        $dnsResolverFactory = new Factory();
        $dns = $dnsResolverFactory->createCached('1.1.1.1', $this->loop);
        $dnsConnector = new DnsConnector($tcpConnector, $dns);
        $connectorPromise = $dnsConnector->connect(sprintf('%s:6667', $this->host));

        $connectorPromise->then(function (ConnectionInterface $connection) {
            $this->socket = $connection;
            $this->isConnected = true;

            Log::info("Connected to the following IRC Server : {$this->socket->getRemoteAddress()}");

            $this->socket->on('data', function ($data) {
                Log::info("[>] $data");
            });

            $this->chatSend('CAP REQ :twitch.tv/membership twitch.tv/tags');
            $this->chatSend("PASS oauth:$this->oAuth");
            $this->chatSend("NICK $this->nick");
        }, function (\Exception $error) {
            Log::info($error);
        });

        $this->loop->run();
    }

Here is an example log of this connect function.

[2024-07-21 09:02:54] local.INFO: Connected to the following IRC Server : 34.212.92.60:6667  
[2024-07-21 09:02:54] local.INFO: [<] CAP REQ :twitch.tv/membership twitch.tv/tags
 (1)  
[2024-07-21 09:02:54] local.INFO: [<] PASS oauth:2xik66orlt3a******************
 (1)  
[2024-07-21 09:02:54] local.INFO: [<] NICK bakersoftware
 (1)  

Any tips/advice would be helpful :slight_smile:

Save yourself a bunch of faff and use a library called SmartIRC

When I did my bots in php I modified it manually for IRCv3 support. But I don’t think I have a copy of that kicking around. But should be straight forward to apply manually yourself. Just refer to the iirc specification.

Thanks Barry,

Will give that a go

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.