Ejemplo n.º 1
0
 public UserRequestProcess(TelegramBotClient bot, string username, long chatId)
 {
     Username    = username;
     CurrentStep = RequestSteps.Start;
     _bot        = bot;
     _chatId     = chatId;
 }
Ejemplo n.º 2
0
        private async Task ProcessChangeBank(string msg)
        {
            await Task.Delay(100);

            if (msg.Equals(LD.CancelKey) || msg.Equals("/start"))
            {
                await Start();

                return;
            }

            if (!msg.Equals(LD.SkipKey))
            {
                _bank = StripTagsRegex(msg);
            }
            else
            {
                _bank = string.Empty;
            }

            CurrentStep = RequestSteps.ChangeEndDate;
            var keyboard = new InlineKeyboardMarkup(new[]
            {
                new[]     // first row
                {
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.CancelKey), LD.CancelKey),
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.SkipKey), LD.SkipKey),
                }
            });

            await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.EnterReqDurationKey), ParseMode.Default, keyboard);
        }
Ejemplo n.º 3
0
        private async Task ProcessBank(string msg)
        {
            await Task.Delay(100);

            if (msg.Equals(LD.CancelKey) || msg.Equals("/start"))
            {
                Console.WriteLine(Username + " Отмена");
                await Start();

                return;
            }

            if (string.IsNullOrEmpty(msg))
            {
                await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.WrongInputKey));

                return;
            }

            _bank = StripTagsRegex(msg);

            CurrentStep = RequestSteps.EnterEndDate;
            var keyboard = new InlineKeyboardMarkup(new[]
            {
                new[]     // first row
                {
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.CancelKey), LD.CancelKey),
                }
            });

            await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.EnterReqDurationKey), ParseMode.Default, keyboard);
        }
Ejemplo n.º 4
0
        private async Task ProcessQuantityAndFee(string msg)
        {
            await Task.Delay(100);

            if (msg.Equals(LD.CancelKey) || msg.Equals("/start"))
            {
                Console.WriteLine(Username + " Отмена");
                await Start();

                return;
            }

            string[] splitted = msg.Split(' ');

            if (splitted.Length < 3 || !int.TryParse(splitted[0], out _quantity) || !float.TryParse(splitted[2], out _fee))
            {
                await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.WrongInputKey));
                await ProcessStartState(_reqType == RequestType.Buy?LD.BuyKey : LD.SellKey);

                return;
            }

            _currency = splitted[1];

            CurrentStep = RequestSteps.EnterBank;
            var keyboard = new InlineKeyboardMarkup(new[]
            {
                new[]     // first row
                {
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.CancelKey), LD.CancelKey),
                }
            });

            await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.EnterBankNameKey), ParseMode.Default, keyboard);
        }
Ejemplo n.º 5
0
        public async Task Start()
        {
            CurrentStep = RequestSteps.Start;

            bool enabledNotifications = Database.IsNotificationsRowExistForUser(Username);
            var  keyboard             = new InlineKeyboardMarkup(new[]
            {
                new[]     // first row
                {
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.BuyKey), LD.BuyKey),
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.SellKey), LD.SellKey),
                },
                new[]     // third row
                {
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.ShowMyReqKey), LD.ShowMyReqKey),
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.ShowAllReqKey), LD.ShowAllReqKey),
                },
                new[]
                {
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.VoteKey), LD.VoteKey),
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.UnvoteKey), LD.UnvoteKey),
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.EscrowListKey), LD.EscrowListKey),
                },
                new []
                {
                    InlineKeyboardButton.WithCallbackData(enabledNotifications ? LD.GetTranslate(Username, LD.DisableNotifKey) : LD.GetTranslate(Username, LD.EnableNotifKey),
                                                          enabledNotifications ? LD.DisableNotifKey : LD.EnableNotifKey),
                },
                new []
                {
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.EnglishKey), LD.EnglishKey),
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.RussianKey), LD.RussianKey),
                }
            });

            try
            {
                if (_startMessage != null)
                {
                    await _bot.DeleteMessageAsync(_chatId, _startMessage.MessageId);
                }
            }
            catch
            {
                _startMessage = null;
            }

            _startMessage = await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.StartMessageKey), ParseMode.Html, keyboard);
        }
Ejemplo n.º 6
0
        private async Task ProcessChangeQuantityAndFee(string msg)
        {
            await Task.Delay(100);

            if (msg.Equals(LD.CancelKey) || msg.Equals("/start"))
            {
                await Start();

                return;
            }

            if (!msg.Equals(LD.SkipKey))
            {
                string[] splitted = msg.Split(' ');

                if (splitted.Length < 3 || !int.TryParse(splitted[0], out _quantity) || !float.TryParse(splitted[2], out _fee))
                {
                    await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.WrongInputKey));

                    return;
                }

                _currency = splitted[1];
            }
            else
            {
                _currency = string.Empty;
                _quantity = -1;
                _fee      = -1f;
            }

            CurrentStep = RequestSteps.ChangeBank;
            var keyboard = new InlineKeyboardMarkup(new[]
            {
                new[]     // first row
                {
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.CancelKey), LD.CancelKey),
                    InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.SkipKey), LD.SkipKey),
                }
            });

            await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.EnterBankNameKey), ParseMode.Default, keyboard);
        }
Ejemplo n.º 7
0
        private async Task ProcessStartState(string msg)
        {
            await Task.Delay(100);

            if (msg.Equals(LD.SellKey))
            {
                Console.WriteLine(Username + " Продать");
                _reqType    = RequestType.Sell;
                CurrentStep = RequestSteps.EnterQuantityAndFee;

                var keyboard = new InlineKeyboardMarkup(new[]
                {
                    new[] // first row
                    {
                        InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.CancelKey), LD.CancelKey),
                    }
                });

                await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.SellingMsgKey), ParseMode.Html, keyboard);
            }
            else if (msg.Equals(LD.BuyKey))
            {
                Console.WriteLine(Username + " Купить");
                _reqType    = RequestType.Buy;
                CurrentStep = RequestSteps.EnterQuantityAndFee;

                var keyboard = new InlineKeyboardMarkup(new[]
                {
                    new[] // first row
                    {
                        InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.CancelKey), LD.CancelKey),
                    }
                });

                await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.BuyingMsgKey), ParseMode.Html, keyboard);
            }
            else if (msg.Contains(LD.RemoveKey))
            {
                int id;
                if (!ParseReqId(msg, out id))
                {
                    await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.RemoveErrorKey));

                    return;
                }
                Console.WriteLine(Username + " Удалить заявку №" + id);

                Database.DeleteReqWithId(Username, id);
                await SendMessageAsync(_chatId, string.Format(LD.GetTranslate(Username, LD.RemoveSuccessKey), id));
            }
            else if (msg.Contains(LD.ChangeKey))
            {
                int id;
                if (!ParseReqId(msg, out id))
                {
                    await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.ChangeErrorKey));

                    return;
                }

                Console.WriteLine(Username + " Изменить заявку №" + id);

                CurrentStep     = RequestSteps.ChangeQuantityAndFee;
                _reqIdForUpdate = id;

                var keyboard = new InlineKeyboardMarkup(new[]
                {
                    new[] // first row
                    {
                        InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.CancelKey), LD.CancelKey),
                        InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.SkipKey), LD.SkipKey),
                    }
                });
                await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.ChangingMsgKey), ParseMode.Html, keyboard);
            }
            else if (msg.Equals(LD.ShowMyReqKey))
            {
                Console.WriteLine(Username + " Посмотреть мои заявки");
                await ProcessShowMy();
            }
            else if (msg.Equals(LD.ShowAllReqKey))
            {
                Console.WriteLine(Username + " Посмотреть все заявки");
                await ProcessShowAll();
            }
            else if (msg.Equals(LD.VoteKey))
            {
                if (Database.GetVotesCount(Username) <= 0)
                {
                    await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.ZeroVotesKey));

                    return;
                }
                CurrentStep = RequestSteps.VoteUser;

                var keyboard = new InlineKeyboardMarkup(new[]
                {
                    new[] // first row
                    {
                        InlineKeyboardButton.WithCallbackData(LD.GetTranslate(Username, LD.CancelKey), LD.CancelKey),
                    }
                });
                await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.VotingMsgKey), ParseMode.Html, replyMarkup : keyboard);
            }
            else if (msg.Equals(LD.UnvoteKey))
            {
                var votedUsersList = Database.GetMyVotedUsers(Username);

                if (votedUsersList.Count == 0)
                {
                    await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.VoteListEmptyKey));

                    return;
                }

                CurrentStep    = RequestSteps.UnvoteUser;
                _unvoteMessage = await SendMessageAsync(_chatId, string.Format(@"<b>{0}</b>", LD.GetTranslate(Username, LD.UnvoteKey)), ParseMode.Html, replyMarkup : GetMarkupForUnvote(votedUsersList));
            }
            else if (msg.Equals(LD.EscrowListKey))
            {
                await ProcessEscrowList();
            }
            else if (msg.Contains(LD.DisableNotifKey))
            {
                Console.WriteLine(Username + " Выключить оповещения");
                Database.DeleteUserFromNotifications(Username);

                await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.NotificationsDisabledKey));
                await Start();
            }
            else if (msg.Contains(LD.EnableNotifKey))
            {
                Console.WriteLine(Username + " Включить оповещения");

                if (!Database.IsNotificationsRowExistForUser(Username))
                {
                    Database.AddUserForNotifications(Username, _chatId);
                }

                await SendMessageAsync(_chatId, LD.GetTranslate(Username, LD.NotificationsEnabledKey));
                await Start();
            }
            else if (msg.Contains(LD.EnglishKey))
            {
                Database.SetUserLanguage(Username, Languages.English);
                await Start();
            }
            else if (msg.Contains(LD.RussianKey))
            {
                Database.SetUserLanguage(Username, Languages.Russian);
                await Start();
            }
        }