Files
telegram-bot/modules/ChatQuotes/Handler/Quote.cs
2023-01-02 20:13:41 +02:00

37 lines
944 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;
}
[Command(InChat.Public, "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);
}
}