-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbot.php
More file actions
130 lines (120 loc) · 4.81 KB
/
Copy pathbot.php
File metadata and controls
130 lines (120 loc) · 4.81 KB
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
<?php
/*
* Demo => @inlinelike_bot
* Author => Ehsan Noureddini
* Email => me@ehsann.info
*/
define('API_KEY', API_KEY);
define('WELCOME_MSG',"
این ربات به شما این اجازه را می دهد که بتوانید پست هایی با دکمه لایک زیر آن ، ایجاد نمایید.
➖➖➖➖➖➖➖➖➖➖
ددر بخش ارسال پیام که هستید ، تایپ کنید <code>@inlinelike_bot یه چیزی</code>را بنویسید و سپس روی <b>ارسال</b> کلیک کنید.
برای مثال همینجا بنویسید: <i>@inlinelike_bot من رو لایک کن </i>
");
function makeHTTPRequest($method,$datas=[]){
$url = "https://api.telegram.org/bot".API_KEY."/".$method;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($datas));
$res = curl_exec($ch);
if(curl_error($ch)){
var_dump(curl_error($ch));
}else{
return json_decode($res);
}
}
$data = file_get_contents("php://input");
$update = json_decode($data, true);
$dsn = 'mysql:dbname=DB_NAME;host=localhost;charset=utf8';
$user = DB_USER;
$password = DB_PASS;
$pdo = new PDO($dsn, $user, $password);
if($update['message']['text']=="/start"){
$chat_id=$update['message']['from']['id'];
makeHTTPRequest('sendMessage',[
'chat_id'=>$update['message']['from']['id'],
'text'=>WELCOME_MSG,
'parse_mode'=>'HTML',
]);
}
if(isset($update['inline_query'])){
$chat_id = $update['inline_query']['from']['id'];
makeHTTPRequest('sendMessage',[
'chat_id'=>"@testt12",
'text'=>json_encode($update),
'parse_mode'=>'HTML',
]);
$inlineQueryID = $update['inline_query']['id'];
makeHTTPRequest('answerInlineQuery',[
'inline_query_id'=>$inlineQueryID,
'results' => json_encode([[
'type' => 'article',
'id' => base64_encode(1),
'title' => 'Send?',
'input_message_content' => ['parse_mode' => 'HTML', 'message_text' => $update['inline_query']['query']],
'reply_markup' => [
'inline_keyboard'=>[
[
['text'=> "❤",'callback_data'=>'like']
]
]]
]])
]);
}
if(isset($update['callback_query']) && $update['callback_query']['data']=="like"){
$alert = "شما این رو ❤ دارید :)";
$callBackQueryID = $update['callback_query']['id'];
$callBackQueryChatID = $update['callback_query']['message']['chat']['id'];
if($callBackQueryChatID==""){ //inline callbackquery
$callBackQueryChatID=$update['callback_query']['from']['id'];
}
$callBackQueryMessageID = $update['callback_query']['message']['message_id'];
if($callBackQueryMessageID==""){
$callBackQueryMessageID=$update['callback_query']['inline_message_id'];
}
$userID = $update['callback_query']['from']['id'];
$firstName = $update['callback_query']['from']['first_name'];
$lastName = $update['callback_query']['from']['last_name'];
$userName = $update['callback_query']['from']['username'];
// insert like
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$st = $pdo->prepare("INSERT INTO likes(`chat_id`,`query_id`,`message_id`,`user_id`) VALUES(:chat_id,:query_id,:message_id,:user_id)");
$st->bindParam(":chat_id",$callBackQueryChatID);
$st->bindParam(":query_id",$callBackQueryID);
$st->bindParam(":message_id", $callBackQueryMessageID);
$st->bindParam(":user_id", $userID);
$exec = $st->execute();
if(!$exec){
$alert = "You already liked this post";
}
else{
//select likes
$st= $pdo->prepare("select count(*) as like_count from likes where message_id=:message_id");
$st->bindParam(":message_id", $callBackQueryMessageID);
$st->execute();
$like_count = $st->fetch()['like_count']+1; // +1 for hearts
if(intval($like_count)<10){
$likes = str_repeat('❤',$like_count);
}
else{
$likes = $like_count . ' ' . '❤';
}
makeHTTPRequest("editMessageReplyMarkup",[
'inline_message_id'=>$callBackQueryMessageID,
'reply_markup' => json_encode([
'inline_keyboard'=>[
[
// ['text'=> $like_count . ' ❤','callback_data'=>'like']
['text'=> $likes,'callback_data'=>'like']
]
]]),
]);
}
makeHTTPRequest("answerCallbackQuery", [
'callback_query_id' => $callBackQueryID,
'text' => $alert,
// 'show_alert' => true,
] );
}
?>