Merge branch 'master' into dev

This commit is contained in:
Netkas 2023-02-25 06:51:56 -05:00
commit a9023f116c
3 changed files with 154 additions and 36 deletions

3
.idea/php.xml generated
View file

@ -14,7 +14,8 @@
<path value="/usr/share/php" /> <path value="/usr/share/php" />
<path value="/etc/ncc" /> <path value="/etc/ncc" />
<path value="/var/ncc/packages/net.nosial.tamerlib=1.0.0" /> <path value="/var/ncc/packages/net.nosial.tamerlib=1.0.0" />
<path value="/var/ncc/packages/net.nosial.loglib=1.0.0" /> <path value="/var/ncc/packages/net.nosial.loglib=1.0.1" />
<path value="/var/ncc/packages/net.nosial.tempfile=1.0.0" />
</include_path> </include_path>
</component> </component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.0"> <component name="PhpProjectSharedConfiguration" php_language_level="8.0">

View file

@ -12,7 +12,7 @@
"package": "net.nosial.tgbotlib", "package": "net.nosial.tgbotlib",
"description": "TgBotLib is a library for interacting with the Telegram Bot API", "description": "TgBotLib is a library for interacting with the Telegram Bot API",
"company": "Nosial", "company": "Nosial",
"version": "6.5.1", "version": "6.5.2",
"uuid": "b409e036-ab04-11ed-b32e-9d3f57a644ae" "uuid": "b409e036-ab04-11ed-b32e-9d3f57a644ae"
}, },
"build": { "build": {
@ -24,6 +24,12 @@
"version": "latest", "version": "latest",
"source_type": "remote", "source_type": "remote",
"source": "nosial/libs.log=latest@n64" "source": "nosial/libs.log=latest@n64"
},
{
"name": "net.nosial.tempfile",
"version": "latest",
"source_type": "remote",
"source": "nosial/libs.tempfile=latest@n64"
} }
], ],
"configurations": [ "configurations": [

View file

@ -5,10 +5,10 @@
namespace TgBotLib; namespace TgBotLib;
use CURLFile; use CURLFile;
use CurlHandle;
use Exception; use Exception;
use InvalidArgumentException; use InvalidArgumentException;
use LogLib\Log; use LogLib\Log;
use TempFile\TempFile;
use TgBotLib\Abstracts\ChatMemberStatus; use TgBotLib\Abstracts\ChatMemberStatus;
use TgBotLib\Abstracts\EventType; use TgBotLib\Abstracts\EventType;
use TgBotLib\Exceptions\TelegramException; use TgBotLib\Exceptions\TelegramException;
@ -141,6 +141,7 @@
*/ */
private function getMethodUrl(string $method): string private function getMethodUrl(string $method): string
{ {
/** @noinspection HttpUrlsUsage */
return ($this->ssl ? 'https://' : 'http://') . $this->host . '/bot' . $this->token . '/' . $method; return ($this->ssl ? 'https://' : 'http://') . $this->host . '/bot' . $this->token . '/' . $method;
} }
@ -442,7 +443,7 @@
if(($update->getMessage() ?? null) !== null && ($update->getMessage()->getText() ?? null) !== null) if(($update->getMessage() ?? null) !== null && ($update->getMessage()->getText() ?? null) !== null)
{ {
$text = $update->getMessage()->getText(); $text = $update->getMessage()->getText();
if(strpos($text, '/') === 0) if(str_starts_with($text, '/'))
{ {
$command = explode(' ', substr($text, 1))[0]; $command = explode(' ', substr($text, 1))[0];
if(isset($this->command_handlers[$command])) if(isset($this->command_handlers[$command]))
@ -691,11 +692,24 @@
]))); ])));
} }
return Message::fromArray($this->sendRequest('sendPhoto', array_merge($options, [ $tmp_file = new TempFile();
'chat_id' => $chat_id, file_put_contents($tmp_file, $photo);
'photo' => $photo
try
{
$response = Message::fromArray($this->sendFileUpload('sendPhoto', 'photo', $tmp_file, array_merge($options, [
'chat_id' => $chat_id
]))); ])));
} }
catch(TelegramException $e)
{
unset($tmp_file);
throw $e;
}
unset($tmp_file);
return $response;
}
/** /**
* Use this method to send audio files, if you want Telegram clients to display them in the music player. Your * Use this method to send audio files, if you want Telegram clients to display them in the music player. Your
@ -721,11 +735,24 @@
]))); ])));
} }
return Message::fromArray($this->sendRequest('sendAudio', array_merge($options, [ $tmp_file = new TempFile();
'chat_id' => $chat_id, file_put_contents($tmp_file, $audio);
'audio' => $audio
try
{
$response = Message::fromArray($this->sendFileUpload('sendAudio', 'audio', $tmp_file, array_merge($options, [
'chat_id' => $chat_id
]))); ])));
} }
catch(TelegramException $e)
{
unset($tmp_file);
throw $e;
}
unset($tmp_file);
return $response;
}
/** /**
* Use this method to send general files. On success, the sent Message is returned. Bots can currently send * Use this method to send general files. On success, the sent Message is returned. Bots can currently send
@ -748,11 +775,24 @@
]))); ])));
} }
return Message::fromArray($this->sendRequest('sendDocument', array_merge($options, [ $tmp_file = new TempFile();
'chat_id' => $chat_id, file_put_contents($tmp_file, $document);
'document' => $document
try
{
$response = Message::fromArray($this->sendFileUpload('sendDocument', 'document', $tmp_file, array_merge($options, [
'chat_id' => $chat_id
]))); ])));
} }
catch(TelegramException $e)
{
unset($tmp_file);
throw $e;
}
unset($tmp_file);
return $response;
}
/** /**
* Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as * Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as
@ -776,11 +816,24 @@
]))); ])));
} }
return Message::fromArray($this->sendRequest('sendVideo', array_merge($options, [ $tmp_file = new TempFile();
'chat_id' => $chat_id, file_put_contents($tmp_file, $video);
'video' => $video
try
{
$response = Message::fromArray($this->sendFileUpload('sendVideo', 'video', $tmp_file, array_merge($options, [
'chat_id' => $chat_id
]))); ])));
} }
catch(TelegramException $e)
{
unset($tmp_file);
throw $e;
}
unset($tmp_file);
return $response;
}
/** /**
* Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent * Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent
@ -804,11 +857,24 @@
]))); ])));
} }
return Message::fromArray($this->sendRequest('sendAnimation', array_merge($options, [ $tmp_file = new TempFile();
'chat_id' => $chat_id, file_put_contents($tmp_file, $animation);
'animation' => $animation
try
{
$response = Message::fromArray($this->sendFileUpload('sendAnimation', 'animation', $tmp_file, array_merge($options, [
'chat_id' => $chat_id
]))); ])));
} }
catch(TelegramException $e)
{
unset($tmp_file);
throw $e;
}
unset($tmp_file);
return $response;
}
/** /**
* Use this method to send audio files, if you want Telegram clients to display the file as a playable voice * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice
@ -833,11 +899,24 @@
]))); ])));
} }
return Message::fromArray($this->sendRequest('sendVoice', array_merge($options, [ $tmp_file = new TempFile();
'chat_id' => $chat_id, file_put_contents($tmp_file, $voice);
'voice' => $voice
try
{
$response = Message::fromArray($this->sendFileUpload('sendVoice', 'voice', $tmp_file, array_merge($options, [
'chat_id' => $chat_id
]))); ])));
} }
catch(TelegramException $e)
{
unset($tmp_file);
throw $e;
}
unset($tmp_file);
return $response;
}
/** /**
* As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to * As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to
@ -859,10 +938,15 @@
]))); ])));
} }
return Message::fromArray($this->sendRequest('sendVideoNote', array_merge($options, [ $tmp_file = new TempFile();
'chat_id' => $chat_id, file_put_contents($tmp_file, $video_note);
'video_note' => $video_note
$response = Message::fromArray($this->sendFileUpload('sendVideoNote', 'video_note', $tmp_file, array_merge($options, [
'chat_id' => $chat_id
]))); ])));
unset($tmp_file);
return $response;
} }
/** /**
@ -1420,11 +1504,22 @@
return true; return true;
} }
$this->sendRequest('setChatPhoto', [ $tmp_file = new TempFile();
'chat_id' => $chat_id, file_put_contents($tmp_file, $photo);
'photo' => $photo
]);
try
{
$this->sendFileUpload('sendChatPhoto', 'photo', $tmp_file, [
'chat_id' => $chat_id
]);
}
catch(TelegramException $e)
{
unset($tmp_file);
throw $e;
}
unset($tmp_file);
return true; return true;
} }
@ -2131,7 +2226,23 @@
); );
} }
return Message::fromArray($this->sendRequest('editMessageMedia', $options)); $tmp_file = new TempFile();
file_put_contents($tmp_file, $media);
try
{
$response = Message::fromArray(
$this->sendFileUpload('editMessageMedia', 'media', $tmp_file, $options)
);
}
catch(TelegramException $e)
{
unset($tmp_file);
throw $e;
}
unset($tmp_file);
return $response;
} }
/** /**