Add add_requirement() and WIP deposit()
Also, removed unneccessary functions
This commit is contained in:
		
							
								
								
									
										98
									
								
								webhook.php
									
									
									
									
									
								
							
							
						
						
									
										98
									
								
								webhook.php
									
									
									
									
									
								
							@@ -15,59 +15,6 @@ function check_command($command) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Send code back to the sender.
 | 
					 | 
				
			||||||
function send_code($post_message, $reply=false) {
 | 
					 | 
				
			||||||
  global $decoded;
 | 
					 | 
				
			||||||
  global $bot_api;
 | 
					 | 
				
			||||||
  global $chat_id;
 | 
					 | 
				
			||||||
  $url = 'https://api.telegram.org/bot' . $bot_api . '/sendMessage';
 | 
					 | 
				
			||||||
  $post_msg = array('chat_id' => $chat_id, 'text' => '```\n ' . $post_message . '```', 'parse_mode' => 'markdown' );
 | 
					 | 
				
			||||||
  if ($reply != false) {
 | 
					 | 
				
			||||||
    if ($reply === true){
 | 
					 | 
				
			||||||
      $post_msg['reply_to_message_id'] = $decoded->{'message'}->{'message_id'};
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else {
 | 
					 | 
				
			||||||
      $post_msg['reply_to_message_id'] = $reply;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  $options = array(
 | 
					 | 
				
			||||||
    'http' => array(
 | 
					 | 
				
			||||||
      'header' => "Content-type: application/x-www-form-urlencoded\r\n",
 | 
					 | 
				
			||||||
      'method' => 'POST',
 | 
					 | 
				
			||||||
      'content' => http_build_query($post_msg)
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  );
 | 
					 | 
				
			||||||
  $context = stream_context_create($options);
 | 
					 | 
				
			||||||
  $result = file_get_contents($url, false, $context);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Send text back to the sender.
 | 
					 | 
				
			||||||
function send_text($post_message, $reply=false) {
 | 
					 | 
				
			||||||
  global $decoded;
 | 
					 | 
				
			||||||
  global $bot_api;
 | 
					 | 
				
			||||||
  global $chat_id;
 | 
					 | 
				
			||||||
  $url = 'https://api.telegram.org/bot' . $bot_api . '/sendMessage';
 | 
					 | 
				
			||||||
  $post_msg = array('chat_id' => $chat_id, 'text' =>$post_message );
 | 
					 | 
				
			||||||
  if ($reply != false) {
 | 
					 | 
				
			||||||
    if ($reply === true){
 | 
					 | 
				
			||||||
      $post_msg['reply_to_message_id'] = $decoded->{'message'}->{'message_id'};
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else {
 | 
					 | 
				
			||||||
      $post_msg['reply_to_message_id'] = $reply;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  $options = array(
 | 
					 | 
				
			||||||
    'http' => array(
 | 
					 | 
				
			||||||
      'header' => "Content-type: application/x-www-form-urlencoded\r\n",
 | 
					 | 
				
			||||||
      'method' => 'POST',
 | 
					 | 
				
			||||||
      'content' => http_build_query($post_msg)
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
  );
 | 
					 | 
				
			||||||
  $context = stream_context_create($options);
 | 
					 | 
				
			||||||
  $result = file_get_contents($url, false, $context);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Send html back to the sender.
 | 
					// Send html back to the sender.
 | 
				
			||||||
function send_html($post_message, $reply=false) {
 | 
					function send_html($post_message, $reply=false) {
 | 
				
			||||||
  global $decoded;
 | 
					  global $decoded;
 | 
				
			||||||
@@ -94,6 +41,51 @@ function send_html($post_message, $reply=false) {
 | 
				
			|||||||
  $result = file_get_contents($url, false, $context);
 | 
					  $result = file_get_contents($url, false, $context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function add_requirement() {
 | 
				
			||||||
 | 
					  global $command_list;
 | 
				
			||||||
 | 
					  $item_id = $command_list[1];
 | 
				
			||||||
 | 
					  $item_name = "";
 | 
				
			||||||
 | 
					  for ($i = 2; $i < count($command_list) - 1; $i++){
 | 
				
			||||||
 | 
					    $item_name .= $command_list[$i];
 | 
				
			||||||
 | 
					    if ($i != count($command_list) - 2){
 | 
				
			||||||
 | 
					      $item_name .= " ";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  $quantity = $command_list[count(command_list) - 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);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  $stmt = $conn->prepare("DELETE FROM req where id = ?;");
 | 
				
			||||||
 | 
					  $stmt->bind('s', $item_id);
 | 
				
			||||||
 | 
					  $stmt->execute();
 | 
				
			||||||
 | 
					  $stmt = $conn->prepare("INSERT INTO req (id, name, quantity) VALUES (?,?,?);");
 | 
				
			||||||
 | 
					  $stmt->bind('ssi', $item_id, $item_name, $quantity);
 | 
				
			||||||
 | 
					  $stmt->execute();
 | 
				
			||||||
 | 
					  $conn->close();
 | 
				
			||||||
 | 
					  send_html("Added to requirements");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function deposit(){
 | 
				
			||||||
 | 
					  global $command_list;
 | 
				
			||||||
 | 
					  $item_id = $command_list[1];
 | 
				
			||||||
 | 
					  for ($i = 2; $i < count($command_list) - 1; $i++){
 | 
				
			||||||
 | 
					    $item_name .= $command_list[$i];
 | 
				
			||||||
 | 
					    if ($i != count($command_list) - 2){
 | 
				
			||||||
 | 
					      $item_name .= " ";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  $quantity = $command_list[count(command_list) - 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);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Get JSON from post, store it and decode it.
 | 
					// Get JSON from post, store it and decode it.
 | 
				
			||||||
$var = file_get_contents('php://input');
 | 
					$var = file_get_contents('php://input');
 | 
				
			||||||
$decoded = json_decode($var);
 | 
					$decoded = json_decode($var);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user