Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('display_errors', 1);
  4. error_log(E_ALL);
  5.  
  6. $token = 'xxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  7. $api = 'https://api.telegram.org/bot' . $token . '/';
  8.  
  9. $db = new mysqli('localhost', 'xxx', 'xxx');
  10. $db->select_db('tb_lazy');
  11. $db->query("SET NAMES utf8");
  12.  
  13. $result = $db->query("SELECT * FROM staff");
  14. while($row = $result->fetch_array(MYSQLI_ASSOC)) {
  15. $staff = $row;
  16. }
  17.  
  18. $data = json_decode(file_get_contents($api . 'getUpdates?offset=' . $staff['offset']));
  19.  
  20. foreach($data->result as $unit) {
  21. $message = $unit->message;
  22. $chat_id = $message->from->id;
  23.  
  24. if(isset($message->chat)) {
  25. $chat_id = $message->chat->id;
  26. }
  27.  
  28. if(isset($message->text)) {
  29. $text = trim($message->text);
  30.  
  31. if(preg_match('/\/lazy/', $text)) {
  32.  
  33. $text = urldecode($text);
  34. $expltext = explode(" ", $text);
  35.  
  36. $service = preg_replace('/(.+?)(@.+)*/', '$1', $expltext[0]);
  37.  
  38. if(count($expltext) > 1) {
  39. $param = '';
  40. for($i = 1; $i < count($expltext); $i++) {
  41. $param .= $expltext[$i] . ' ';
  42. }
  43. $param = trim($param);
  44. }
  45. else {
  46. $param = false;
  47. }
  48.  
  49. switch($service) {
  50.  
  51. case '/lazywiki': {
  52. include('modules/lazywiki.php');
  53. break;
  54. }
  55.  
  56. case '/lazycurr': {
  57. include('modules/lazycurr.php');
  58. break;
  59. }
  60.  
  61. case '/lazy': {
  62. include('modules/lazyhelp.php');
  63. break;
  64. }
  65.  
  66. default: {
  67. $response = '/lazy';
  68. }
  69.  
  70. }
  71.  
  72. $response = urlencode($response);
  73. file_get_contents($api . 'sendMessage?chat_id=' . $chat_id . '&text=' . $response);
  74. }
  75. }
  76.  
  77. $update_id = $unit->update_id + 1;
  78. $db->query("UPDATE staff SET offset = $update_id WHERE id = 1");
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement