Esempio n. 1
0
        public void BotRun()
        {
            context.Database.EnsureCreated();
            MainProvider provider = new MainProvider();

            client = new TelegramBotClient(Constant.Token);
            CommandProvider commandProvider = new CommandProvider(client, provider);
            AdminHandler    adminHandler    = new AdminHandler(client, provider);

            client.StartReceiving();

            List <string> commandList = CommandList.GetCommands();
            var           scope       = new ServiceCollection()
                                        .AddScoped <IMessageHandler, MessageHandler>(x => new MessageHandler(client, provider, commandProvider, adminHandler))
                                        .AddScoped <ICallbackHandler, CallBackHandler>(i => new CallBackHandler(client, provider))
                                        .BuildServiceProvider();

            client.OnCallbackQuery += async(object sender, CallbackQueryEventArgs args) =>
            {
                var callbackHandler = scope.GetService <ICallbackHandler>();
                await callbackHandler.BaseCallBackHandler(args);
            };

            client.OnMessage += async(object sender, MessageEventArgs args) =>
            {
                var handler = scope.GetService <IMessageHandler>();
                try
                {
                    await handler.BaseHandlerMessage(args, args.Message.Text);
                }
                catch (System.FormatException) { }
            };
        }
        public MessageHandler(TelegramBotClient client, MainProvider provider, CommandProvider commandProvider, AdminHandler adminHandler)
        {
            this.client          = client;
            this.provider        = provider;
            this.commandProvider = commandProvider;

            this.adminHandler = adminHandler;

            authSystem   = new AuthenticateSystem(client, provider);
            chatCommands = new ChatCommands(client, provider);
            addCash      = new AddCash(client, provider);
        }