using Telegram.Bot; using Telegram.Bot.Types; using JetKarmaBot.Commands; namespace JetKarmaBot.Services.Handling; public class RequestContext : IServiceProvider { public ITelegramBotClient Client { get; } public Update EventArgs { get; } public CommandString Command { get; } public Dictionary Features { get; } = new Dictionary(); public RequestContext(ITelegramBotClient client, Update args, CommandString cmd) { Client = client; EventArgs = args; Command = cmd; } public object GetService(Type serviceType) => Features[serviceType]; public T GetFeature() => (T)Features[typeof(T)]; public void AddFeature(T feat) => Features[typeof(T)] = feat; //Method to reduce WET in commands public Task SendMessage(string text) => Client.SendMessage( chatId: EventArgs.Message.Chat.Id, text: text, disableNotification: true, parseMode: Telegram.Bot.Types.Enums.ParseMode.Html, replyParameters: new ReplyParameters { MessageId = EventArgs.Message.MessageId } ); }