protected async Task NotifyException(Exception e)
 {
     await Notifier.NotifyMessage(
         $"@{BotService.CredentialsService.Credentials.TelegramUsername}, your bot is stuck due to:\n" +
         GetExceptionInfo(e)
         );
 }
        private void Init()
        {
            try
            {
                try
                {
                    Task.Run(async() => await Bot.CheckAuth()).GetAwaiter().GetResult();

                    ScreenReader.EventProcessor = DependencyHolder.Dependencies.Resolve <LoginEventProcessor>();

                    Intent intentToAccessibility = new Intent(
                        this, typeof(ScreenReader)
                        );

                    BotService.StateService.StateInfo.Paused = true;
                    BotService.StateService.Save();

                    Bot.Start();
                    StartService(intentToAccessibility);
                    StartDelivery();
                }
                catch (PaymentRequiredException ex)
                {
                    SetContentView(Resource.Layout.liqpay);
                    WebView liqpay = FindViewById <WebView>(Resource.Id.liqPayWebView);
                }
            }
            catch (Exception e)
            {
                TelegramNotifier.NotifyMessage(
                    $"@{BotService.CredentialsService.Credentials.TelegramUsername}, your bot is stuck due to:\n" +
                    GetExceptionInfo(e)
                    ).GetAwaiter().GetResult();
            }
        }
Example #3
0
        private async Task ProcessCommand(Command <string> command)
        {
            switch (command.CommandType)
            {
            case CommandType.PAUSE:
                BotService.StateService.StateInfo.Paused = true;
                BotService.StateService.Save();
                break;

            case CommandType.RESUME:
                BotService.StateService.StateInfo.Paused = false;
                BotService.StateService.Save();
                break;

            case CommandType.GET_FILTERS_INFO:
                await Notifier.NotifyMessage(BotService.FilterService.Filters.ToString());

                break;

            case CommandType.GET_CONSTRAINTS_INFO:
                await Notifier.NotifyMessage(BotService.ConstraintsService.Constraints.ToString());

                break;

            case CommandType.GET_ACTIVE_LIST:
                string activeOrders = string.Join('\n', BotService.WorkService.WorkInfo.ActiveOrders);
                await Notifier.NotifyMessage(string.IsNullOrEmpty(activeOrders)? "No active orders" : activeOrders);

                break;

            case CommandType.GET_DAY_HISTORY:
                string doneOrders = string.Join('\n', BotService.WorkService.WorkInfo.DoneOrders);
                await Notifier.NotifyMessage(string.IsNullOrEmpty(doneOrders)? "No done orders" : doneOrders);

                break;

            case CommandType.CLEAR_DAY_HISTORY:
                if (BotService.WorkService.WorkInfo.DoneOrders.Count == 0)
                {
                    await Notifier.NotifyMessage("No history to be cleared");
                }
                else
                {
                    BotService.WorkService.WorkInfo.DoneOrders.Clear();
                    BotService.WorkService.Save();
                    await Notifier.NotifyMessage("History cleared");
                }
                break;

            case CommandType.GET_BLACK_LIST:
                if (BotService.BadOrdersService.OrdersBlackList.Count == 0)
                {
                    await Notifier.NotifyMessage("No blacklisted orders");
                }
                else
                {
                    await Notifier.NotifyMessage(string.Join("\n\n********\n\n", BotService.BadOrdersService.OrdersBlackList));
                }
                break;

            case CommandType.CLEAR_BLACK_LIST:
                if (BotService.BadOrdersService.OrdersBlackList.Count == 0)
                {
                    await Notifier.NotifyMessage("No blacklisted orders to be cleared");
                }
                else
                {
                    BotService.BadOrdersService.OrdersBlackList.Clear();
                    await Notifier.NotifyMessage("Orders blacklist cleared");
                }
                break;

            case CommandType.DELIVERED: await MarkDelivered(command.Data); break;
            }
        }