Minor Changes

This commit is contained in:
Netkas 2023-02-20 16:06:11 -05:00
parent 11e60c56c4
commit e3ed0529b9
4 changed files with 34 additions and 21 deletions

View file

@ -5,36 +5,22 @@
abstract class EventType abstract class EventType
{ {
const GenericUpdate = 'generic_update'; const GenericUpdate = 'generic_update';
const Message = 'message'; const Message = 'message';
const EditedMessage = 'edited_message'; const EditedMessage = 'edited_message';
const GenericCommandMessage = 'generic_command_message'; const GenericCommandMessage = 'generic_command_message';
const ChatMemberJoined = 'chat_member_joined'; const ChatMemberJoined = 'chat_member_joined';
const ChatMemberLeft = 'chat_member_left'; const ChatMemberLeft = 'chat_member_left';
const ChatMemberKicked = 'chat_member_kicked'; const ChatMemberKicked = 'chat_member_kicked';
const ChatMemberBanned = 'chat_member_banned'; const ChatMemberBanned = 'chat_member_banned';
const ChatMemberUnbanned = 'chat_member_unbanned'; const ChatMemberUnbanned = 'chat_member_unbanned';
const ChatMemberPromoted = 'chat_member_promoted'; const ChatMemberPromoted = 'chat_member_promoted';
const ChatMemberDemoted = 'chat_member_demoted'; const ChatMemberDemoted = 'chat_member_demoted';
const ChatMemberRestricted = 'chat_member_restricted'; const ChatMemberRestricted = 'chat_member_restricted';
const ChatMemberUnrestricted = 'chat_member_unrestricted'; const ChatMemberUnrestricted = 'chat_member_unrestricted';
const ChatMemberChanged = 'chat_member_changed';
const ChatTitleChanged = 'chat_title_changed'; const ChatTitleChanged = 'chat_title_changed';
const ChatPhotoChanged = 'chat_photo_changed'; const ChatPhotoChanged = 'chat_photo_changed';
Const CallbackQuery = 'callback_query';
const ChatDescriptionChanged = 'chat_description_changed';
} }

View file

@ -6,6 +6,7 @@
use CURLFile; use CURLFile;
use CurlHandle; use CurlHandle;
use Exception;
use InvalidArgumentException; use InvalidArgumentException;
use TgBotLib\Abstracts\ChatMemberStatus; use TgBotLib\Abstracts\ChatMemberStatus;
use TgBotLib\Abstracts\EventType; use TgBotLib\Abstracts\EventType;
@ -129,6 +130,7 @@
* Sets whether the library will use SSL to send requests * Sets whether the library will use SSL to send requests
* *
* @param bool $ssl * @param bool $ssl
* @noinspection PhpUnused
*/ */
public function setSsl(bool $ssl): void public function setSsl(bool $ssl): void
{ {
@ -405,6 +407,13 @@
$handler->handle($this, $update); $handler->handle($this, $update);
} }
break; break;
case EventType::CallbackQuery:
if(($update->getCallbackQuery() ?? null) !== null)
{
$handler->handle($this, $update);
}
break;
} }
} }
@ -2165,4 +2174,19 @@
]); ]);
return true; return true;
} }
/**
* Public Destructor
*/
public function __destruct()
{
try
{
$this->close();
}
catch(Exception $e)
{
unset($e);
}
}
} }

View file

@ -18,6 +18,8 @@
public function handle(Bot $bot, Update $update): void public function handle(Bot $bot, Update $update): void
{ {
// reply to the incoming message // reply to the incoming message
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello, ' . $update->getMessage()->getFrom()->getFirstName()); $bot->sendMessage(
$update->getMessage()->getChat()->getId(), 'Hello, ' . $update->getMessage()->getFrom()->getFirstName()
);
} }
} }

View file

@ -1,13 +1,14 @@
<?php <?php
use commands\StartCommand;
require 'ncc'; require 'ncc';
import('net.nosial.tgbotlib'); import('net.nosial.tgbotlib');
require 'commands/StartCommand.php'; require 'commands/StartCommand.php';
$bot = new TgBotLib\Bot('YOUR_BOT_TOKEN'); $bot = new TgBotLib\Bot('865804194:AAHTo9aIFP5X47dMYLJ6eoldHJnM6sc3LBc');
$bot->setCommandHandler('start', new StartCommand()); $bot->setCommandHandler('start', new \commands\StartCommand());
$bot->handleGetUpdates(true); print_r(json_encode($bot->getMe()->toArray()) . PHP_EOL);
$bot->sendMessage(570787098, 'Hello, world!');
$bot->handleGetUpdates();
unset($bot);