-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebhook.php
474 lines (425 loc) · 17.7 KB
/
webhook.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<?php
//So that PHPStorm finally shuts up about it not existing...
$config = array();
require_once(__DIR__ . "/funcs.php");
require_once(__DIR__ . "/config.php");
require_once(__DIR__ . "/infos.php");
require_once(__DIR__ . '/vendor/autoload.php');
//^ guzzlehttp
$response = file_get_contents('php://input');
$data = json_decode($response, true);
$dump = print_r($data, true);
if(file_exists($config['timeoutsave'])){
$timeouts = json_decode(file_get_contents($config['timeoutsave']),true);
}
else{
file_put_contents($config['timeoutsave'], '{}');
$timeouts = json_decode(file_get_contents($config['timeoutsave']),true);
}
$chatId = $data['message']['chat']['id'];
$chatType = $data['message']['chat']['type'];
$message = $data['message']['text'];
$messageId = $data['message']['message_id'];
$fee = $config['fee'];
if ($chatType !== 'private') {
$messageIdToReplyTo = $messageId;
}
else {
$messageIdToReplyTo = '';
}
$ownId = explode(':', $config['token'])[0];
$senderUserId = $data['message']['from']['id'];
$senderName = $data['message']['from']['first_name'];
if (isset($replyToMessage['from']['last_name'])) {
$senderName .= ' ' . $data['message']['from']['last_name'];
}
$senderUsername = NULL;
if (isset($data['message']['from']['username'])) {
$senderUsername = $data['message']['from']['username'];
}
if (isset($data['message']['reply_to_message'])) {
$replyToMessage = $data['message']['reply_to_message'];
$repliedToMessageId = $replyToMessage['message_id'];
if ($chatType !== 'private') {
$messageIdToReplyTo = $repliedToMessageId;
}
$repliedToUserId = $replyToMessage['from']['id'];
$repliedToName = $replyToMessage['from']['first_name'];
if (isset($replyToMessage['from']['last_name'])) {
$repliedToName = $repliedToName . ' ' . $replyToMessage['from']['last_name'];
}
$repliedToUsername = NULL;
if (isset($replyToMessage['from']['username'])) {
$repliedToUsername = $replyToMessage['from']['username'];
}
}
if (substr($message, '0', '1') == '/') {
$messageArr = explode(' ', $message);
$command = explode('@', $messageArr[0])[0];
if (isset($messageArr[1]) && $messageArr[1] == 'zencommands') {
$command = '/zencommands';
}
}
else {
die();
}
$nodeText = 'We have <a href="https://horizen.global/securenodes">secure nodes</a> and also <a href="https://horizen.global/supernodes">super nodes</a>.
A <i>secure</i> node needs 42 ZEN in a transparent address, whereas the <i>super</i> node requires 500 ZEN.';
$nodeText = 'ZEN has <a href="https://horizen.global/securenodes">secure nodes</a> and <a href="https://horizen.global/supernodes">super nodes</a>.
A secure node needs 42 ZEN in a transparent address, whereas the <i>super</i> node requires 500 ZEN.';
switch ($command) {
case '/start':
if ($chatType === 'private') {
sendMessage($chatId, 'Hello!
I\'m the ZEN Bot. I can provide quick information about topics when I see a command that I know.
To get a list of all of the commands I know, simply send “/zencommands” to me.
You can also use me to tip or thank people. For more info about that send “/tipbot” or “/thanks”
I am open source, so if you’d like you can add your own commands by creating a pull request here: https://github.com/DatDraggy/zen-help-bot
If you would like to buy @DatDraggy a beer or two, this is his donation address: zni7tRLevBnJxWMzkUoMVze1e6RCSPDdbfw');
}
break;
case '/zenprice':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, getCurrentPrice() . '
<code>Source: Bittrex, Coinmarketcap</code>', $messageIdToReplyTo);
break;
case '/nodes':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, $nodeText, $messageIdToReplyTo);
break;
case '/securenode':
case '/securenodes':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, '
For a secure node, you need 42 ZEN and a small VPS with a single core cpu, ~20GB space, 3-4GB RAM + some swap and a domain.
More info can be found here: https://horizen.global/securenodes
', $messageIdToReplyTo);
break;
case '/securenoderewards':
case '/securenodesreward':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, getCurrentSecureReward() . '
Keep in mind that these estimates are very rough and that the number of secure nodes can raise/fall at any time, therefore changing the estimates.
You can see the current daily reward for a secure node here: https://securenodes.zensystem.io
', $messageIdToReplyTo);
break;
case '/supernode':
case '/supernodes':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, '
A super node requires 500 ZEN, a bigger VPS with a quad core cpu, +100GB space, ~8GB RAM and a domain.
More info can be found here: https://horizen.global/supernodes
', $messageIdToReplyTo);
break;
case '/supernodesreward':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, getCurrentSuperReward() . '
Keep in mind that these estimates are very rough and that the number of secure nodes can raise/fall at any time, therefore changing the estimates.
You can see the current daily reward for a super node here: https://supernodes.zensystem.io
', $messageIdToReplyTo);
break;
case '/masternodes':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, '
We do not have masternodes. ' . $nodeText . '
', $messageIdToReplyTo);
break;
case '/zencommands':
case '/zenhelp':
case '/zenhelp@' . $config['botName']:
if ($chatType === 'private') {
sendMessage($chatId, '
Here is a list of available commands. Click them to find out what they do.
Note that you have to add @zenhelp_bot behind the command when trying it in the Horizen group, because of the other bots.
Example: /zenprice@zenhelp_bot
Knowledge Commands (click to get info):
/zenprice
/zengroups
/start
/nodes
/securenodes
/securenodesreward
/supernodes
/supernodesreward
/masternodes
/zencommands
/zenhelp
/ping
/zenadmins
/wallets
/freezen
/helpdesk
/securenoderoi
/supernoderoi
/stakeratio
Reputationsystem:
/thanks
/scoreboard
/mythanks
Tippingbot:
How to use: /tipbot
/withdraw
/deposit
/tip
/myaddress
/mybalance
<code>Text</code> - Indicates a command name
<b>Text</b> - Required parameter
<i>Text</i> - Optional parameter
');
}
else {
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
$replyMarkup = array(
'inline_keyboard' => array(
array(
array(
"text" => "/zencommands",
"url" => "https://telegram.me/" . $config['botName'] . "?start=zencommands"
)
)
)
);
//ToDo: Check last use of command/create a timeout
sendMessage($chatId, '
Click the button to get a list of all commands:
', $messageId, json_encode($replyMarkup));
}
break;
case '/ping':
sendMessage($chatId, 'Pong.', $messageId);
break;
case '/zenadmins':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
if ($chatType !== 'private') {
$adminText = 'Here is a list of all admins in this group:
';
//We don't want no notification on command
sendMessage($chatId, $adminText . getAdmins($chatId), $messageIdToReplyTo);
}
else {
sendMessage($chatId, 'Send this command in a group I\'m in. We are the only admins in this private chat. 😉');
}
break;
case '/wallets':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
$walletText = '
ZEN has two types of wallets: full and light. The Swing wallet is a full wallet, while our Arizen and Horizen mobile wallets are light wallets.
The full wallet is capable of using z-addresses, which are also known as private addresses. The Swing Wallet needs to download the entire blockchain, but that will take a while and is going to use some space on your hard drive. It\'s available for macOS, Windows 7+ 64bit, and Linux.
The light wallets, on the other hand, don’t need the full blockchain but can only use and send to t-addresses. They can receive from z-addresses and t-addresses. Arizen is available on macOS, Windows, and Linux. The mobile wallet is only available on Android, but you can use Coinomi on iOS.
It\'s also possible to connect Arizen with a machine running zend (Swing without GUI) to use z-addresses in Arizen.
If you would rather use a web wallet, a paper wallet or want to find out more about the wallets, take a look here: https://horizen.global/wallets/
';
sendMessage($chatId, $walletText, $messageIdToReplyTo);
break;
case '/freezen':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, 'You can get small amounts of ZEN from our free faucet, https://getzen.cash .
Registration is required. Once registered, you will be able to receive free ZEN every 24 hours.', $messageIdToReplyTo);
break;
case '/helpdesk':
case '/zensupport':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId,'Our <a href="https://support.horizen.global">ZenHelp</a> helpdesk is available around the clock. If you need help with something, try asking here: https://support.horizen.global
', $messageIdToReplyTo);
break;
case '/thanks':
if ($chatType === 'private') {
sendMessage($chatId, 'You can thank users by replying to their helping message with “/thanks”.
Their thank-score will increase which will hopefully encourage more people to help.');
}
else {
if (isset($repliedToMessageId)) {
if ($senderUserId !== $repliedToUserId && $repliedToUserId !== $ownId) {
$newScore = countThanks($repliedToUserId, $repliedToName, $repliedToUsername);
sendMessage($chatId, 'Awesome! ' . $repliedToName . '\'s thank-score is now ' . $newScore . '.', $messageIdToReplyTo);
zlog('/thanks', 'Added thanks to user ' . anonUserId($repliedToUserId));
}
}
}
break;
case '/mythanks':
if ($chatType === 'private') {
$ownScore = getOwnThankScore($senderUserId);
sendMessage($chatId, 'Your current thank-score is ' . $ownScore . '.');
//ToDo: Add Scoreboard Position
}
break;
case '/myaddress':
if ($chatType === 'private') {
if (empty($messageArr[1])) {
$address = getUserAddress($senderUserId);
$messageToSend = 'No Address supplied. Use “/myaddress t_addr” to set up your address. It will be used for the monthly giveaway for the top 3 helpers and withdrawing your tips.';
if (!empty($address)) {
$messageToSend .= '
Your current address is ' . $address;
}
sendMessage($chatId, $messageToSend);
}
else if (strlen($messageArr[1]) === 35) {
addUserAddress($senderUserId, $messageArr[1], $senderName, $senderUsername);
sendMessage($chatId, 'Your address has been set to ' . $messageArr[1]);
zlog('/myaddress', 'Added address to user ' . anonUserId($senderUserId));
}
else {
sendMessage($chatId, 'Your address is invalid. Please try again. Remember, only t-addresses are accepted.');
}
}
break;
case '/scoreboard':
if ($chatType === 'private') {
$scoreboard = getScoreboard();
sendMessage($chatId, 'These are the top 5 people with the most thanks received:
' . $scoreboard);
}
break;
case '/zengroups':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, 'Here is a list of all official chats:
' . $infos['groups'], $messageIdToReplyTo);
break;
case '/community':
break;
case '/securenoderoi':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
$roiMessage = calculateSecureRoi();
sendMessage($chatId, $roiMessage, $messageIdToReplyTo);
break;
case '/supernoderoi':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
$roiMessage = calculateSuperRoi();
sendMessage($chatId, $roiMessage, $messageIdToReplyTo);
break;
case '/nodeamount':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, "More nodes result in lower rewards for each individual node. Less nodes result in higher rewards for each individual node.
That's because nodes get 10% of the block reward, which needs to be spread across all nodes evenly.", $messageIdToReplyTo);
break;
case '/stakeratio':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
$ratio = getStakeNodeRatio();
sendMessage($chatId, "Current stake to supply ratio: $ratio%", $messageIdToReplyTo);
break;
/*
* TIPPING BOT
*/
case '/mybalance':
if ($chatType === 'private') {
$balance = number_format(getBalance($senderUserId), 8);
$balanceUnconf = number_format(getBalance($senderUserId, 0) - $balance, 8);
if ($balance === FALSE) {
}
else {
sendMessage($chatId, "Your current balance is: $balance
(Unconfirmed: $balanceUnconf)");
}
}
break;
case '/tip':
if ($chatType === 'private') {
sendMessage($chatId, "Sends a tip to the user you replied to. Without a reply attached to your message, this command won't do anything.
After tipping someone, you will have to wait for the transaction to be confirmed.
Usage: <code>/tip</code> <b>amount</b>
/tip 0.1");
die();
}
if (!empty($messageArr[1]) && isset($repliedToUserId)) {
if ($senderUserId !== $repliedToUserId && $repliedToUserId !== $config['botId']) {
$tip = $messageArr[1];
if (isset($repliedToMessageId)) {
if (is_numeric($tip) && $tip > 0) {
// /tip 0.1
if ($tip <= 1) {
$tipResult = sendTipToMessage($senderUserId, $repliedToUserId, $messageArr[1]);
zlog('/tip', 'User ' . anonUserId($senderUserId) . ' sent tip ' . $tip . ' to ' . anonUserId($repliedToUserId));
if ($tipResult === FALSE) {
}
else if ($tipResult === 'no_balance') {
//sendMessage($chatId, "You either haven't created a deposit address yet, or your tipping address doesn't contain enough ZEN. Keep in mind that there is a <b>$fee</b> fee.", $messageId);
}
else if ($tipResult === TRUE) {
if($senderUsername === NULL){
$senderUsername = $senderName;
}
sendMessage($chatId, "$senderUsername just sent you <b>$tip</b> ZEN as a tip!
See your balance by sending me a private message.", $messageIdToReplyTo);
}
}
else {
sendMessage($chatId, "For security reasons you can't tip more than 1 ZEN.", $messageId);
}
}
}
else {
//To implement later
// /tip username 0.1
}
}
}
break;
case '/deposit':
if ($chatType === 'private') {
$address = 'Feature Disabled';
$address = getDepositAddress($senderUserId);
zlog('/deposit', 'Requested depo addr for ' . anonUserId($senderUserId));
sendMessage($chatId, "
This is your deposit address:
$address
Send any amount of ZEN to it. You'll be able to withdraw it at any time by using /withdraw.
When sending tips, a fee of $fee will be subtracted from your balance.");
}
break;
case '/withdraw':
if ($chatType === 'private') {
if(!empty($messageArr[1]) && is_numeric($messageArr[1]) && $messageArr[1] > 0) {
$amount = $messageArr[1];
$result = withdraw($config, $senderUserId, $amount);
if ($result === FALSE) {
}
else if ($result === 'no_balance') {
sendMessage($chatId, "You either haven't created a deposit address yet, or your tipping address doesn't contain enough ZEN. Keep in mind that there is a <b>$fee</b> fee.");
}
else if ($result === 'no_withdraw') {
sendMessage($chatId, "There is no withdrawal address associated with your account.
You can add one with “/myaddress”.");
}
else if ($result === TRUE) {
sendMessage($chatId, "Success. Your $amount ZEN are now on their way to your /myaddress address.");
zlog('/withdraw', 'Withdraw ' . $amount . ' from ' . anonUserId($senderUserId));
}
}
else{
sendMessage($chatId, "
Sends the specified amount from your /deposit address, to your /myaddress address.
Usage: <code>/withdraw</code> <b>amount</b>
/withdraw 0.1");
die();
}
}
break;
case '/tipbot':
if ($chatType === 'private') {
sendMessage($chatId, '
To use the tipping bot you have to get your deposit address by using “/deposit”.
Send some ZEN to this address and wait for the transaction to confirm. Use the “/mybalance” command to see if your ZEN arrived.
Once you have a balance, simply reply to a users message in a group chat with “/tip” as seen on the screenshot <a href="https://puu.sh/ATVvn/d765ac3c3d.png">here</a>.
To withdraw your tips or balance you\'ll firstly have to use /myaddress to set a withdrawal address.
Then, simply use “/withdraw” with the amount behind. `/withdraw 0.1` would withdraw ' . 0.1 - $config['fee'] . ' from your tipping address and send it to the address you set with “/myaddress”.');
}
break;
/*
* TIPPING BOT
*/
case '/id':
$timeouts = checkLastExecute($timeouts, $command, $chatType, $chatId);
sendMessage($chatId, $chatId . ' ' . $senderUserId);
break;
case '/testdev':
require_once('testdev.php');
break;
default:
if ($chatType === 'private') {
sendMessage($chatId, 'Unknown command! Use /zencommands if you need assistance or contact @DatDraggy.');
}
}
file_put_contents($config['timeoutsave'], json_encode($timeouts));