-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.php
197 lines (162 loc) · 6.1 KB
/
bot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* Created by PhpStorm.
* Author: SMHassanAlavi
* Date: 12/29/16
* Time: 4:17 PM
*/
function makeCurl($method,$datas=[]) //make and receive requests to bot
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.telegram.org/bot274622754:AAFb0_FK4ShDjOjy1KpnbRf-U9-GVBzNpVk/{$method}");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($datas));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
return $server_output;
}
$db; //global database connect
$level; //user level
$user_id; //user unique user id.find in main function in each update
$text; //text that user sent.sometimes the callback data of inline keyboard
$username; //user telegram username
$message_id; //message_id of button that user pressed
$question; //the question should be asked from user
$user_firstname; //user first name;
$locale; //user language
$last_updated_id = 0; //should be removed
$db=mysqli_connect("localhost","root","root","padporsc_bot4");
require "recognize.php";
require "level_finder.php";
require "intro.php";
require "firststep.php";
require "got_email.php";
require "entrance.php";
require "getting_master_key.php";
require "answering_entrance_question.php";
require "continue_handler.php";
require "question_menu.php";
require "question_handling.php";
require "warm.php";
require "warmquestion.php";
require "returnQuestion.php";
require "askQuestion.php";
require "userMenu.php";
require "team.php";
require "haveTeam.php";
require "kick.php";
require "teamChangeName.php";
require "leaving.php";
require "makeQuestion.php";
require "score.php";
require "info.php";
require "account.php";
require "myEmail.php";
require "changeLang.php";
require "startAsking.php";
require "answering.php";
require "send.php";
require "askMyFriend.php";
require "comment.php";
function main()
{
global $level;
global $user_id;
global $text;
global $username;
global $user_firstname;
global $message_id;
global $last_updated_id;
global $db;
// $update = json_decode(file_get_contents("php://input")); //should not be comment
$updates = json_decode(makeCurl("getUpdates",["offset"=>($last_updated_id+1)])); //should be removed
if($updates->ok == true && count($updates->result) > 0) { //should be removed
foreach ($updates->result as $update) { //should be removed
if ($update->callback_query) {
makeCurl("answerCallbackQuery", ["callback_query_id" => $update->callback_query->id]);
$text = $update->callback_query->data;
$user_id = $update->callback_query->from->id;
$user_firstname = $update->callback_query->from->first_name;
$username = $update->callback_query->from->username;
$message_id = $update->callback_query->message->message_id;
} else {
$text = $update->message->text;
$user_id = $update->message->chat->id;
$username = $update->message->from->username;
$user_firstname = $update->message->from->first_name;
}
levelFinder();
if ($level == "Begin")
intro();
elseif ($text == "C0nT1nu3")
continueHandler();
elseif ($text == "my_3ma1L")
myEmail(0);
elseif ($level == "intro_showed")
firstStep();
elseif ($level == "firstStep")
getEmailStartEntrance();
elseif ($level == "has_email_go_to_entrance")
entrance();
elseif ($level == "answering_the_entrance_question")
answeringEntranceQuestion();
elseif ($level == "waiting_for_master_key")
gettingMasterKey();
elseif ($level == "question_menu")
question_menu();
elseif ($level == "question_showed")
questionHandling();
elseif ($level == "user_menu")
userMenu(2,0);
elseif ($level == "question_asked")
startAsking();
elseif ($level == "answering")
answering();
elseif ($level == "watching_info")
info(1);
elseif ($level == "watching_change_language")
changeLang(1);
elseif ($level == "changing_email")
myEmail(1);
elseif ($level == "making_question")
makeQuestion(1);
elseif ($level == "how_Enter")
account(1);
elseif ($level == "current_user")
account(2);
elseif ($level == "getting_username_for_sign_up")
account(3);
elseif ($level == "getting_password")
account(4);
elseif ($level == "team_menu")
team(1);
elseif ($level == "getting_team_name")
team(2);
elseif ($level == "get_master_key")
team(3);
elseif ($level == "random_find")
team(4);
elseif ($level == "have_team_menu")
haveTeam(1);
elseif ($level == "send_message")
send();
elseif ($level == "leaving")
leaving();
elseif ($level == "changing_name_team")
changeName(1);
elseif ($level == "kick")
kick(1);
elseif ($level == "make_sure")
kick(2);
elseif ($level == "warming_up")
warm(1);
elseif ($level == "commenting")
comment(1);
$last_updated_id = $update->update_id; //should be removed
} //should be removed
} //should be removed
}
while(1) {
main();
}