private async Task ProcessUser(User user, Bot.Core.Services.Bot.FSM <Bot.Core.Models.GateKeeperBot> fsm, Update update)
        {
            var temp = await dataStorage.GetChat(user.Id, CancellationToken.None, TextMessage.defaultClient.BotId.Value);

            if (temp != null && temp.Status == Bot.Core.Enums.UserStatus.banned)
            {
                if (fsm.config.Mode == ChatState.Overrun)
                {
                    await TextMessage.defaultClient.KickChatMemberAsync(update.Message.Chat.Id, user.Id, revokeMessages : true);
                }
                else
                {
                    long   chatId             = update.Message.Chat.Id;
                    long   userId             = user.Id;
                    string commandBan         = string.Format("{0}_{1}_{2}", chatId, userId, Command.Ban.ToString());
                    InlineKeyboardMarkup keyb = new InlineKeyboardMarkup(new List <List <InlineKeyboardButton> >()
                    {
                        new List <InlineKeyboardButton>()
                        {
                            new InlineKeyboardButton()
                            {
                                CallbackData = commandBan,
                                Text         = "Ban"
                            }
                        }
                    });
                    TextMessage textMessage = new TextMessage(null, update.Message.Chat.Id, Environment.GetEnvironmentVariable("PreBanMessage") ?? "Обнаружен подтверждённый антипрививочник!", null, null, update.Message.MessageId, null, keyb);
                    messagesSender.AddItem(textMessage);
                }
            }
            else if (temp == null)
            {
                await Check(update.Message.From.Id, update.Message.From.Username, update.Message.From.FirstName, update.Message.Chat.Id, update.Message.MessageId, fsm);
            }
        }
 public async Task <bool> TryChangeStatus(Update update, Bot.Core.Services.Bot.FSM <Bot.Core.Models.GateKeeperBot> fsm)
 {
     if ((update.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Group || update.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Supergroup) && (await TextMessage.defaultClient.GetChatAdministratorsAsync(update.Message.Chat.Id)).ToList().FindIndex(item => item.User.Id == update.Message.From.Id) >= 0)
     {
         if (update.Message.Text.ToLower().StartsWith("/overrun"))
         {
             fsm.config.Mode = ChatState.Overrun;
         }
         else if (update.Message.Text.ToLower().StartsWith("/common"))
         {
             fsm.config.Mode = ChatState.Common;
         }
         return(false);
     }
     return(true);
 }
        public async Task ProcessUpdateAsyncWr(Update update, Bot.Core.Services.Bot.FSM <Bot.Core.Models.GateKeeperBot> fsm)
        {
            if (await TryChangeStatus(update, fsm))
            {
                Regex reg = new Regex(@"(\d+)");
                if (update.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private)
                {
                    Match match = reg.Match(update.Message.Text.ToLower());
                    if (match.Success && long.TryParse(match.Groups[1].Value, out long userId))
                    {
                        var res = await userChecker.Check(userId);

                        TextMessage textMessage = new TextMessage(null, update.Message.Chat.Id, Newtonsoft.Json.JsonConvert.SerializeObject(res), null, null, update.Message.MessageId, null, null);
                        messagesSender.AddItem(textMessage);
                    }
                }
                else
                {
                    await ProcessUpdateAsync(update, fsm);
                }
            }
        }
        public async Task ProcessUpdateAsync(Update update, Bot.Core.Services.Bot.FSM <Bot.Core.Models.GateKeeperBot> fsm)
        {
            if (update.Message.NewChatMembers != null)
            {
                foreach (User user in update.Message.NewChatMembers)
                {
                    await ProcessUser(user, fsm, update);
                }
            }
            else if (update.ChatMember != null && update.ChatMember.NewChatMember != null)
            {
                var user = update.ChatMember.NewChatMember.User;
                await ProcessUser(user, fsm, update);
            }
            else
            {
                var ch = await TextMessage.defaultClient.GetChatMemberAsync(update.Message.Chat.Id, update.Message.From.Id);

                if (ch.Status == Telegram.Bot.Types.Enums.ChatMemberStatus.Left)
                {
                    await ProcessUser(ch.User, fsm, update);
                }
            }
        }
        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);
            }
        }
 public async Task ProcessUpdate(Update update, Bot.Core.Services.Bot.FSM <Bot.Core.Models.GateKeeperBot> fsm)
 {
     asyncTaskExecutor.Add(ProcessUpdateAsyncWr(update, fsm));
 }
Exemplo n.º 7
0
 public async Task <bool> Check <TBot>(Update update, Bot.Core.Services.Bot.FSM <TBot> fsm) where TBot : IConfig, new()
 {
     return(update.Type == Telegram.Bot.Types.Enums.UpdateType.Message && (update.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Group || update.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Supergroup || update.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private) && update.Message.From.Id != 777000 && fsm.config.Status <= botSettings.BoundUserStatus);
 }
 public async Task ProcessUpdate(Update update, Bot.Core.Services.Bot.FSM <Bot.Core.Models.ObserverBot> fsm)
 {
     messagesSender.AddItem(new TextMessage(null, update.Message.Chat.Id, Environment.GetEnvironmentVariable("def_reply") ?? "Оповещаю о появляющихся в телеграме упоминаниях. \nЕсли ничего не приходит - просто подождите какое-то время (возможно - несколько часов), и тему обязательно упомянут, а я сообщу вам об этом. \n\nНе выключайте оповещения!", null, new ReplyKeyboardRemove()));
 }