too many changes
This commit is contained in:
@@ -14,7 +14,7 @@ namespace MemeVault.Bot.Telegram.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Обрабатывает входящие сообщения.
|
||||
/// Поддерживает media groups (альбомы): несколько фото/видео в одном "визуальном" сообщении.
|
||||
/// Альбомы (media groups) не поддерживаются — пользователь получает уведомление.
|
||||
/// </summary>
|
||||
public sealed class MessageHandler
|
||||
{
|
||||
@@ -64,8 +64,7 @@ public sealed class MessageHandler
|
||||
{
|
||||
await SaveSingleItemAsync(message.From.Id, message.Chat.Id,
|
||||
source, mediaType,
|
||||
message.Caption ?? message.Text,
|
||||
mediaGroupId: null, ct);
|
||||
message.Caption ?? message.Text, ct);
|
||||
}
|
||||
else if (message.Text?.StartsWith('/') == true)
|
||||
{
|
||||
@@ -129,39 +128,11 @@ public sealed class MessageHandler
|
||||
var entries = JsonSerializer.Deserialize<List<MediaGroupEntry>>(raw)!;
|
||||
if (entries.Count == 0) return;
|
||||
|
||||
var first = entries[0];
|
||||
var tags = ExtractHashtags(first.Caption ?? "");
|
||||
var caption = StripHashtags(first.Caption ?? "");
|
||||
long chatId = first.ChatId;
|
||||
|
||||
// Сохраняем каждый файл группы как отдельный MediaItem, но с общим MediaGroupId
|
||||
var savedIds = new List<Guid>();
|
||||
foreach (var e in entries)
|
||||
{
|
||||
var origin = Enum.Parse<MediaOrigin>(e.Origin);
|
||||
var source = origin == MediaOrigin.Telegram
|
||||
? MediaSource.FromTelegram(e.Reference)
|
||||
: MediaSource.FromS3(e.Reference);
|
||||
|
||||
var mediaType = Enum.Parse<MediaType>(e.MediaType);
|
||||
|
||||
var id = await _mediator.Send(new SaveMediaCommand(
|
||||
e.OwnerTelegramId,
|
||||
source,
|
||||
mediaType,
|
||||
string.IsNullOrWhiteSpace(caption) ? null : caption,
|
||||
tags,
|
||||
MediaGroupId: groupId), ct);
|
||||
|
||||
savedIds.Add(id);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Saved media group {GroupId}: {Count} items", groupId, savedIds.Count);
|
||||
_logger.LogInformation("Ignored media group {GroupId}: {Count} items (unsupported)", groupId, entries.Count);
|
||||
|
||||
await _bot.SendMessage(
|
||||
chatId,
|
||||
$"✅ Альбом сохранён ({savedIds.Count} файлов)" +
|
||||
(tags.Count > 0 ? $"\nТеги: {string.Join(", ", tags.Select(t => "#" + t))}" : ""),
|
||||
entries[0].ChatId,
|
||||
"❌ Альбомы пока не поддерживаются — отправь каждый файл отдельно.",
|
||||
cancellationToken: ct);
|
||||
}
|
||||
|
||||
@@ -171,7 +142,6 @@ public sealed class MessageHandler
|
||||
long ownerId, long chatId,
|
||||
MediaSource? source, MediaType mediaType,
|
||||
string? rawText,
|
||||
string? mediaGroupId,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var tags = ExtractHashtags(rawText ?? "");
|
||||
@@ -182,8 +152,7 @@ public sealed class MessageHandler
|
||||
source,
|
||||
mediaType,
|
||||
string.IsNullOrWhiteSpace(caption) ? null : caption,
|
||||
tags,
|
||||
mediaGroupId), ct);
|
||||
tags), ct);
|
||||
|
||||
_logger.LogInformation("Saved {Type} for user {UserId}, item {ItemId}", mediaType, ownerId, id);
|
||||
|
||||
@@ -213,7 +182,7 @@ public sealed class MessageHandler
|
||||
"Теги прямо в подписи: #мем #кот\n" +
|
||||
"Поиск в инлайне: @bot #мем #кот -#толстый",
|
||||
"/help" => "📖 Команды:\n/start — приветствие\n/help — помощь\n\n" +
|
||||
"Поддерживаю: фото, видео, GIF, стикеры, текст и альбомы.",
|
||||
"Поддерживаю: фото, видео, GIF, стикеры и текст.",
|
||||
_ => "Неизвестная команда. Попробуй /help"
|
||||
};
|
||||
|
||||
|
||||
@@ -43,28 +43,42 @@ public sealed class InlineQueryHandler
|
||||
{
|
||||
var id = item.Id.ToString();
|
||||
|
||||
var tagsLine = item.Tags.Count > 0
|
||||
? string.Join(" ", item.Tags.Take(5).Select(t => "#" + t))
|
||||
: null;
|
||||
|
||||
return item.MediaType switch
|
||||
{
|
||||
MediaType.Photo => new InlineQueryResultCachedPhoto(id, item.FileId!)
|
||||
{
|
||||
Caption = item.Caption,
|
||||
Title = item.InlineTitle,
|
||||
Description = item.InlineDescription ?? tagsLine,
|
||||
},
|
||||
|
||||
MediaType.Video => new InlineQueryResultCachedVideo(id, item.FileId!, item.Caption ?? "Video"),
|
||||
MediaType.Video => new InlineQueryResultCachedVideo(
|
||||
id,
|
||||
item.FileId!,
|
||||
title: item.InlineTitle ?? item.Caption ?? "Video")
|
||||
{
|
||||
Caption = item.Caption,
|
||||
Description = item.InlineDescription ?? tagsLine,
|
||||
},
|
||||
|
||||
MediaType.Sticker => new InlineQueryResultCachedSticker(id, item.FileId!),
|
||||
|
||||
MediaType.Animation => new InlineQueryResultCachedMpeg4Gif(id, item.FileId!)
|
||||
{
|
||||
Caption = item.Caption,
|
||||
Title = item.InlineTitle,
|
||||
},
|
||||
|
||||
MediaType.Text => new InlineQueryResultArticle(
|
||||
id,
|
||||
title: item.Caption?[..Math.Min(60, item.Caption.Length)] ?? "Текст",
|
||||
title: item.InlineTitle ?? item.Caption?[..Math.Min(60, item.Caption.Length)] ?? "Текст",
|
||||
inputMessageContent: new InputTextMessageContent(item.Caption ?? ""))
|
||||
{
|
||||
Description = string.Join(" ", item.Tags.Take(5).Select(t => "#" + t)),
|
||||
Description = item.InlineDescription ?? tagsLine,
|
||||
},
|
||||
|
||||
_ => null
|
||||
|
||||
Reference in New Issue
Block a user