Skip to content

Commit 36675a1

Browse files
committed
Initial import
0 parents  commit 36675a1

27 files changed

+2942
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
composer.phar
2+
/vendor/
3+
4+
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
5+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6+
# composer.lock
7+
8+
/.idea/
9+
10+
/config/settings.php
11+
/config/send-ips.json
12+
/storage/
13+
!/storage/.gitkeep
14+
/logs/
15+
!/logs/.gitkeep

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Vencislav Atanasov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

bin/set.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* README
4+
* This file is intended to set the webhook.
5+
* Uncommented parameters must be filled
6+
*/
7+
8+
if (PHP_SAPI !== 'cli') {
9+
exit;
10+
}
11+
12+
require __DIR__ . '/../config/init.php';
13+
14+
// Define the URL to your hook.php file
15+
$hook_url = BOT_BASE_URL . '/hook.php?' . http_build_query([
16+
'key' => TELEGRAM_API_KEY,
17+
]);
18+
19+
try {
20+
// Create Telegram API object
21+
$telegram = new Longman\TelegramBot\Telegram(TELEGRAM_API_KEY, TELEGRAM_BOT_NAME);
22+
// Set webhook
23+
$result = $telegram->setWebhook($hook_url);
24+
if ($result->isOk()) {
25+
echo $result->getDescription();
26+
}
27+
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
28+
echo $e->getMessage();
29+
}

bin/unset.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* README
4+
* This file is intended to unset the webhook.
5+
* Uncommented parameters must be filled
6+
*/
7+
8+
if (PHP_SAPI !== 'cli') {
9+
exit;
10+
}
11+
12+
require __DIR__ . '/../config/init.php';
13+
14+
try {
15+
// Create Telegram API object
16+
$telegram = new Longman\TelegramBot\Telegram(TELEGRAM_API_KEY, TELEGRAM_BOT_NAME);
17+
18+
// Delete webhook
19+
$result = $telegram->deleteWebhook();
20+
21+
if ($result->isOk()) {
22+
echo $result->getDescription();
23+
}
24+
} catch (Longman\TelegramBot\Exception\TelegramException $e) {
25+
echo $e->getMessage();
26+
}

commands/CallbackqueryCommand.php

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* This file is part of the TelegramBot package.
4+
*
5+
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Longman\TelegramBot\Commands\SystemCommands;
12+
13+
use Longman\TelegramBot\Commands\SystemCommand;
14+
use Longman\TelegramBot\Request;
15+
use Longman\TelegramBot\Entities\InlineKeyboardMarkup;
16+
use Longman\TelegramBot\Entities\InlineKeyboardButton;
17+
18+
use Longman\TelegramBot\Exception\TelegramException;
19+
20+
use Longman\TelegramBot\Commands\UserCommands\FaunaCommand;
21+
22+
use Exception;
23+
24+
/**
25+
* Callback query command
26+
*/
27+
class CallbackqueryCommand extends SystemCommand
28+
{
29+
/**#@+
30+
* {@inheritdoc}
31+
*/
32+
protected $name = 'callbackquery';
33+
protected $description = 'Reply to callback query';
34+
protected $version = '1.0.0';
35+
/**#@-*/
36+
37+
private static function answer($callback_query_id, array $data)
38+
{
39+
return Request::answerCallbackQuery(array_merge(compact('callback_query_id'), $data));
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function execute()
46+
{
47+
$update = $this->getUpdate();
48+
$callback_query = $update->getCallbackQuery();
49+
$callback_query_id = $callback_query->getId();
50+
$sender = $callback_query->getFrom();
51+
$message = $callback_query->getMessage();
52+
53+
parse_str($callback_query->getData(), $data);
54+
55+
$answerData = [];
56+
57+
if (is_array($data) && array_key_exists('cmd', $data)) {
58+
$cmd = $data['cmd'];
59+
unset($data['cmd']);
60+
61+
$config = $this->telegram->getCommandConfig($cmd);
62+
63+
switch ($cmd) {
64+
case 'fauna':
65+
$answerData = FaunaCommand::processCallback($sender, $message, $data, $config);
66+
break;
67+
default:
68+
$answerData = [
69+
'text' => 'Service ' . $cmd . ' not supported',
70+
'show_alert' => true,
71+
];
72+
break;
73+
}
74+
}
75+
else {
76+
$answerData = [
77+
'text' => 'Missing cmd parameter',
78+
'show_alert' => true,
79+
];
80+
}
81+
82+
return static::answer($callback_query_id, $answerData);
83+
}
84+
}

commands/CsCommand.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the TelegramBot package.
5+
*
6+
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Longman\TelegramBot\Commands\UserCommands;
12+
13+
use Longman\TelegramBot\Commands\UserCommand;
14+
use Longman\TelegramBot\Request;
15+
16+
use User890104\HldsStatus;
17+
18+
class CsCommand extends UserCommand
19+
{
20+
protected $name = 'cs';
21+
protected $description = 'Show Counter-Strike server status';
22+
protected $usage = '/cs';
23+
protected $version = '1.0.0';
24+
protected $enabled = true;
25+
26+
public function execute()
27+
{
28+
$update = $this->getUpdate();
29+
$message = $this->getMessage();
30+
31+
$chat_id = $message->getChat()->getId();
32+
$message_id = $message->getMessageId();
33+
$reply_to_message_id = $chat_id < 0 ? $message_id : null;
34+
35+
return Request::sendMessage([
36+
'chat_id' => $chat_id,
37+
'text' => HldsStatus::getStatus('hl.6bez10.info', 27016),
38+
'reply_to_message_id' => $reply_to_message_id,
39+
'parse_mode' => 'HTML',
40+
]);
41+
}
42+
}

0 commit comments

Comments
 (0)