Add /update

This commit is contained in:
Ceda EI 2018-04-05 11:04:45 +05:30
parent d49d6fa764
commit ad73619959
2 changed files with 10 additions and 2 deletions

View File

@ -127,7 +127,7 @@ $chain = get_longest_chain();
$chain_string = chain_to_string($chain);
$saved_chain = include('chain.php');
if ($saved_chain != $chain_string) {
$send_message = "Chain Length: " . count($chain) . "\n" . $chain_string;
$send_message = "Chain Length: " . count($chain) . "\n\n" . $chain_string;
send_text($send_message);
$file = fopen('chain.php', 'w');
$contents = "<?php return '". $chain_string . "'; ?>";

View File

@ -53,6 +53,9 @@ function send_html($post_message, $reply=false) {
function new_member() {
global $decoded;
foreach ($decoded->{'message'}->{'new_chat_members'} as $member){
if ($member->{'is_bot'}) {
continue;
}
$username = $member->{"username"};
$user_id = $member->{"chat_id"};
$query = "INSERT INTO users (user_id, username, follows) values($user_id, '$username', -1);";
@ -73,8 +76,13 @@ function new_member() {
$text .= "Have Fun";
send_text($text);
}
}
function update() {
send_text("Update started. New chain will only be send if the chain has changed. Please wait as this takes about a minute.");
include('./update_chain.php');
}
// Get JSON from post, store it and decode it.
$var = file_get_contents('php://input');
$decoded = json_decode($var);