-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
123 lines (97 loc) · 3.43 KB
/
Copy pathindex.php
File metadata and controls
123 lines (97 loc) · 3.43 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
<?php
require_once('db.php');
class teleBot{
public $api = ':';
public $apiUrl = 'https://api.telegram.org';
public $method;
public $update;
public function getUpdate(){
$update = json_decode(file_get_contents("php://input"),TRUE);
$this->update = $update;
}
public function getLastChat($id){
$getLog = substr_replace(file_get_contents('log_telegram.txt'), "", -1);
$getLog = explode('|',$getLog);
for ($i=0; $i < count($getLog); $i++) {
$getLogId = $getLog[$i];
$getLogId = explode(',',$getLogId);
if($getLogId[0] == $id){
$chat = $getLogId[1];
}
}
return $chat;
}
public function method($m){
$chatId = $this->update["message"]["chat"]["id"];
switch ($m['type']) {
case 'sendMessage':
$this->method = 'sendMessage?chat_id='.$chatId.'&text='.$m['data'];
return $this;
break;
default:
break;
}
}
public function start(){
$DB = new DB();
$this->getUpdate();
$chatId = $this->update["message"]["chat"]["id"];
switch ($this->update['message']['text']) {
case '/start':
$this->method([
'type'=> 'sendMessage',
'data'=>'Selamat Datang di Jondes Bot'
])->exec();
break;
case '/cek':
$getUser = $DB->getUserById($chatId);
if(count($getUser) !== 0){
$this->method([
'type'=> 'sendMessage',
'data'=>'Anda sudah registrasi, silahkan cek data dengan /info'
])->exec();
}
else{
$this->method([
'type'=> 'sendMessage',
'data'=>'Anda belum registrasi, silahkan registrasi di @d_n_s_bot'
])->exec();
}
break;
case '/info':
$getUserInfo = $DB->getUserInfo($chatId);
if(count($getUserInfo) !== 0){
$this->method([
'type'=> 'sendMessage',
'data'=> $getUserInfo[0]['nama']
])->exec();
}
else{
$this->method([
'type'=> 'sendMessage',
'data'=>'Anda belum registrasi, silahkan registrasi di @d_n_s_bot'
])->exec();
}
break;
default:
$this->method([
'type'=> 'sendMessage',
'data'=> $this->getLastChat($this->update["message"]["chat"]["id"])
])->exec();
break;
}
}
public function exec(){
$log = $this->update['message']['chat']['id'].','.$this->update['message']['text'].'|';
$this->storeLog($log);
$url = $this->apiUrl.'/bot'.$this->api.'/'.$this->method;
file_get_contents($url);
}
public function storeLog($log_msg){
$log_file_data = 'log_telegram.txt';
file_put_contents($log_file_data, $log_msg, FILE_APPEND);
}
}
$teleBot = new teleBot();
$teleBot->start();
//jondesbotv01