using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using JetKarmaBot.Commands; using JetKarmaBot.Models; using Telegram.Bot; using Telegram.Bot.Args; using Telegram.Bot.Types; 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.SendTextMessageAsync( EventArgs.Message.Chat.Id, text, replyToMessageId: EventArgs.Message.MessageId, disableNotification: true, parseMode: Telegram.Bot.Types.Enums.ParseMode.Html); } }