Files
telegram-bot/modules/ChatQuotes/Handler/Quote.cs
T
2023-07-29 01:50:28 +03:00

38 lines
957 B
C#

using BotFramework;
using BotFramework.Attributes;
using BotFramework.Enums;
using Telegram.Bot;
using Telegram.Bot.Types;
namespace West.TelegramBot.ChatQuotes.Handler;
public class Quote : BotEventHandler
{
private readonly QuoteGeneratorService _quoteGenerator;
public Quote(QuoteGeneratorService quoteGenerator)
{
_quoteGenerator = quoteGenerator;
}
[InChat(InChat.Public)]
[Command("q", CommandParseMode.Both)]
public async Task HandleQuote()
{
var msg = RawUpdate.Message;
var replyToMessage = msg?.ReplyToMessage;
if (msg == null || replyToMessage == null)
{
return;
}
var quoteImage = await _quoteGenerator.GenerateQuoteImage(replyToMessage);
if (quoteImage == null)
{
return;
}
await Bot.SendStickerAsync(Chat.Id, new InputFile(quoteImage),
replyToMessageId: msg.MessageId);
}
}