Exemplo n.º 1
0
        public Step(long chatId, IBotClient client)
        {
            ChatId    = chatId;
            BotClient = client;

            CallbackActions = new Dictionary <string, Func <BotUpdate, IBotClient, Task> >();
        }
Exemplo n.º 2
0
        public ICommandStrategyFactory <IButtonCommand> CreateButtonCSF(
            IBotClient botClient,
            ISourceRepository sourceRepo,
            IMetricRepository metricRepo,
            IValueRepository valueRepo)
        {
            var buttonCommands = new List <IButtonCommand>
            {
                new AddMetricButtonCommand(botClient, sourceRepo),
                new ChooseDelMetricButtonCommand(botClient, sourceRepo, metricRepo),
                new ChooseDelValueButtonCommand(botClient, metricRepo, valueRepo),
                new ChooseMainMetricButtonCommand(botClient, sourceRepo, metricRepo),
                new DelMetricButtonCommand(botClient, sourceRepo, metricRepo),
                new DelValueButtonCommand(botClient, valueRepo),
                new FileMenuButtonCommand(botClient),
                new FromJsonButtonCommand(botClient),
                new PlotButtonCommand(botClient, metricRepo, valueRepo),
                new MetricMenuButtonCommand(botClient),
                new SetMainMetricButtonCommand(botClient, metricRepo),
                new ShowMetricButtonCommand(botClient, metricRepo),
                new ToJsonButtonCommand(botClient, metricRepo, sourceRepo),
                new TopMenuButtonCommand(botClient),
            };

            return(new ButtonCommandStrategyFactory(buttonCommands));
        }
Exemplo n.º 3
0
        public InitialCatalogueStep(long chatId, IBotClient client) : base(chatId, client)
        {
            CallbackActions.Add("Back", BackAction);

            KeyboardMarkup = new KeyboardMarkup(KeyboardTools.GetCategoriesButtonRow(CommandName));
            NextStep       = new ShowCatalogueProductsStep(ChatId, BotClient);
        }
        public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            Data.PhoneNumber = update.MessageText;
            NextStep         = new ConfirmOrderStep(ChatId, BotClient, Data);

            await SendMessageAsync(Message);
        }
Exemplo n.º 5
0
        private async Task BackAction(BotUpdate update, IBotClient client)
        {
            var next = new InitialCatalogueStep(ChatId, client);
            await next.Execute(update, client);

            NextStep = next.NextStep;
        }
Exemplo n.º 6
0
 private Task BackAction(BotUpdate update, IBotClient client)
 {
     return(Task.Run(() =>
     {
         NextStep = new ShowCatalogueProductsStep(SelectedCategoryId, ChatId, client);
     }));
 }
Exemplo n.º 7
0
        public AppMain(string baseDirectory)
        {
            this.baseDirectory = baseDirectory;

            client   = new BotClient();
            compiler = new Compiler(client);
        }
Exemplo n.º 8
0
        public async Task Execute(BotUpdate update, IBotClient client)
        {
            if (CallbackActions.Count > 0)
            {
                Func <BotUpdate, IBotClient, Task> action = null;

                var callbackWords = update.CallbackData != null?update.CallbackData.Split() : null;

                if (callbackWords != null && callbackWords[0] == CommandName)
                {
                    action = CallbackActions.SingleOrDefault(a => !string.IsNullOrEmpty(a.Key) && a.Key == callbackWords[1]).Value;
                    if (action != null)
                    {
                        await action.Invoke(update, client);
                    }
                }

                if (action == null)
                {
                    await DefaultAction(update, client);
                }
            }

            await MainAction(update, client);
        }
        public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            Data.Product = Catalog.GetProductName(update.CallbackData.Split()[1]);
            NextStep     = new SpecifyAdressStep(ChatId, BotClient, Data);

            await EditMessageAsync(Message, update.CallbackMessageId);
        }
 public override Task DefaultAction(BotUpdate update, IBotClient client)
 {
     return(Task.Run(() =>
     {
         SelectedCategoryName = Catalog.GetCategoryName(update.CallbackData.Split()[1]);
     }));
 }
 private Task BackAction(BotUpdate update, IBotClient client)
 {
     return(Task.Run(() =>
     {
         SelectedCategoryName = Catalog.GetCategoryNameByProductId(CategoryId);
     }));
 }
Exemplo n.º 12
0
        public DescribeProductStep(long chatId, IBotClient client, string selectedCategory) :
            base(chatId, client)
        {
            Data.Category = selectedCategory;

            CallbackActions.Add("Back", BackAction);
        }
        public ConnectViewModel(AppMain appMain, IBotClient client)
        {
            this.appMain = appMain;
            this.client  = client;

            Host = DefaultHost;
            Port = DefaultPort.ToString();
        }
Exemplo n.º 14
0
 internal void SwitchToReleaseMode()
 {
     if (client is DebugClient)
     {
         client   = new BotClient();
         compiler = new Compiler(client);
     }
 }
Exemplo n.º 15
0
 internal void SwitchToDebugMode()
 {
     if (!(client is DebugClient))
     {
         client   = new DebugClient();
         compiler = new Compiler(client);
     }
 }
Exemplo n.º 16
0
        public ReturnOrOrderStep(OrderData data, string categoryID, long chatId, IBotClient client) : base(chatId, client)
        {
            SelectedCategoryId = categoryID;
            Data = data;

            CallbackActions.Add("Back", BackAction);
            CallbackActions.Add("Order", OrderAction);
        }
Exemplo n.º 17
0
        public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            NextStep = new SpecifyOrderProductsStep(ChatId, BotClient, Data);

            var keyboard = new KeyboardMarkup(KeyboardTools.GetCategoriesButtonRow(CommandName));

            await SendMessageAsync(Message, keyboardMarkup : keyboard);
        }
Exemplo n.º 18
0
        public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            Data.Category = Catalog.GetCategoryName(update.CallbackData.Split()[1]);
            NextStep      = new SpecifyPhoneStep(ChatId, BotClient, Data);

            var keyboard = new KeyboardMarkup(KeyboardTools.GetProductsButtonRow(Data.Category, CommandName));

            await EditMessageAsync(Message, update.CallbackMessageId, keyboard);
        }
Exemplo n.º 19
0
 private Task OrderAction(BotUpdate update, IBotClient client)
 {
     return(Task.Run(() =>
     {
         Data.SetFullName(update.FullName);
         update.CallbackData = SelectedCategoryId;
         NextStep = new SpecifyPhoneStep(ChatId, client, Data);
     }));
 }
Exemplo n.º 20
0
        public override async Task DefaultAction(BotUpdate update, IBotClient client)
        {
            Data.Product = Catalog.GetProductName(update.CallbackData.Split()[1]);
            var backButton = new KeyboardMarkup(KeyboardTools.GetOrderAndBackButtons(Data.Product, CommandName));

            NextStep = new ReturnOrOrderStep(Data, update.CallbackData, ChatId, client);

            await EditMessageAsync($"{Message} {Data.Product}", update.CallbackMessageId, backButton);
        }
 public MenuCommandHandler(IBotClient botClient,
                           ILittleThingService littleThingService,
                           ICallbackDataFormatter callbackDataFormatter,
                           ICurrentChatService currentChatService) : base(botClient)
 {
     _littleThingService    = littleThingService;
     _callbackDataFormatter = callbackDataFormatter;
     _currentChatService    = currentChatService;
 }
Exemplo n.º 22
0
        public override async void Execute(BotUpdate update, IBotClient client)
        {
            var chatId = update.ChatId;

            await client.SendTextMessageAsync(chatId,
                                              "Используйте следующие команды чтобы:\n" +
                                              "/help - помощь\n" +
                                              "/order - оформить заказ\n" +
                                              "/catalogue - получить каталог товаров\n");
        }
        public override async Task MainAction(BotUpdate update, IBotClient clien)
        {
            Data.Adress = update.MessageText;
            NextStep    = new FinishOrderStep(ChatId, BotClient, Data);

            var keyboard = new KeyboardMarkup(KeyboardTools.GetConfirmAndCancelButtons(CommandName));

            await SendMessageAsync(Message);
            await SendMessageAsync(IsItCorrectMessage, keyboardMarkup : keyboard);
        }
Exemplo n.º 24
0
 public BotUpdateService(
     ILogger <BotUpdateService> logger,
     IBotClient botClient,
     IUpdateRepository updateRepository,
     IProcessMessageVisitor processMessageVisitor)
 {
     _logger                = logger;
     _botClient             = botClient;
     _updateRepository      = updateRepository;
     _processMessageVisitor = processMessageVisitor;
 }
Exemplo n.º 25
0
 public ValueHandlerService(
     ILogger <ValueHandlerService> logger,
     IBotClient botClient,
     IMetricRepository metricRepository,
     IValueRepository valueRepository)
 {
     _logger           = logger;
     _botClient        = botClient;
     _metricRepository = metricRepository;
     _valueRepository  = valueRepository;
 }
Exemplo n.º 26
0
 public Bot(IActionScheduler actionScheduler, IAnswerSearchEngine answerSearchEngine, IConnectedClients clients,
            IBotClient botDataClient, IBotSettings settings)
 {
     Settings           = settings;
     ActionScheduler    = actionScheduler;
     AnswerSearchEngine = answerSearchEngine;
     BotDataClient      = botDataClient;
     AnswerSearchEngine.SetApiKey(Settings.AnswerSearchApiKey);
     ConnectedClients = clients.ChatClients;
     CommandHandler   = new BotCommandHandler(this);
     _ = ScheduleRepeatedMessages();
 }
        internal ProgrammerViewModel(Compiler compiler, UserProgramRepository programRepository, IBotClient botClient)
        {
            this.compiler          = compiler;
            this.programRepository = programRepository;
            this.botClient         = botClient;

            blockViewModelFactory        = new BlockViewModelFactory();
            blockBuilderViewModelFactory = new BlockBuilderViewModelFactory();

            blocks          = programRepository.GetBlocks().ToList();
            blockViewModels = blocks.Select(b => blockViewModelFactory.CreateBlockViewModel(b, blocks)).ToList();
        }
        public override async Task MainAction(BotUpdate update, IBotClient client)
        {
            var keyboard = new KeyboardMarkup(new KeyboardButtonInfo[][]
            {
                KeyboardTools.GetProductsButtonRow(SelectedCategoryName, CommandName),
                new KeyboardButtonInfo[] { KeyboardTools.GetBackButton(CommandName) }
            });

            NextStep = new DescribeProductStep(ChatId, client, SelectedCategoryName);

            await EditMessageAsync(string.Format(Message, SelectedCategoryName), update.CallbackMessageId, keyboard);
        }
Exemplo n.º 29
0
        public ICommandStrategyFactory <ICommand> CreateCSF(IBotClient botClient)
        {
            var commands = new List <ICommand>
            {
                new StartCommand(botClient),
                new AboutCommand(botClient),
                new HelpCommand(botClient),
                new MenuCommand(botClient),
                new UnknownCommand(botClient),
            };

            return(new CommandStrategyFactory(commands));
        }
Exemplo n.º 30
0
        public MainFrame()
        {
            InitializeComponent();

            _bot = new BotClient();
            _bot.OnMessageReceived  += Bot_OnMessageReceived;
            _bot.OnConsoleOuput     += Bot_OnConsoleOuput;
            _bot.OnUptimeTick       += Bot_OnUptimeTick;
            _bot.OnUserJoined       += Bot_OnUserJoined;
            _bot.OnUserDisconnected += Bot_OnUserDisconnected;
            _timer = new SystemTimer();

            System.Threading.Thread.CurrentThread.CurrentCulture   = System.Globalization.CultureInfo.InvariantCulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
        }