files = {}
def load_files():
global files
res = db.execute("SELECT file_name,file_id FROM files")
files = {}
for row in res:
file_name, file_id = row
files[file_name] = file_id
def save_file(file_name, file_id):
global files
db.execute("INSERT INTO files (file_name,file_id) VALUES (?,?) ON CONFLICT(file_name) DO UPDATE SET file_id=excluded.file_id", (file_name, file_id))
files[file_name] = file_id
load_files()
...
if item["photo"] in files:
file_id = files[item["photo"]]
print (f" send photo file_name={item['photo']} file_id={file_id}")
bot.send_photo(call.message.chat.id, file_id)
else:
with open(os.path.join("menu", item["photo"]), "rb") as f:
bot.send_chat_action(call.message.chat.id, "upload_photo")
r = bot.send_photo(call.message.chat.id, f)
file_id = r.photo[0].file_id
save_file(item["photo"], file_id)
print (f" uploaded photo file_name={item['photo']} file_id={file_id}")
photo_data = await db.get_file_info(f'{files_dir}file_name.png')
if photo_data is None:
media = types.InputFile(f'{files_dir}file_name.png')
msg = await dp.bot.send_photo(chat_id=message.chat.id, photo=media)
full_size_photo_id = msg['photo'][-1]['file_id']
await db.add_file_info(full_size_photo_id)
else:
await dp.bot.send_photo(chat_id=message.chat.id, photo=photo_data)
if photo_data is None:
if len(photo_data) == 0:
register_*_handler
, в то время как для инлайн кнопки вызвали обычную функцию, которая должна являться декоратором. register_callback_query_handler()