#База Данных
conn = sqlite3.connect("zqmi_bot_t4_t2.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_member INTEGER, chat_id INTEGER)''')
conn.commit()
class SQLither:
def __init__(self, database) -> object:
self.conn = sqlite3.connect(database)
self.c = self.conn.cursor()
def exists_user_chat(self, user_id):
"""Проверка существования пользователя в БД и в группе"""
return bool(self.c.execute("SELECT * FROM users WHERE user_id=?", (user_id,)).fetchone())
def add_to_db(self, user_id, username, name, chat_id, new_chat_members):
"""Добавление пользователя в БД"""
self.c.execute("INSERT INTO users(user_id, username, name, chat_id, new_chat_member) VALUES(?,?,?,?,?)", (user_id, username, name, chat_id, new_chat_member))
self.conn.commit()
db = SQLither("zqmi_bot_t4_t2.db")
@dp.message_handler(content_types=["new_chat_member"])
async def new_member(message: types.ChatMemberUpdated):
#async def new_member(self, update: types.ChatMemberUpdated):
#async def handler_new_member(message: types.Message):
user_id = message.from_user.id
username = message.from_user.username
name = message.from_user.full_name
chat_id = message.chat.id
new_chat_member = message.new_chat_member.user.id
user_id = update.from_user.id
username = update.from_user.username
name = update.from_user.full_name
chat_id = update.chat.id
new_chat_member = update.new_chat_member.user.id
#member = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id)
#ChatMember = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id)
#ChatMemberUpdated = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id)
if db.exists_user_chat(user_id):
member = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id)
ChatMemberUpdated = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id)
ChatMember = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id)
ChatMemberUpdated = await bot.get_chat_member(chat_id=update.chat.id, user_id=update.from_user.id)
ChatMember = await bot.get_chat_member(chat_id=update.chat.id, user_id=update.from_user.id)
#if message.from_user.id in message.new_chat_members:
if ChatMember.status in ChatMemberUpdated.values:
db.add_to_db(user_id, username, name, new_chat_member, chat_id)
return
#База Данных
conn = sqlite3.connect("zqmi_bot_t2.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 INTEGER, 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):
"""Проверка существования пользователя в БД и в группе"""
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, new_chat_members, chat_id) VALUES(?,?,?,?,?)", (user_id, username, name, new_chat_members, chat_id))
self.conn.commit()
db = SQLither("zqmi_bot_t2.db")
@dp.message_handler(content_types=["new_chat_members"])
async def new_member(message: types.ChatMemberUpdated):
user_id = message.from_user.id
username = message.from_user.username
name = message.from_user.full_name
chat_id = message.chat.id
new_chat_members = message.new_chat_members
if not db.exists_user_chat(user_id):
if message.from_user.id in message.new_chat_members:
if new_chat_members.status == 'member':
db.add_to_db(message.from_user.id, username, name, new_chat_members, message.chat.id)
def add_to_db(self, user_id, username, name, new_chat_members, chat_id):
"""Добавление пользователя в БД"""
self.c.execute("INSERT INTO users(user_id, username, name, new_chat_members, chat_id) VALUES(?,?,?,?,?)", (user_id, username, name, new_chat_members, chat_id))
self.conn.commit()
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())
return bool(self.c.execute("SELECT * FROM users WHERE user_id=? and chat_id=? and new_chat_members=?", (user_id, chat_id, new_chat_members,)).fetchone())
self.c.execute("INSERT INTO users(user_id, username, name, new_chat_members, chat_id) VALUES(?,?,?,?,?)", (user_id, username, name, new_chat_members, chat_id))
sqlite3.InterfaceError: Error binding parameter 3 - probably unsupported type.
return bool(self.c.execute("SELECT * FROM users WHERE user_id=? and chat_id=? and new_chat_members=?", (user_id, chat_id, new_chat_members,)).fetchone())
sqlite3.InterfaceError: Error binding parameter 2 - probably unsupported type.
return bool(self.c.execute("SELECT * FROM users WHERE user_id=? and chat_id=? and new_chat_members=?", (user_id, chat_id, new_chat_members,)).fetchone())
member = await bot.get_chat_member(message.chat.id, message.from_user.id)
if member.user.username == 'GroupAnonymousBot':
#if member.user.first_name == 'Group':
return
@dp.message_handler(commands=['myCommand'])
async def my_command(message: types.Message):
if message.chat.type != "supergroup, private, channel":
return
user_status = await get_chat_member(channel_id, message.from_user.id)
#user_status = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id)
if isinstance(user_status, types.ChatMemberMember):
if user_status["status"] != 'member':
await bot.restrict_chat_member(message.chat.id, message.from_user.id, can_send_messages=True)
return
@dp.message_handler()
#async def check(message):
#async def on_joined(message: types.Message):
async def check_new_user(message: types.Message):
for user_status in message.text:
user_status = await bot.get_chat_member(chat_id=message.chat.id, user_id=message.from_user.id)
if message.chat.type != "supergroup, private, channel":
return
if isinstance(user_status, types.ChatMemberMember):
if user_status["status"] != 'left':
await bot.restrict_chat_member(message.chat.id, message.from_user.id, can_send_messages=False)
await bot.send_message(message.from_user.id, "Вы уже находитесь в канале!")
else:
if isinstance(user_status, types.ChatMemberMember):
if user_status["status"] != 'member':
await bot.unban_chat_member(chat_id=message.chat.id, user_id=message.from_user.id)
#await bot.restrict_chat_member(message.chat.id, message.from_user.id, can_send_messages=True)
print(user_status)
return
Вопрос: как прописать, это в коде?
Тоже самое, принцип текста, тот же, в описание вопроса.
Кнопки я знаю, как прописать, но нужно, чтобы эти кнопки с постом, увидел, только я, в чате бота.
И как прописать, все id? по идеи, мне нужно, перенаправить пост, сначала, обратно боту, прописать id админов и id канала.