как получить количество приглашенных, в колонке new_chat_members, но добавляя контакт, в группу телеграм, колонка пуста.
#База Данных
conn = sqlite3.connect("mibot_t1.db")
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS USERS
(id INTEGER PRIMARY KEY NOT NULL, user_id INTEGER, username TEXT, name TEXT, new_chat_members TEXT, chat_id INTEGER)''')
conn.commit()
#conn.close()
class SQLither:
def __init__(self, database) -> object:
self.conn = sqlite3.connect(database)
self.c = self.conn.cursor()
def exists_user_chat(self, user_id, chat_id, new_chat_members):
"""Проверка существования пользователя в БД и в группе"""
return bool(self.c.execute("SELECT * FROM users WHERE user_id=?", (user_id,)).fetchone())
def add_to_db(self, user_id, username, name, new_chat_members, chat_id):
"""Добавление пользователя в БД"""
self.c.execute("INSERT INTO users(user_id, username, name, chat_id) VALUES(?,?,?,?)", (user_id, username, name, chat_id))
self.conn.commit()
db = SQLither("mibot_t1.db")
@dp.callback_query_handler(text="check")
async def check(call: types.CallbackQuery):
user_id = str(call.from_user.id)
to_id = call.data.split(':')[1]
username = call.from_user.username
last_name = call.from_user.last_name
name = call.from_user.full_name
chat_id = call.message.chat.id
new_chat_members = call.message.new_chat_members
#chat_member: ChatMemberUpdated = fields.Field(base=ChatMemberUpdated)
if db.exists_user_chat(user_id, chat_id, new_chat_members):
db.add_to_db(call.from_user.id, username, name, new_chat_members, call.message.chat.id)
ChatMember = await bot.get_chat_member(chat_id=call.message.chat.id, user_id=call.from_user.id)
ChatMemberUpdated.new_chat_members = await bot.get_chat_member(chat_id=call.message.chat.id, user_id=call.from_user.id)
ChatMemberUpdated = await bot.get_chat_member(chat_id=call.message.chat.id, user_id=call.from_user.id)
#if ChatMemberUpdated in new_chat_members:
if ChatMember in new_chat_members:
await call.message.delete()
await bot.restrict_chat_member(call.message.chat.id, call.from_user.id, ChatPermissions(can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, can_send_polls=True, can_pin_messages=True, can_invite_users=True, can_change_info=True))
else:
await call.answer(text="Не пригласили контакты.", show_alert=True)
filters.py
from aiogram import types
from aiogram.dispatcher.filters import BoundFilter
from aiogram.types import base
from aiogram.types import fields
from aiogram.types.chat import Chat
from aiogram.types.chat_invite_link import ChatInviteLink
from aiogram.types.chat_member import ChatMember
from aiogram.types.user import User
import datetime
class IsAdminFilter(BoundFilter):
key = "is_admin"
def __init__(self, is_admin):
self.is_admin = is_admin
async def check(self, message: types.Message):
member = await message.bot.get_chat_member(message.chat.id, message.from_user.id)
return member.is_chat_admin()
class ChatMemberUpdated(base.TelegramObject):
"""
This object represents changes in the status of a chat member.
https://core.telegram.org/bots/api#chatmemberupdated
"""
chat: Chat = fields.Field(base=Chat)
from_user: User = fields.Field(alias="from", base=User)
date: datetime.datetime = fields.DateTimeField()
old_chat_member: ChatMember = fields.Field(base=ChatMember)
new_chat_member: ChatMember = fields.Field(base=ChatMember)
invite_link: ChatInviteLink = fields.Field(base=ChatInviteLink)
В документации написано ChatMemberUpdated, new_chat_member ChatMember Новая информация об участнике чата.