dashboard / melanie/penelope / convert to environment variables #114 rss

closed · opened on 2026-02-25T00:32:19Z by melanie
Help
checkout latest patchset:
ssh pr.pico.sh print pr-114 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print ps-X | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 114
add review to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add --review 114
accept PR:
ssh pr.pico.sh pr accept 114
close PR:
ssh pr.pico.sh pr close 114
Timeline Patchsets

Patchset ps-205

convert to environment variables

Melanie Kat
2026-02-25T00:26:38Z
bot.php
+8 -7

change port env name to avoid collision

Melanie Kat
2026-02-25T00:33:44Z
bot.php
+50 -52
Back to top
+8 -7 bot.php link
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
diff --git a/bot.php b/bot.php
index 1333798..78ce627 100644
--- a/bot.php
+++ b/bot.php
@@ -3,17 +3,18 @@
 // The omg.lol generic IRC bot framework lol
 // Based on https://github.com/Hammster/php-irc-bot/tree/master
 
-// Configure your bot's details here
-$nickname = 'your-bot';
-$hostname = 'example.com';
-$password = 'correct-horse-battery-stapler';
-$server   = 'irc.example.com';
-$port     = 6697;
+// Configure your bot's details
+// with environment variables
+$nickname = $_ENV["NICKNAME"];
+$hostname = $_ENV["HOSTNAME"];
+$password = $_ENV["PASSWORD"];
+$server   = $_ENV["SERVER"];
+$port     = $_ENV["PORT"];
 
 // In order to update the bot's code while it's connected to IRC, we need a separate "functions" script.
 // This script will receive a stream of the IRC activity, and then it'll "do stuff" and send the response
 // back to *this* script. If that makes sense. I hope it does.
-$functions_script_command = '/usr/bin/php /path/to/bot_functions.php';
+$functions_script_command = 'NICKNAME=$nickname /usr/bin/php -d variables_order=EGPCS ./bot_functions.php';
 
 // Finally, you can plop a URL to an avatar image here for IRCv3 avatars, or set to 'false' to disable
 $avatar_url = false;
+1 -1 bot_functions.php link
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
diff --git a/bot_functions.php b/bot_functions.php
index 0a60dc3..9269c87 100644
--- a/bot_functions.php
+++ b/bot_functions.php
@@ -3,7 +3,7 @@
 // Penelope Bot Functions
 
 // eventually we can make the nickname be handed off from the main script, but for now, set it here too
-$nickname = 'your-bot';
+$nickname = $_ENV["NICKNAME"];
 
 // you can configure channels to join here
 $channels  = array(

+50 -52 bot.php link
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
diff --git a/bot.php b/bot.php
index 78ce627..0268a4e 100644
--- a/bot.php
+++ b/bot.php
@@ -9,7 +9,7 @@ $nickname = $_ENV["NICKNAME"];
 $hostname = $_ENV["HOSTNAME"];
 $password = $_ENV["PASSWORD"];
 $server   = $_ENV["SERVER"];
-$port     = $_ENV["PORT"];
+$port     = $_ENV["IRCPORT"];
 
 // In order to update the bot's code while it's connected to IRC, we need a separate "functions" script.
 // 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);
 
 // Now we'll set up our connection
 $context = stream_context_create([
-  'ssl' => [
-    'verify_peer'       => true,
-    'verify_peer_name'  => true,
-    'allow_self_signed' => false,
-    'SNI_enabled'       => true,
-    'peer_name'         => $server,
-  ],
+    'ssl' => [
+        'verify_peer'       => true,
+        'verify_peer_name'  => true,
+        'allow_self_signed' => false,
+        'SNI_enabled'       => true,
+        'peer_name'         => $server,
+    ],
 ]);
 
 // And actually connect
 $socket = stream_socket_client(
-  "tls://{$server}:{$port}",
-  $errno,
-  $errstr,
-  30,
-  STREAM_CLIENT_CONNECT,
-  $context
+    "tls://{$server}:{$port}",
+    $errno,
+    $errstr,
+    30,
+    STREAM_CLIENT_CONNECT,
+    $context
 );
 
-if(!$socket) {
-  die("Connection failed: $errstr ($errno)\n");
+if (! $socket) {
+    die("Connection failed: $errstr ($errno)\n");
 }
 
 // If our code is still running at this point, we're connected to the server!
@@ -58,47 +58,45 @@ fputs($socket, "NICK " . $nickname . "\n");
 fputs($socket, "USER " . $nickname . " 0 * :$nickname@$hostname\n");
 
 // Send avatar metadata? does this even work? lol
-if($avatar_url) {
-  fputs($socket, "METADATA * SET avatar $avatar_url\n");
+if ($avatar_url) {
+    fputs($socket, "METADATA * SET avatar $avatar_url\n");
 }
 
-
 // Loopy loop forever and ever and ever
-while(1) {
-  while ($data = fgets($socket, 512)) {
-    echo $data;
-    flush();
-    
-    // Take the line of data that we've received and snap it into separate pieces wherever there's a space
-    $pieces = explode(' ', $data);
-    
-    // At this point, $pieces[0] will contain the sender, and $pieces[1] will contain the command that was sent
-    
-    // Send a PONG back to the server whenever we receive a PING
-    if($pieces[0] == "PING") {
-      fputs($socket, "PONG " . $pieces[1] . "\n");
-    }
-    
-    // Otherwise, we're going to send everything to our separate functions script for handling
-    else {
-      
-      // Execute the functions script, passing the $data to it as an argument
-      $response = shell_exec($functions_script_command.' '.escapeshellarg($data));
-      
-      // Since we're receiving JSON in response, we'll decode that
-      $response = json_decode($response);
-      
-      // Process responses
-      if(isset($response->response)) {
-        if(is_countable($response->response)) {
-          foreach($response->response as $response_item) {
-            fputs($socket, $response_item."\r\n");
-          }
+while (1) {
+    while ($data = fgets($socket, 512)) {
+        echo $data;
+        flush();
+
+        // Take the line of data that we've received and snap it into separate pieces wherever there's a space
+        $pieces = explode(' ', $data);
+
+        // At this point, $pieces[0] will contain the sender, and $pieces[1] will contain the command that was sent
+
+        // Send a PONG back to the server whenever we receive a PING
+        if ($pieces[0] == "PING") {
+            fputs($socket, "PONG " . $pieces[1] . "\n");
         }
+
+        // Otherwise, we're going to send everything to our separate functions script for handling
         else {
-          fputs($socket, $response->response."\r\n");
+
+            // Execute the functions script, passing the $data to it as an argument
+            $response = shell_exec($functions_script_command . ' ' . escapeshellarg($data));
+
+            // Since we're receiving JSON in response, we'll decode that
+            $response = json_decode($response);
+
+            // Process responses
+            if (isset($response->response)) {
+                if (is_countable($response->response)) {
+                    foreach ($response->response as $response_item) {
+                        fputs($socket, $response_item . "\r\n");
+                    }
+                } else {
+                    fputs($socket, $response->response . "\r\n");
+                }
+            }
         }
-      }
     }
-  }
 }