Change add_vote and post for name
This commit is contained in:
parent
0176c385e9
commit
c464088c57
17
bot.py
17
bot.py
|
@ -18,10 +18,19 @@ def get_callback_id(db):
|
|||
return int(cursor.fetchone()[0]) + 1
|
||||
|
||||
|
||||
def add_vote(db, callback_id, user_id):
|
||||
def add_vote(db, callback_id, user=None):
|
||||
if user is not None:
|
||||
user_id = user.id
|
||||
name = str(user.first_name)
|
||||
if user.last_name:
|
||||
name += " " + str(user.last_name)
|
||||
else:
|
||||
user_id = 0
|
||||
name = ""
|
||||
|
||||
cursor = db.cursor()
|
||||
query = ("INSERT INTO poll(callback, user_id) values(?,?)")
|
||||
cursor.execute(query, (callback_id, user_id))
|
||||
query = ("INSERT INTO poll(callback, user_id, name) values(?,?,?)")
|
||||
cursor.execute(query, (callback_id, user_id, name))
|
||||
db.commit()
|
||||
|
||||
|
||||
|
@ -29,7 +38,7 @@ def post(bot, update, db):
|
|||
chat_id = update.message.chat_id
|
||||
if chat_id in config.allowed_users:
|
||||
callback_id = get_callback_id(db)
|
||||
add_vote(db, callback_id, 0)
|
||||
add_vote(db, callback_id)
|
||||
photo = update.message.photo[0]
|
||||
file_id = photo.file_id
|
||||
keyboard = InlineKeyboardMarkup([[InlineKeyboardButton(text="❤️",
|
||||
|
|
Loading…
Reference in New Issue