Add write last member. Add new_member function

The update file now writes the last member to lastmember.php. Added new_member function.
This commit is contained in:
Ceda EI 2018-04-04 20:54:10 +05:30
parent 6c4fa4848c
commit d49d6fa764
2 changed files with 39 additions and 1 deletions

View File

@ -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 = "<?php return '". $chain_string . "'; ?>";
fwrite($file, $contents);
fclose($file);
$file2 = fopen('lastmember.php', 'w');
$contents = "<?php return '" . $chain[count($chain) - 1] . "'; ?>";
fwrite($file2, $contents);
fclose($file2);
}

View File

@ -1,4 +1,13 @@
<?php
ignore_user_abort(true);
set_time_limit(0);
ob_start();
// do initial processing here
header('Connection: close');
header('Content-Length: '.ob_get_length());
ob_end_flush();
ob_flush();
flush();
$bot_name = "zeeth_naaw_bot";
$bot_api = require('api_key.php');
@ -41,6 +50,31 @@ function send_html($post_message, $reply=false) {
$result = file_get_contents($url, false, $context);
}
function new_member() {
global $decoded;
foreach ($decoded->{'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);