add messages to db
This commit is contained in:
parent
3d69805765
commit
02c26474e4
1 changed files with 6 additions and 5 deletions
11
main.py
11
main.py
|
@ -40,7 +40,6 @@ class Database:
|
||||||
sql = self.connect_db()
|
sql = self.connect_db()
|
||||||
sql["cursor"].execute("select * from users where id_telegram = ?", (user_id,))
|
sql["cursor"].execute("select * from users where id_telegram = ?", (user_id,))
|
||||||
info_users = sql["cursor"].fetchone()
|
info_users = sql["cursor"].fetchone()
|
||||||
print(info_users)
|
|
||||||
self.close(sql['connect'],sql['cursor'])
|
self.close(sql['connect'],sql['cursor'])
|
||||||
if info_users is None:
|
if info_users is None:
|
||||||
return {"status":False}
|
return {"status":False}
|
||||||
|
@ -56,10 +55,10 @@ class Database:
|
||||||
def create_message(self,message: telebot.types.Message):
|
def create_message(self,message: telebot.types.Message):
|
||||||
sql = self.connect_db()
|
sql = self.connect_db()
|
||||||
date = datetime.datetime.now().strftime("%Y-%m-%d")
|
date = datetime.datetime.now().strftime("%Y-%m-%d")
|
||||||
# TODO: specify params to query( you can get from check_user)
|
|
||||||
sql["cursor"].execute("""
|
sql["cursor"].execute("""
|
||||||
insert into messages (id_user, message_id, message_text, date_send) values (?,?,?,?)
|
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'])
|
self.close(sql['connect'],sql['cursor'])
|
||||||
def close(self,connect,cursor):
|
def close(self,connect,cursor):
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
@ -87,12 +86,14 @@ class TelegramBot(Database):
|
||||||
)
|
)
|
||||||
@self.bot.message_handler(func=lambda message: True)
|
@self.bot.message_handler(func=lambda message: True)
|
||||||
def echo_all(message):
|
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.reply_to(message,"Сообщение отправлено админу")
|
||||||
|
|
||||||
self.bot.polling()
|
self.bot.polling()
|
||||||
|
|
||||||
TelegramBot(
|
TelegramBot(
|
||||||
db_name="tg.db",
|
db_name="tg.db",
|
||||||
token="7037219892:AAGoZ1bKjN79KMiEGqYCWtPOEOk8s_N0RI4"
|
token="7037219892:AAFbu4QNhX6ffS0X1XoFiNTkpTa80yousC4"
|
||||||
)
|
)
|
Loading…
Reference in a new issue