penelope
created pr with
114.1
added 114.2
1: 3c7cbc2 = 1: 3c7cbc2 convert to environment variables
-: ------- > 2: 5798fe8 change port env name to avoid collision
cmds
checkout latest patchset:
ssh pr.pico.sh print 114 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 114.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 114
Patchset
114.2
change port env name to avoid collision
Melanie Kat
2026-02-25T00:33:44ZSemantic diff summary
0 added,
0 modified,
0 signature changed,
0 removed
across 0 analyzed files
(1 file skipped: unsupported file type)
+50
-52
bot.php
#
| ... | ... | @@ -9,7 +9,7 @@ $nickname = $_ENV["NICKNAME"]; | |
| 9 | 9 | $hostname = $_ENV["HOSTNAME"]; | |
| 10 | 10 | $password = $_ENV["PASSWORD"]; | |
| 11 | 11 | $server = $_ENV["SERVER"]; | |
| 12 | - | $port = $_ENV["PORT"]; | |
| 12 | + | $port = $_ENV["IRCPORT"]; | |
| 13 | 13 | ||
| 14 | 14 | // In order to update the bot's code while it's connected to IRC, we need a separate "functions" script. | |
| 15 | 15 | // This script will receive a stream of the IRC activity, and then it'll "do stuff" and send the response |
| ... | ... | @@ -26,27 +26,27 @@ set_time_limit(0); | |
| 26 | 26 | ||
| 27 | 27 | // Now we'll set up our connection | |
| 28 | 28 | $context = stream_context_create([ | |
| 29 | - | 'ssl' => [ | |
| 30 | - | 'verify_peer' => true, | |
| 31 | - | 'verify_peer_name' => true, | |
| 32 | - | 'allow_self_signed' => false, | |
| 33 | - | 'SNI_enabled' => true, | |
| 34 | - | 'peer_name' => $server, | |
| 35 | - | ], | |
| 29 | + | 'ssl' => [ | |
| 30 | + | 'verify_peer' => true, | |
| 31 | + | 'verify_peer_name' => true, | |
| 32 | + | 'allow_self_signed' => false, | |
| 33 | + | 'SNI_enabled' => true, | |
| 34 | + | 'peer_name' => $server, | |
| 35 | + | ], | |
| 36 | 36 | ]); | |
| 37 | 37 | ||
| 38 | 38 | // And actually connect | |
| 39 | 39 | $socket = stream_socket_client( | |
| 40 | - | "tls://{$server}:{$port}", | |
| 41 | - | $errno, | |
| 42 | - | $errstr, | |
| 43 | - | 30, | |
| 44 | - | STREAM_CLIENT_CONNECT, | |
| 45 | - | $context | |
| 40 | + | "tls://{$server}:{$port}", | |
| 41 | + | $errno, | |
| 42 | + | $errstr, | |
| 43 | + | 30, | |
| 44 | + | STREAM_CLIENT_CONNECT, | |
| 45 | + | $context | |
| 46 | 46 | ); | |
| 47 | 47 | ||
| 48 | - | if(!$socket) { | |
| 49 | - | die("Connection failed: $errstr ($errno)\n"); | |
| 48 | + | if (! $socket) { | |
| 49 | + | die("Connection failed: $errstr ($errno)\n"); | |
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | 52 | // If our code is still running at this point, we're connected to the server! |
| ... | ... | @@ -58,47 +58,45 @@ fputs($socket, "NICK " . $nickname . "\n"); | |
| 58 | 58 | fputs($socket, "USER " . $nickname . " 0 * :$nickname@$hostname\n"); | |
| 59 | 59 | ||
| 60 | 60 | // Send avatar metadata? does this even work? lol | |
| 61 | - | if($avatar_url) { | |
| 62 | - | fputs($socket, "METADATA * SET avatar $avatar_url\n"); | |
| 61 | + | if ($avatar_url) { | |
| 62 | + | fputs($socket, "METADATA * SET avatar $avatar_url\n"); | |
| 63 | 63 | } | |
| 64 | 64 | ||
| 65 | - | ||
| 66 | 65 | // Loopy loop forever and ever and ever | |
| 67 | - | while(1) { | |
| 68 | - | while ($data = fgets($socket, 512)) { | |
| 69 | - | echo $data; | |
| 70 | - | flush(); | |
| 71 | - | ||
| 72 | - | // Take the line of data that we've received and snap it into separate pieces wherever there's a space | |
| 73 | - | $pieces = explode(' ', $data); | |
| 74 | - | ||
| 75 | - | // At this point, $pieces[0] will contain the sender, and $pieces[1] will contain the command that was sent | |
| 76 | - | ||
| 77 | - | // Send a PONG back to the server whenever we receive a PING | |
| 78 | - | if($pieces[0] == "PING") { | |
| 79 | - | fputs($socket, "PONG " . $pieces[1] . "\n"); | |
| 80 | - | } | |
| 81 | - | ||
| 82 | - | // Otherwise, we're going to send everything to our separate functions script for handling | |
| 83 | - | else { | |
| 84 | - | ||
| 85 | - | // Execute the functions script, passing the $data to it as an argument | |
| 86 | - | $response = shell_exec($functions_script_command.' '.escapeshellarg($data)); | |
| 87 | - | ||
| 88 | - | // Since we're receiving JSON in response, we'll decode that | |
| 89 | - | $response = json_decode($response); | |
| 90 | - | ||
| 91 | - | // Process responses | |
| 92 | - | if(isset($response->response)) { | |
| 93 | - | if(is_countable($response->response)) { | |
| 94 | - | foreach($response->response as $response_item) { | |
| 95 | - | fputs($socket, $response_item."\r\n"); | |
| 96 | - | } | |
| 66 | + | while (1) { | |
| 67 | + | while ($data = fgets($socket, 512)) { | |
| 68 | + | echo $data; | |
| 69 | + | flush(); | |
| 70 | + | ||
| 71 | + | // Take the line of data that we've received and snap it into separate pieces wherever there's a space | |
| 72 | + | $pieces = explode(' ', $data); | |
| 73 | + | ||
| 74 | + | // At this point, $pieces[0] will contain the sender, and $pieces[1] will contain the command that was sent | |
| 75 | + | ||
| 76 | + | // Send a PONG back to the server whenever we receive a PING | |
| 77 | + | if ($pieces[0] == "PING") { | |
| 78 | + | fputs($socket, "PONG " . $pieces[1] . "\n"); | |
| 97 | 79 | } | |
| 80 | + | ||
| 81 | + | // Otherwise, we're going to send everything to our separate functions script for handling | |
| 98 | 82 | else { | |
| 99 | - | fputs($socket, $response->response."\r\n"); | |
| 83 | + | ||
| 84 | + | // Execute the functions script, passing the $data to it as an argument | |
| 85 | + | $response = shell_exec($functions_script_command . ' ' . escapeshellarg($data)); | |
| 86 | + | ||
| 87 | + | // Since we're receiving JSON in response, we'll decode that | |
| 88 | + | $response = json_decode($response); | |
| 89 | + | ||
| 90 | + | // Process responses | |
| 91 | + | if (isset($response->response)) { | |
| 92 | + | if (is_countable($response->response)) { | |
| 93 | + | foreach ($response->response as $response_item) { | |
| 94 | + | fputs($socket, $response_item . "\r\n"); | |
| 95 | + | } | |
| 96 | + | } else { | |
| 97 | + | fputs($socket, $response->response . "\r\n"); | |
| 98 | + | } | |
| 99 | + | } | |
| 100 | 100 | } | |
| 101 | - | } | |
| 102 | 101 | } | |
| 103 | - | } | |
| 104 | 102 | } |