private async Task Check(long userId, string Username, string Name, long chatId, int messageId, Bot.Core.Services.Bot.FSM <Bot.Core.Models.GateKeeperBot> fsm)
        {
            var res = await userChecker.Check(userId);

            var user = new GateKeeperBot()
            {
                Id       = userId,
                Name     = Name,
                Username = Username,
                userType = Bot.Core.Enums.UserType.User,
                Status   = Bot.Core.Enums.UserStatus.common
            };

            if (res.Status <= Common.Enums.UserStatus.SimpleBad)
            {
                //if (fsm.config.Mode == ChatState.Overrun)
                //{
                await TextMessage.defaultClient.KickChatMemberAsync(chatId, userId, revokeMessages : true);

                user.Status = Bot.Core.Enums.UserStatus.banned;
                await dataStorage.SaveChat(user, CancellationToken.None, TextMessage.defaultClient.BotId.Value);

                TextMessage textMessage = new TextMessage(null, chatId, "Автоматически забанен антипрививочник. UserId:" + userId + "; Соцрейтинг: " + Math.Round(res.Score, 3), null);
                messagesSender.AddItem(textMessage);
                //}
                //else
                //{
                //    string commandBan = string.Format("{0}_{1}_{2}", chatId, userId, Command.Ban.ToString());
                //    string commandTrust = string.Format("{0}_{1}_{2}", chatId, userId, Command.Trust.ToString());
                //    InlineKeyboardMarkup keyb = new InlineKeyboardMarkup(new List<List<InlineKeyboardButton>>()
                //    {
                //        new List<InlineKeyboardButton>()
                //        {
                //            new InlineKeyboardButton()
                //            {
                //                CallbackData=commandBan,
                //                Text= "Бан"
                //            }
                //        }
                //    });
                //    TextMessage textMessage = new TextMessage(null, chatId, Environment.GetEnvironmentVariable("PreBanMessage") ?? "Обнаружена антивакса! " + "Соцрейтинг: " + Math.Round(res.Score, 3).ToString() + " Выберете действие:", null, null, messageId, null, keyb);
                //    messagesSender.AddItem(textMessage);
                //}
            }
            else if (res.Status == Common.Enums.UserStatus.Middle)
            {
                string commandBan    = string.Format("{0}_{1}_{2}", chatId, userId, Command.Ban.ToString());
                string commandTrust  = string.Format("{0}_{1}_{2}", chatId, userId, Command.Trust.ToString());
                string commandWait   = string.Format("{0}_{1}_{2}", chatId, userId, Command.Wait.ToString());
                string commandSearch = res.FirstPageId != ObjectId.Empty ? res.FirstPageId.ToString() : string.Empty;
                var    keybBase      = new List <List <InlineKeyboardButton> >()
                {
                    new List <InlineKeyboardButton>()
                    {
                        new InlineKeyboardButton()
                        {
                            CallbackData = commandBan,
                            Text         = "Бан"
                        },
                        new InlineKeyboardButton()
                        {
                            CallbackData = commandTrust,
                            Text         = "Оправдать"
                        },
                    }
                };
                if (!string.IsNullOrEmpty(commandSearch))
                {
                    keybBase.Add(new List <InlineKeyboardButton>()
                    {
                        new InlineKeyboardButton()
                        {
                            Text = "Личное дело", CallbackData = commandSearch
                        }
                    });
                }
                InlineKeyboardMarkup keyb        = new InlineKeyboardMarkup(keybBase);
                TextMessage          textMessage = new TextMessage(null, chatId, Environment.GetEnvironmentVariable("PreBanMessage") ?? "Обнаружен потенциальный антипрививочник! \n\nДля просмотра личного дела нужно иметь права администратора и стартовать личный диалог со мной." + "Соц рейтинг: " + Math.Round(res.Score, 3).ToString() + "\n\n Выберите действие:", null, null, messageId, null, keyb);
                messagesSender.AddItem(textMessage);
            }
        }
Ejemplo n.º 2
0
        public override void Execute()
        {
            FtpMessage responce = new FtpMessage("230 успешная авторизация", ClientConnection.Encoding);

            ClientConnection.Password =
                _commandArgsResolver.ResolvePassword(FtpMessage.Args);

            if (String.IsNullOrEmpty(ClientConnection.UserLogin) ||
                String.IsNullOrEmpty(ClientConnection.Password) ||
                String.IsNullOrEmpty(ClientConnection.RemoteServerIdentifier))
            {
                //TODO ctor
                SendToClient(new FtpMessage("530 неверная последовательность команд", ClientConnection.Encoding));
                return;
            }

            IUserCheckerResult checkerResult = _userChecker.Check(ClientConnection.UserLogin,
                                                                  ClientConnection.Password,
                                                                  ClientConnection.RemoteServerIdentifier);

            if (checkerResult == null)
            {
                SendToClient(new FtpMessage("530 Неверная комбинация логин-пароль", ClientConnection.Encoding));
                return;
            }
            try
            {
                _serverConnectionBuilder.BuildRemoteConnection(checkerResult.UrlAddress, checkerResult.Port);
            }
            catch (AuthenticationException)
            {
                Logger.Log.Error(String.Format("remote server anavailable: {0}| USER: {1}", checkerResult.UrlAddress,
                                               ClientConnection.UserLogin));
                SendToClient(new FtpMessage("434 remote server anavailable", ClientConnection.Encoding));
                return;
            }

            try
            {
                _serverConnectionBuilder.BuildConnectionSecurity();
            }
            catch (AuthenticationException e)
            {
                Logger.Log.Error(String.Format("BuildConnectionSecurity: {0}, Host: {1}, User: {2}", e.Message,
                                               checkerResult.UrlAddress, ClientConnection.UserLogin));
            }

            try
            {
                _serverConnectionBuilder.BuildUser(checkerResult.Login);
                _serverConnectionBuilder.BuildPass(checkerResult.Pass);
            }
            catch (AuthenticationException e)
            {
                Logger.Log.Error(String.Format("BuildUserPass: {0}; Host: {1}, User: {2}", e.Message,
                                               checkerResult.UrlAddress, ClientConnection.UserLogin));
                SendToClient(new FtpMessage("425 incorrect remote server auth data. Please contact the administrator",
                                            ClientConnection.Encoding));
                return;
            }
            SendToClient(responce);
        }