There is a bot that can send voice both inline and just a list. When sending by number from the list, the number of uses is stored in the database, but through the inline mode could not find how to implement it. Please help
Code block inline mode:
@router_start.inline_query()
async def inline_on(query: types.InlineQuery):
with sq.connect('database.db') as con:
cur = con.cursor()
text = query.query
offset = int(query.offset) if query.offset else 0
num = cur.execute('''SELECT ID, Name, File_id
FROM voices
WHERE Description
LIKE ?
LIMIT 50
OFFSET ?''',
(f'%{text}%', offset)).fetchall()
await bot.send_chat_action(query.from_user.id, action="upload_voice")
results = []
for ID, Name, File_id in num:
results.append(types.InlineQueryResultCachedVoice(
id=str(ID),
title=Name,
voice_file_id=File_id))
await query.answer(results, cache_time=1, is_personal=True,
next_offset=str(offset + 50))
List mode code block:
@router_get.message(StateFilter("*"))
async def send_voice(message: types.Message):
await bot.send_chat_action(message.from_user.id, action="upload_voice")
if message.text is None:
return
else:
num = message.text.replace("/", "")
with sq.connect('database.db') as con:
cur = con.cursor()
voice_name = cur.execute(f"SELECT Name FROM voices WHERE ID = {num}").fetchone()[0]
voice_use_number = cur.execute(f"SELECT Num_of_uses FROM voices WHERE ID = {num}").fetchone()[0]
cur.execute(f"UPDATE voices SET Num_of_uses = ? WHERE ID = ?", (voice_use_number + 1, num))
con.commit()
voice_open = FSInputFile(f'audio\{voice_name}.ogg')
await bot.send_voice(message.chat.id, voice_open)
cur.close()
con.close()
Tried searching the documentation, but I’m not that good at it
I understand that when sending via inline mode, there should be a “query_result” parameter that displays the sent message, but I didn’t find such a parameter in the documentation.
Роберт Шакиров is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.