Exemplo n.º 1
0
        public async Task <OkResult> GetUpdates([FromBody] Update updates)
        {
            if (updates.Type == UpdateType.Unknown)
            {
                return(Ok());
            }
            else if (updates.Type == UpdateType.Message)
            {
                if (updates.Message.Chat.Type == ChatType.Private)
                {
                    if (updates.Type == UpdateType.Message)
                    {
                    }
                }
                else if (updates.Message.Chat.Type == ChatType.Supergroup || updates.Message.Chat.Type == ChatType.Group)
                {
                    if (updates.Message.Text == "فعال شدن")
                    {
                        var creator = await _client.GetChatMemberAsync(updates.Message.Chat.Id, updates.Message.From.Id);

                        if (creator.Status == ChatMemberStatus.Creator)
                        {
                            if (_context.Groups.Any(c => c.Id == updates.Message.Chat.Id.ToString()))
                            {
                                await _client.SendTextMessageAsync(updates.Message.Chat.Id, ErrorAnswerModel.GroupAddedbefor);
                            }
                            else
                            {
                                try
                                {
                                    _context.Groups.Add(new Group
                                    {
                                        Id         = updates.Message.Chat.Id.ToString(),
                                        BotSetting = new botSetting {
                                            LockGap = false, LockSticker = false, LockVideo = false, LockVoice = false, SettingId = Guid.NewGuid().ToString()
                                        },
                                        GroupAdded  = true,
                                        GroupName   = updates.Message.Chat.FirstName + updates.Message.Chat.LastName,
                                        MemberCount = await _client.GetChatMembersCountAsync(updates.Message.Chat.Id),
                                    });

                                    _context.Admins.Add(new Admin
                                    {
                                        Id       = updates.Message.From.Id.ToString(),
                                        Name     = updates.Message.From.FirstName + updates.Message.From.LastName,
                                        UserName = updates.Message.From.Username ?? default
                                    });

                                    _context.AdminGroups.Add(new AdminGroup {
                                        AdminId = updates.Message.From.Id.ToString(), GroupId = updates.Message.Chat.Id.ToString()
                                    });

                                    _context.SaveChanges();

                                    await _client.SendTextMessageAsync(updates.Message.Chat.Id, TextAnswerModel.GapAdded(updates.Message.Chat.Id, updates.Message.From.Id));
                                }