|
|
@@ -221,59 +221,75 @@ class BaseService
|
|
|
if (empty($separator)) $separator = "\n";
|
|
|
$array = explode($separator, $text);
|
|
|
|
|
|
-
|
|
|
- foreach ($array as $key => $line) {
|
|
|
- if (empty(str_ireplace(" ", "", str_ireplace("\n", '', $line)))) {
|
|
|
- unset($array[$key]);
|
|
|
- } else {
|
|
|
- $array[$key] .= $separator;
|
|
|
- }
|
|
|
- }
|
|
|
- $texts = [];
|
|
|
- $len = !empty($image) ? 1024 : 4096;
|
|
|
- foreach ($array as $item) {
|
|
|
- if (count($texts) > 1) $len = 4096;
|
|
|
- if (count($texts) == 0 || strlen($texts[count($texts) - 1] . $item) > $len) {
|
|
|
- $texts[] = $item;
|
|
|
- } else {
|
|
|
- $texts[count($texts) - 1] .= $item;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
$res = [];
|
|
|
- foreach ($texts as $index => $item) {
|
|
|
- $botMsg = [
|
|
|
+ // 为空只发图片
|
|
|
+ if(empty($text) && !empty($image)) {
|
|
|
+ $botMsg = [
|
|
|
'chat_id' => "@{$bettingGroup}",
|
|
|
- 'text' => $item,
|
|
|
];
|
|
|
- if ($index > 0) {
|
|
|
- $res[] = $botMsg;
|
|
|
- self::telegram()->sendMessage($botMsg);
|
|
|
- } else {
|
|
|
- if (count($keyboard) > 0) {
|
|
|
- $botMsg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
|
|
|
- }
|
|
|
- if (!empty($image)) {
|
|
|
- unset($botMsg['text']);
|
|
|
- $botMsg['photo'] = InputFile::create($image);
|
|
|
- $botMsg['caption'] = $item;
|
|
|
- $botMsg['protect_content'] = true;
|
|
|
- $res[] = $botMsg;
|
|
|
- $response = self::telegram()->sendPhoto($botMsg);
|
|
|
+ $botMsg['photo'] = InputFile::create($image);
|
|
|
+ $botMsg['caption'] = $text;
|
|
|
+ $botMsg['protect_content'] = true; // 防止转发
|
|
|
+ if (count($keyboard) > 0) {
|
|
|
+ $botMsg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
|
|
|
+ }
|
|
|
+ $response = self::telegram()->sendPhoto($botMsg);
|
|
|
+ } else {
|
|
|
+ foreach ($array as $key => $line) {
|
|
|
+ if (empty(str_ireplace(" ", "", str_ireplace("\n", '', $line)))) {
|
|
|
+ unset($array[$key]);
|
|
|
} else {
|
|
|
- $res[] = $botMsg;
|
|
|
- $response = self::telegram()->sendMessage($botMsg);
|
|
|
+ $array[$key] .= $separator;
|
|
|
}
|
|
|
- if ($isTop === true) {
|
|
|
- self::telegram()->pinChatMessage([
|
|
|
- 'chat_id' => "@{$bettingGroup}",
|
|
|
- 'message_id' => $response->get('message_id')
|
|
|
- ]);
|
|
|
+ }
|
|
|
+ $texts = [];
|
|
|
+ $len = !empty($image) ? 1024 : 4096;
|
|
|
+ foreach ($array as $item) {
|
|
|
+ if (count($texts) > 1) $len = 4096;
|
|
|
+ if (count($texts) == 0 || strlen($texts[count($texts) - 1] . $item) > $len) {
|
|
|
+ $texts[] = $item;
|
|
|
+ } else {
|
|
|
+ $texts[count($texts) - 1] .= $item;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ foreach ($texts as $index => $item) {
|
|
|
+ $botMsg = [
|
|
|
+ 'chat_id' => "@{$bettingGroup}",
|
|
|
+ 'text' => $item,
|
|
|
+ ];
|
|
|
+ if ($index > 0) {
|
|
|
+ $res[] = $botMsg;
|
|
|
+ self::telegram()->sendMessage($botMsg);
|
|
|
+ } else {
|
|
|
+ if (count($keyboard) > 0) {
|
|
|
+ $botMsg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
|
|
|
+ }
|
|
|
+ if (!empty($image)) {
|
|
|
+ unset($botMsg['text']);
|
|
|
+ $botMsg['photo'] = InputFile::create($image);
|
|
|
+ $botMsg['caption'] = $item;
|
|
|
+ $botMsg['protect_content'] = true;
|
|
|
+ $res[] = $botMsg;
|
|
|
+ $response = self::telegram()->sendPhoto($botMsg);
|
|
|
+ } else {
|
|
|
+ $res[] = $botMsg;
|
|
|
+ $response = self::telegram()->sendMessage($botMsg);
|
|
|
+ }
|
|
|
+ if ($isTop === true) {
|
|
|
+ self::telegram()->pinChatMessage([
|
|
|
+ 'chat_id' => "@{$bettingGroup}",
|
|
|
+ 'message_id' => $response->get('message_id')
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
return $res;
|
|
|
}
|
|
|
|