Change add_vote and post for name

This commit is contained in:
Ceda EI 2019-01-06 23:32:29 +05:30
parent 0176c385e9
commit c464088c57
1 changed files with 13 additions and 4 deletions

17
bot.py
View File

@ -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="❤️",