def barrel(message): cid = message.chat.id uid = message.from_user.id uname = message.from_user.username db_worker = SQLighter(config.users_db) user_photo = bot.get_user_profile_photos(uid,0,1) # getting user profile photo fid = user_photo.photos[0][0].file_id # getting user profile photo id if db_worker.check_user(uid): # if user exists if db_worker.check_barrel(uid): # if barrel_roll-gif already exists and uploaded bar_id = db_worker.get_barrel(uid) # getting file id bot.send_document(cid,bar_id) # sending barrel_roll-gif else: file_path = bot.get_file(fid).file_path # getting file_path of users profile image utils.make_barrel_roll(file_path) # making gif-animation barrel_roll = open('barrel_roll.gif', 'rb') msg = bot.send_document(cid,barrel_roll) # sending gif-animation to chat barrel_roll_id = msg.document.file_id # saving gif-animation file id db_worker.add_barrel(uid,barrel_roll_id) # saving file-id in database else: db_worker.add_user(uid,uname,fid) file_path = bot.get_file(fid).file_path utils.make_barrel_roll(file_path) barrel_roll = open('barrel_roll.gif', 'rb') msg = bot.send_document(cid, barrel_roll) barrel_roll_id = msg.document.file_id db_worker.add_barrel(uid, barrel_roll_id)