Guest User

Untitled

a guest
Oct 30th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. $title=9; $cat=8; //to test global variable
  2. function processMessage($message) {
  3. global $title, $cat; //declaring global
  4. // process incoming message
  5. $message_id = $message['message_id'];
  6. $chat_id = $message['chat']['id'];
  7. $sender_id = $message['from']['id'];
  8. $sender_first_name = $message['from']['first_name'];
  9. $sender_last_name = $message['from']['last_name'];
  10. $message_date = $message['date'];
  11.  
  12. if (isset($message['text'])) {
  13. // incoming text message
  14. $text = $message['text'];
  15.  
  16. //when user starts the bot
  17. if (strpos($text, "/start") === 0) {
  18. apiRequestJson("sendmessage", array('chat_id' => $chat_id, "text" => 'Please select an option:', 'reply_markup' => array(
  19. 'keyboard' => array(array('Category Check', 'Uncategorized')),
  20. 'one_time_keyboard' => false,
  21. 'resize_keyboard' => true)));
  22.  
  23. }
  24.  
  25. //category check that returns news title and category question to user
  26. else if ($text === "Category Check") {
  27.  
  28. //MySQL Connection Details
  29. $servername = "localhost";
  30. $username = "user";
  31. $password = "pass";
  32. $dbname = "dbname";
  33. $conn = new mysqli($servername, $username, $password, $dbname);
  34.  
  35. $sql = "SELECT * FROM `newsdata` WHERE `nb_count` OR `svm_count` <> 0 ORDER BY RAND() LIMIT 1 ";
  36.  
  37. $row = $result->fetch_assoc();
  38.  
  39. $nb_business = $row["nb_business"];
  40. $nb_entertainment = $row["nb_entertainment"];
  41. $nb_health = $row["nb_health"];
  42. $nb_politics = $row["nb_politics"];
  43. $nb_science = $row["nb_science"];
  44. $nb_technology = $row["nb_technology"];
  45. $nb_world = $row["nb_world"];
  46. $svm_business = $row["svm_business"];
  47. $svm_entertainment = $row["svm_entertainment"];
  48. $svm_health = $row["svm_health"];
  49. $svm_politics = $row["svm_politics"];
  50. $svm_science = $row["svm_science"];
  51. $svm_technology = $row["svm_technology"];
  52. $svm_world = $row["svm_world"];
  53. $title=$row["title"]; //assigning title
  54. $nb_count=$row["nb_count"];
  55. $svm_count=$row["svm_count"];
  56.  
  57. if($nb_business!=0)
  58. {$cat='BUSINESS'; $track=1;}
  59. else if ($nb_entertainment!=0)
  60. {$cat='ENTERTAINMENT'; $track=1;}
  61. else if ($nb_health!=0)
  62. {$cat='HEALTH'; $track=1;}
  63. else if ($nb_politics!=0)
  64. {$cat='POLITICS'; $track=1;}
  65. else if ($nb_science!=0)
  66. {$cat='SCIENCE'; $track=1;}
  67. else if ($nb_technology!=0)
  68. {$cat='TECHNOLOGY'; $track=1;}
  69. else if ($nb_world!=0)
  70. {$cat='WORLD'; $track=1;}
  71.  
  72. else if ($svm_business!=0)
  73. {$cat='BUSINESS'; $track=0;}
  74. else if ($svm_entertainment!=0)
  75. {$cat='ENTERTAINMENT'; $track=0;}
  76. else if ($svm_health!=0)
  77. {$cat='HEALTH'; $track=0;}
  78. else if ($svm_politics!=0)
  79. {$cat='POLITICS'; $track=0;}
  80. else if ($svm_science!=0)
  81. {$cat='SCIENCE'; $track=0;}
  82. else if ($svm_technology!=0)
  83. {$cat='TECHNOLOGY'; $track=0;}
  84. else if ($svm_world!=0)
  85. {$cat='WORLD'; $track=0;}
  86. // output data of each row
  87.  
  88. //asking user if the category is correct
  89. apiRequestJson("sendmessage", array('chat_id' => $chat_id, "text" => 'Is this news belongs to '.
  90. $cat.' category? '.
  91. $title.' '.$row["link"],
  92. 'reply_markup' => array(
  93. 'keyboard' => array(array('yes', 'no')),
  94. 'one_time_keyboard' => false,
  95. 'resize_keyboard' => true)));
  96. }
  97. //user answers
  98. if ($text == "yes" || $text == "no"){
  99. switch ($text) {
  100. case "yes":
  101. $nb_count=$nb_count--;
  102. $svm_count=$svm_count--;
  103. apiRequestJson("sendmessage", array('chat_id' => $chat_id, "text" => $cat.$title)); //broken here, output: 98
  104.  
  105. break;
  106. case "no":
  107. //dothat; break;
  108. }
Add Comment
Please, Sign In to add comment