Exemplo n.º 1
0
        public async Task <IActionResult> Update([FromBody] BotUpdateInput input)
        {
            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            _messageRepository.InsertMessage(new MessageEntity()
            {
                UserId = user?.Id,
                ChatId = input.Message.Chat.Id.ToString(),
                Text   = input.Message.Text,
                Date   = DateTime.Now
            });

            string commandString = (input.Message.Text + " ").Split(' ')[0].TrimStart('/');

            if (!commands.ContainsKey(commandString))
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid command!");
            }
            else
            {
                Type commandType = commands[commandString];

                IBotCommand command = HttpContext.RequestServices.GetService(commandType) as IBotCommand;

                await command.ExecuteAsync(input);
            }

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string message = input.Message.Text.Trim();

            message = message.Replace((message + " ").Split(' ')[0], string.Empty).Trim();

            List <string> values = message.Contains(" ") ? message.Split(' ').ToList() : new List <string>()
            {
                message
            };

            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            if (user == null || user.Type != UserTypeEnum.Admin)
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Unauthorized!");

                return;
            }

            if (values[0] == "get")
            {
                if (values.Count == 1)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                if (values[1] == "all")
                {
                    var response2 = _socketServiceManager.CheckStatus();

                    await _messageService.SendMessageAsync(user.ChatId, response2);

                    return;
                }

                var symbol = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Name == values[1].ToUpperInvariant() || x.FriendlyName == values[1].ToUpperInvariant());

                if (symbol == null)
                {
                    await _messageService.SendMessageAsync(user.ChatId, "Symbol is not found!");

                    return;
                }

                var response = _socketServiceManager.CheckSymbolStatus(symbol.Id);

                await _messageService.SendMessageAsync(user.ChatId, response);
            }
            else
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                return;
            }
        }
Exemplo n.º 3
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string message = input.Message.Text.Trim();

            message = message.Replace((message + " ").Split(' ')[0], string.Empty).Trim();

            List <string> values = message.Contains(" ") ? message.Split(' ').ToList() : new List <string>()
            {
                message
            };

            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            if (user == null)
            {
                user = new UserEntity();
            }

            user.ChatId    = input.Message.Chat.Id.ToString();
            user.Username  = input.Message.From.Username;
            user.FirstName = input.Message.From.FirstName;
            user.LastName  = input.Message.From.LastName;

            if (values[0] != "normal!123" && values[0] != "admin!123")
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid key!");
            }

            if (values[0] == "normal!123")
            {
                user.Type = UserTypeEnum.Normal;
            }
            else if (values[0] == "admin!123")
            {
                user.Type = UserTypeEnum.Admin;
            }

            if (string.IsNullOrEmpty(user.Id))
            {
                _userRepository.InsertUser(user);
            }
            else
            {
                _userRepository.UpdateUser(user);
            }

            _socketServiceManager.UpdateUsers();

            await _messageService.SendMessageAsync(user.ChatId, "Success!");

            var admins = _userRepository.FindUsers().Where(x => x.Type == UserTypeEnum.Admin);

            foreach (var admin in admins)
            {
                await _messageService.SendMessageAsync(admin.ChatId, $"{input.Message.From.Username} is added to users!");
            }
        }
Exemplo n.º 4
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string result = $"Wellcome @{input.Message.From.Username}!\r\n";

            result += "If you want to authenticate this bot, please type /auth command with password.\r\n\r\n";

            result += "Example:\r\n/auth 123456";

            await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), result);

            var admins = _userRepository.FindUsers().Where(x => x.Type == UserTypeEnum.Admin);

            foreach (var admin in admins)
            {
                await _messageService.SendMessageAsync(admin.ChatId, $"@{input.Message.From.Username} is joined!");
            }
        }
Exemplo n.º 5
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string message = input.Message.Text.Trim();

            message = message.Replace((message + " ").Split(' ')[0], string.Empty).Trim();

            List <string> values = message.Contains(" ") ? message.Split(' ').ToList() : new List <string>()
            {
                message
            };

            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            if (user == null)
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Unauthorized!");

                return;
            }

            if (values[0] == "all")
            {
                _socketServiceManager.ResetCache(user.Id);

                await _messageService.SendMessageAsync(user.ChatId, "Success!");

                return;
            }
            else
            {
                var symbol = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Name == values[0].ToUpperInvariant() || x.FriendlyName == values[0].ToUpperInvariant());

                if (symbol == null)
                {
                    await _messageService.SendMessageAsync(user.ChatId, "Symbol is not found!");

                    return;
                }

                _socketServiceManager.ResetCache(user.Id, symbol.Id);

                await _messageService.SendMessageAsync(user.ChatId, "Success!");
            }
        }
Exemplo n.º 6
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string message = input.Message.Text.Trim();

            message = message.Replace((message + " ").Split(' ')[0], string.Empty).Trim();

            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            if (user == null || user.Type != UserTypeEnum.Admin)
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Unauthorized!");

                return;
            }

            var users = _userRepository.FindUsers();

            foreach (var item in users)
            {
                await _messageService.SendMessageAsync(item.ChatId, message);
            }
        }
Exemplo n.º 7
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string message = input.Message.Text.Trim();

            message = message.Replace((message + " ").Split(' ')[0], string.Empty).Trim();

            List <string> values = message.Contains(" ") ? message.Split(' ').ToList() : new List <string>()
            {
                message
            };

            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            if (user == null || user.Type != UserTypeEnum.Admin)
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Unauthorized!");

                return;
            }

            if (values[0] == "get")
            {
                if (values.Count == 1)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                if (values[1] == "all")
                {
                    string result = string.Empty;

                    var users = _userRepository.FindUsers();

                    foreach (var item in users)
                    {
                        result += $"@{item.Username} - {item.FirstName} {item.LastName}\r\n";
                    }

                    await _messageService.SendMessageAsync(user.ChatId, result);
                }
                else
                {
                    var usr = _userRepository.FindUser(values[1]);

                    if (usr == null)
                    {
                        await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "User is not found!");

                        return;
                    }

                    await _messageService.SendMessageAsync(user.ChatId, $"@{usr.Username} - {usr.FirstName} {usr.LastName}");
                }
            }
            else
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                return;
            }
        }
Exemplo n.º 8
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            List <string> lines = new List <string>();

            if (user == null)
            {
                lines.Add("Authenticate the bot");
                lines.Add("/auth <password>");
                lines.Add(string.Empty);
            }
            else
            {
                if (user.Type == UserTypeEnum.Admin)
                {
                    lines.Add("Send command to console");
                    lines.Add("/console <command>");
                    lines.Add(string.Empty);

                    lines.Add("Send message to all users");
                    lines.Add("/message <message>");
                    lines.Add(string.Empty);

                    lines.Add("Get symbol streams status");
                    lines.Add("/status get <all|symbol>");
                    lines.Add(string.Empty);
                }

                lines.Add("Manage your subscriptions");
                lines.Add("/subscriptions get <all|symbol>");
                lines.Add("/subscriptions set <all|symbol>");
                lines.Add("/subscriptions del <all|symbol>");
                lines.Add(string.Empty);

                lines.Add("Manage your alerts");
                lines.Add("/alerts get <all|symbol>");
                lines.Add("/alerts set <symbol> less <value>");
                lines.Add("/alerts set <symbol> greater <value>");
                lines.Add("/alerts del <symbol>");
                lines.Add(string.Empty);

                lines.Add("Get price history");
                lines.Add("/prices get <all|symbol> <interval>");
                lines.Add(string.Empty);

                lines.Add("Manage your settings");
                lines.Add("/settings get <all|key>");
                lines.Add("/settings set <key> <value>");
                lines.Add("/settings del <key>");
                lines.Add(string.Empty);

                lines.Add("Reset a symbol changes cache");
                lines.Add("/reset <all|symbol>");
                lines.Add(string.Empty);

                lines.Add("Help commands");
                lines.Add("/help");
                lines.Add(string.Empty);
            }

            await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), string.Join("\r\n", lines));
        }
Exemplo n.º 9
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string message = input.Message.Text.Trim();

            message = message.Replace((message + " ").Split(' ')[0], string.Empty).Trim();

            List <string> values = message.Contains(" ") ? message.Split(' ').ToList() : new List <string>()
            {
                message
            };

            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            if (user == null)
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Unauthorized!");

                return;
            }

            // "/subscriptions get <all|symbol>"
            if (values[0] == "get")
            {
                if (values.Count == 1)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                if (values[1] == "all")
                {
                    var subscriptions = _subscriptionRepository.FindSubscriptions().Where(x => x.UserId == user.Id);

                    List <string> lines = new List <string>();

                    foreach (var item in subscriptions)
                    {
                        var sym = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Id == item.SymbolId);

                        lines.Add($"{sym.FriendlyName} for minimum {(item.MinimumChange * 100).ToString("0.00")}% change");
                    }

                    if (!lines.Any())
                    {
                        await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "There are no subscriptions!");

                        return;
                    }

                    lines = lines.OrderBy(x => x).ToList();

                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), string.Join("\r\n", lines));

                    return;
                }
                else
                {
                    var symbol = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Name == values[1].ToUpperInvariant() || x.FriendlyName == values[1].ToUpperInvariant());

                    if (symbol == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Symbol is not found!");

                        return;
                    }

                    var subscription = _subscriptionRepository.FindSubscription(symbol.Id, user.Id);

                    if (subscription == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Subscription is not found!");

                        return;
                    }

                    await _messageService.SendMessageAsync(user.ChatId, $"{symbol.FriendlyName} for minimum {(subscription.MinimumChange * 100).ToString("0.00")}% change\r\n");
                }
            }
            // "/subscriptions set <all|symbol> <change?>"
            else if (values[0] == "set")
            {
                if (values.Count == 1)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                if (values[1] == "all")
                {
                    decimal minimumChange = (decimal)0.02;

                    if (values.Count > 2)
                    {
                        if (!decimal.TryParse(values[2], out minimumChange))
                        {
                            await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                            return;
                        }

                        minimumChange /= 100;
                    }

                    var symbols = _symbolRepository.FindSymbols();

                    foreach (var symbol in symbols)
                    {
                        var subscription = _subscriptionRepository.FindSubscription(symbol.Id, user.Id);

                        if (subscription == null)
                        {
                            _subscriptionRepository.InsertSubscription(new SubscriptionEntity()
                            {
                                UserId        = user.Id,
                                SymbolId      = symbol.Id,
                                MinimumChange = minimumChange
                            });
                        }
                        else
                        {
                            subscription.MinimumChange = minimumChange;

                            _subscriptionRepository.UpdateSubscription(subscription);
                        }
                    }
                }
                else
                {
                    decimal minimumChange = (decimal)0.02;

                    if (values.Count > 2)
                    {
                        if (!decimal.TryParse(values[2], out minimumChange))
                        {
                            await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                            return;
                        }

                        minimumChange /= 100;
                    }

                    var symbol = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Name == values[1].ToUpperInvariant() || x.FriendlyName == values[1].ToUpperInvariant());

                    if (symbol == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Symbol is not found!");

                        return;
                    }

                    if (minimumChange < symbol.MinimumChange)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, $"Minimum Change should be at least {(symbol.MinimumChange * 100).ToString("0.00")}!");

                        return;
                    }

                    var subscription = _subscriptionRepository.FindSubscription(symbol.Id, user.Id);

                    if (subscription == null)
                    {
                        _subscriptionRepository.InsertSubscription(new SubscriptionEntity()
                        {
                            UserId        = user.Id,
                            SymbolId      = symbol.Id,
                            MinimumChange = minimumChange
                        });
                    }
                    else
                    {
                        subscription.MinimumChange = minimumChange;

                        _subscriptionRepository.UpdateSubscription(subscription);
                    }
                }

                _socketServiceManager.UpdateSubscription(user.Id);

                await _messageService.SendMessageAsync(user.ChatId, "Success!");
            }
            // "/subscriptions del <all|symbol>"
            else if (values[0] == "del")
            {
                if (values.Count == 1)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                if (values[1] == "all")
                {
                    var subscriptions = _subscriptionRepository.FindSubscriptions().Where(x => x.UserId == user.Id);

                    foreach (var subscription in subscriptions)
                    {
                        _subscriptionRepository.RemoveSubscription(subscription.Id);
                    }
                }
                else
                {
                    var symbol = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Name == values[1].ToUpperInvariant() || x.FriendlyName == values[1].ToUpperInvariant());

                    if (symbol == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Symbol is not found!");

                        return;
                    }

                    var subscription = _subscriptionRepository.FindSubscription(symbol.Id, user.Id);

                    if (subscription == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Subscription is not found!");

                        return;
                    }

                    _subscriptionRepository.RemoveSubscription(subscription.Id);
                }

                _socketServiceManager.UpdateSubscription(user.Id);

                await _messageService.SendMessageAsync(user.ChatId, "Success!");
            }
            else
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                return;
            }
        }
Exemplo n.º 10
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string message = input.Message.Text.Trim();

            message = message.Replace((message + " ").Split(' ')[0], string.Empty).Trim();

            List <string> values = message.Contains(" ") ? message.Split(' ').ToList() : new List <string>()
            {
                message
            };

            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            if (user == null)
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Unauthorized!");

                return;
            }

            if (values[0] == "get")
            {
                if (values.Count < 3)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                DateTime startDate = DateTime.Now;

                if (values[2].EndsWith("h"))
                {
                    int interval;

                    if (!int.TryParse(values[2].Replace("h", string.Empty), out interval))
                    {
                        await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                        return;
                    }

                    startDate = DateTime.Now.AddHours(-1 * interval);
                }
                else if (values[2].EndsWith("m"))
                {
                    int interval;

                    if (!int.TryParse(values[2].Replace("m", string.Empty), out interval))
                    {
                        await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                        return;
                    }

                    startDate = DateTime.Now.AddMinutes(-1 * interval);
                }

                IEnumerable <PriceEntity> prices;

                if (values[1] == "all")
                {
                    prices = _priceRepository.FindPrices(startDate).OrderBy(x => x.Date);
                }
                else
                {
                    var symbol = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Name == values[1].ToUpperInvariant() || x.FriendlyName == values[1].ToUpperInvariant());

                    if (symbol == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Symbol is not found!");

                        return;
                    }

                    prices = _priceRepository.FindPrices(symbol.Id, startDate).OrderBy(x => x.Date);
                }

                List <string> lines = new List <string>();

                foreach (var item in prices)
                {
                    var sym = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Id == item.SymbolId);

                    lines.Add($"{item.Date.AddHours(3).ToString("dd.MM.yyyy HH:mm:ss")} | {sym.FriendlyName}: {item.Price} {string.Format("[{0}%{1}]", (item.Change * 100).ToString("+0.00;-0.00;0"), GetTimeSpanString(DateTime.Now - item.LastChangeDate))}");
                }

                if (!lines.Any())
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "There are no prices!");

                    return;
                }

                lines = lines.OrderBy(x => x).ToList();

                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), string.Join("\r\n", lines));

                return;
            }
            else
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                return;
            }
        }
Exemplo n.º 11
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string message = input.Message.Text.Trim();

            message = message.Replace((message + " ").Split(' ')[0], string.Empty).Trim();

            List <string> values = message.Contains(" ") ? message.Split(' ').ToList() : new List <string>()
            {
                message
            };

            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            if (user == null)
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Unauthorized!");

                return;
            }

            // "/settings get <all|key>"
            if (values[0] == "get")
            {
                if (values.Count == 1)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                if (values[1] == "all")
                {
                    var settings = _settingRepository.FindSettings(user.Id);

                    List <string> lines = new List <string>();

                    foreach (var item in settings)
                    {
                        lines.Add($"{item.Key} = {item.Value}");
                    }

                    if (!lines.Any())
                    {
                        await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "There are no settings!");

                        return;
                    }

                    lines = lines.OrderBy(x => x).ToList();

                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), string.Join("\r\n", lines));

                    return;
                }
                else
                {
                    var setting = _settingRepository.FindSetting(user.Id, values[1]);

                    if (setting == null)
                    {
                        await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Setting is not found!");

                        return;
                    }

                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), $"{setting.Key} = {setting.Value}");

                    return;
                }
            }
            // "/settings set <key> <value>"
            else if (values[0] == "set")
            {
                if (values.Count < 3)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                var setting = _settingRepository.FindSetting(user.Id, values[1]);

                if (setting == null)
                {
                    _settingRepository.InsertSetting(new SettingEntity()
                    {
                        UserId = user.Id,
                        Key    = values[1],
                        Value  = values[2]
                    });
                }
                else
                {
                    setting.Value = values[2];

                    _settingRepository.UpdateSetting(setting);
                }

                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Success!");
            }
            // "/settings del <key>"
            else if (values[0] == "del")
            {
                if (values.Count == 1)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                var setting = _settingRepository.FindSetting(user.Id, values[1]);

                if (setting == null)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Setting is not found!");

                    return;
                }

                _settingRepository.RemoveSetting(setting.Id);

                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Success!");
            }
            else
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                return;
            }
        }
Exemplo n.º 12
0
        public async Task ExecuteAsync(BotUpdateInput input)
        {
            string message = input.Message.Text.Trim();

            message = message.Replace((message + " ").Split(' ')[0], string.Empty).Trim();

            List <string> values = message.Contains(" ") ? message.Split(' ').ToList() : new List <string>()
            {
                message
            };

            UserEntity user = _userRepository.FindUser(input.Message.Chat.Id.ToString());

            if (user == null)
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Unauthorized!");

                return;
            }

            // "/alerts get <all|symbol>"
            if (values[0] == "get")
            {
                if (values.Count == 1)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                if (values[1] == "all")
                {
                    var alerts = _alertRepository.FindAlerts(user.Id);

                    List <string> lines = new List <string>();

                    foreach (var item in alerts)
                    {
                        var sym = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Id == item.SymbolId);

                        string line = $"{sym.FriendlyName} when";

                        if (item.LessValue.HasValue)
                        {
                            line += $" less than {item.LessValue.Value}";
                        }

                        if (item.GreaterValue.HasValue)
                        {
                            line += $" greater than {item.GreaterValue.Value}";
                        }

                        lines.Add(line);
                    }

                    if (!lines.Any())
                    {
                        await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "There are no alerts!");

                        return;
                    }

                    lines = lines.OrderBy(x => x).ToList();

                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), string.Join("\r\n", lines));

                    return;
                }
                else
                {
                    var symbol = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Name == values[1].ToUpperInvariant() || x.FriendlyName == values[1].ToUpperInvariant());

                    if (symbol == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Symbol is not found!");

                        return;
                    }

                    var alert = _alertRepository.FindAlert(user.Id, symbol.Id);

                    if (alert == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Alert is not found!");

                        return;
                    }

                    string result = $"{symbol.FriendlyName} when";

                    if (alert.LessValue.HasValue)
                    {
                        result += $" less than {alert.LessValue.Value}";
                    }

                    if (alert.GreaterValue.HasValue)
                    {
                        result += $" greater than {alert.GreaterValue.Value}";
                    }

                    await _messageService.SendMessageAsync(user.ChatId, result);
                }
            }
            // "/alerts set <symbol> <less|greater> <value>"
            else if (values[0] == "set")
            {
                if (values.Count < 4)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                var symbol = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Name == values[1].ToUpperInvariant() || x.FriendlyName == values[1].ToUpperInvariant());

                if (symbol == null)
                {
                    await _messageService.SendMessageAsync(user.ChatId, "Symbol is not found!");

                    return;
                }

                var alert = _alertRepository.FindAlert(user.Id, symbol.Id);

                if (values[2] == "less")
                {
                    decimal lessValue = Convert.ToDecimal(values[3]);

                    if (alert == null)
                    {
                        _alertRepository.InsertAlert(new AlertEntity()
                        {
                            UserId    = user.Id,
                            SymbolId  = symbol.Id,
                            LessValue = lessValue
                        });
                    }
                    else
                    {
                        alert.LessValue = lessValue;

                        _alertRepository.UpdateAlert(alert);
                    }

                    _socketServiceManager.UpdateAlert(user.Id);

                    await _messageService.SendMessageAsync(user.ChatId, "Success!");
                }
                else if (values[2] == "greater")
                {
                    decimal greaterValue = Convert.ToDecimal(values[3]);

                    if (alert == null)
                    {
                        _alertRepository.InsertAlert(new AlertEntity()
                        {
                            UserId       = user.Id,
                            SymbolId     = symbol.Id,
                            GreaterValue = greaterValue
                        });
                    }
                    else
                    {
                        alert.GreaterValue = greaterValue;

                        _alertRepository.UpdateAlert(alert);
                    }

                    _socketServiceManager.UpdateAlert(user.Id);

                    await _messageService.SendMessageAsync(user.ChatId, "Success!");
                }
                else
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }
            }
            // "/alerts del <all|symbol>"
            else if (values[0] == "del")
            {
                if (values.Count == 1)
                {
                    await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                    return;
                }

                if (values[1] == "all")
                {
                    var alerts = _alertRepository.FindAlerts(user.Id);

                    foreach (var alert in alerts)
                    {
                        _alertRepository.RemoveAlert(alert.Id);
                    }

                    _socketServiceManager.UpdateAlert(user.Id);

                    await _messageService.SendMessageAsync(user.ChatId, "Success!");
                }
                else
                {
                    var symbol = _symbolRepository.FindSymbols().FirstOrDefault(x => x.Name == values[1].ToUpperInvariant() || x.FriendlyName == values[1].ToUpperInvariant());

                    if (symbol == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Symbol is not found!");

                        return;
                    }

                    var alert = _alertRepository.FindAlert(user.Id, symbol.Id);

                    if (alert == null)
                    {
                        await _messageService.SendMessageAsync(user.ChatId, "Alert is not found!");
                    }
                    else
                    {
                        _alertRepository.RemoveAlert(alert.Id);

                        _socketServiceManager.UpdateAlert(user.Id);

                        await _messageService.SendMessageAsync(user.ChatId, "Success!");
                    }
                }
            }
            else
            {
                await _messageService.SendMessageAsync(input.Message.Chat.Id.ToString(), "Invalid arguments!");

                return;
            }
        }