add messages to db

This commit is contained in:
doesnm 2024-05-18 17:36:50 +03:00
parent 3d69805765
commit 02c26474e4

11
main.py
View file

@ -40,7 +40,6 @@ class Database:
sql = self.connect_db()
sql["cursor"].execute("select * from users where id_telegram = ?", (user_id,))
info_users = sql["cursor"].fetchone()
print(info_users)
self.close(sql['connect'],sql['cursor'])
if info_users is None:
return {"status":False}
@ -56,10 +55,10 @@ class Database:
def create_message(self,message: telebot.types.Message):
sql = self.connect_db()
date = datetime.datetime.now().strftime("%Y-%m-%d")
# TODO: specify params to query( you can get from check_user)
sql["cursor"].execute("""
insert into messages (id_user, message_id, message_text, date_send) values (?,?,?,?)
""", ())
""", (message.from_user.id,message.message_id,message.text,date))
sql["connect"].commit()
self.close(sql['connect'],sql['cursor'])
def close(self,connect,cursor):
cursor.close()
@ -87,12 +86,14 @@ class TelegramBot(Database):
)
@self.bot.message_handler(func=lambda message: True)
def echo_all(message):
check = self.check_user(message.from_user.id)
if not check["status"]: return
self.create_message(message)
self.bot.reply_to(message,"Сообщение отправлено админу")
self.bot.polling()
TelegramBot(
db_name="tg.db",
token="7037219892:AAGoZ1bKjN79KMiEGqYCWtPOEOk8s_N0RI4"
token="7037219892:AAFbu4QNhX6ffS0X1XoFiNTkpTa80yousC4"
)