diff --git a/update_chain.php b/update_chain.php index 2afb7d0..b471ffe 100644 --- a/update_chain.php +++ b/update_chain.php @@ -87,7 +87,7 @@ function chain_to_string($chain) { for ($i = count($chain) - 1; $i >= 0 ; $i--) { $string .= $chain[$i]['username']; if ($i != 0) { - $string .= " > "; + $string .= " → "; } } return $string; @@ -133,6 +133,10 @@ if ($saved_chain != $chain_string) { $contents = ""; fwrite($file, $contents); fclose($file); + $file2 = fopen('lastmember.php', 'w'); + $contents = ""; + fwrite($file2, $contents); + fclose($file2); } diff --git a/webhook.php b/webhook.php index 50ab1d6..d569c98 100644 --- a/webhook.php +++ b/webhook.php @@ -1,4 +1,13 @@ {'message'}->{'new_chat_members'} as $member){ + $username = $member->{"username"}; + $user_id = $member->{"chat_id"}; + $query = "INSERT INTO users (user_id, username, follows) values($user_id, '$username', -1);"; + $mysql = require('mysql_credentials.php'); + $conn = new mysqli($mysql['servername'], $mysql['username'], $mysql['password'], $mysql['database']); + if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); + } + $conn->query($query); + $conn->close(); + $lastmember = include('lastmember.php'); + $text = "Welcome $username,\n"; + $text .= "\n"; + $text .= "Congratulations for following the chain all the way to here.\n"; + $text .= "To get started, read the rules @Bio_Chain_2_Rules and add @$lastmember to your bio.\n"; + $text .= "You can run /update to regenerate the chain.\n"; + $text .= "\n"; + $text .= "Have Fun"; + send_text($text); + } + +} // Get JSON from post, store it and decode it. $var = file_get_contents('php://input'); $decoded = json_decode($var);