diff --git a/bot.py b/bot.py index 87998e0..e9fb806 100644 --- a/bot.py +++ b/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="❤️",