-
Notifications
You must be signed in to change notification settings - Fork 0
/
sinaudevbot.php
157 lines (116 loc) · 3.79 KB
/
sinaudevbot.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
<?php
require __DIR__ . '/src/config.php';
require __DIR__ . '/src/helper.php';
require __DIR__ . '/src/telegrambot.php';
use \telegram\Bot;
//Set Token
Bot::setToken('');
// Daftar seluruh plugins
$plugin_dir = array_diff(scandir(__DIR__ .'/plugin'), array('..', '.'));
$plugin_name = array();
if (!empty($plugin_dir)){
foreach ($plugin_dir as $plugin_file) {
$pInfo = pathinfo($plugin_file);
if(strtolower($pInfo['extension'])=='php'){
require __DIR__.'/plugin/'.$plugin_file;
$plugin_name[] = str_replace('.php', '', $plugin_file);
}
}
}
Bot::run(function($update) use (&$plugin_name)
{
if ($update['error'] == false)
{
$message = $update['message'];
$inline = isset($update['inline_query'])?$update['inline_query']:'';
$message_id = isset($message['message_id'])?$message['message_id']:'';
$reply = (isset($message['reply_to_message']))?$message['reply_to_message']:'';
if (!empty($reply)){
if ($message['text']=='kick'){
Bot::kickMember($reply['chat']['id'],$reply['from']['id']);
}
}
Bot::setParam(array('reply_to_message_id' => $message_id));
// Membaca seluruh plugin dan function nya
foreach($plugin_name as $plugin){
if (function_exists('call_'. $plugin))
{
$pResult = call_user_func('call_'.$plugin,$update);
}
}
if (Bot::getChatType($message) == 'text')
{
if ($message['text'] == 'ping')
{
$keyboard = [
'inline_keyboard' =>[
[
['text' => 'Selengkapnya', 'url' => 'http://sinaudev.org'],
['text' => 'Gabung Sinaudev', 'url' => 'https://t.me/sinaudev']
]
]
];
$param['reply_markup']=json_encode($keyboard);
$send = Bot::send('message',"<b>PONG</b>\n{$myfile}",$param);
}
if ($message['text'] == 'photo')
{
$send = Bot::send('photo',__DIR__.'/test/stickerTest.png');
}
if ($message['text'] == 'contact')
{
$send = Bot::send('contact',array('phone_number'=>'0217977752454','first_name'=>'Test Number'));
}
if ($message['text'] == 'map')
{
// How to find a coordinates of a location?
// 1. On your computer, visit Google Maps.
// 2. Right-click a location on the map.
// 3. Select "What's here?".
// 4. A card appears at the bottom of the screen with more info.
//Send a location of The Zimbabwe
$send = Bot::send('location',array('latitude'=>-18.389069, 'longitude'=> 29.160894));
}
}
//inline method
if (!empty($inline)){ inlinebot($inline); }
}
else{
if ($update['ok'] == false) print_r($update);
}
}
);
function inlinebot($inline){
$query = $inline['query'];
$id = $inline['id'];
$from = $inline['from'];
$answer = [];
$json = getSinaudevJSON();
if (!empty($query)){
$json = getSinaudevPost($query,$json);
}
foreach ($json as $key => $value){
$keyboard = [
'inline_keyboard' =>[
[
['text' => 'Selengkapnya', 'url' => 'http://sinaudev.org'.$value['url']],
['text' => 'Gabung Sinaudev', 'url' => 'https://t.me/sinaudev']
]
]
];
$textMessage = "<b>{$value['title']}</b>\n\n";
$textMessage .= $value['description'];
$content = array('type'=>'article',
'id' => (string)$key,
'title' => $value['title'],
'hide_url' => true,
'message_text' => $textMessage,
'parse_mode' => 'HTML',
'description' => tokenTruncate($value['description'],30),
'reply_markup'=>$keyboard);
$answer[] = $content;
}
//print_r($answer);
$send = Bot::answerInlineQuery($id,json_encode($answer));
//print_r($send);
}