Теперь поддерживается плавающая запятая, а не только точка. Фикс (вроде) UnboundLocalError

This commit is contained in:
Данил 2024-08-25 20:01:25 +03:00
parent 46a1ecdbf8
commit 5bc5f37723

View file

@ -73,6 +73,7 @@ async def inline_reply(result_id: str, title: str, description: str or None, inl
@dp.inline_query() @dp.inline_query()
async def currency(inline_query: types.InlineQuery) -> None: async def currency(inline_query: types.InlineQuery) -> None:
global result
query = inline_query.query query = inline_query.query
args = query.split() args = query.split()
@ -86,7 +87,7 @@ async def currency(inline_query: types.InlineQuery) -> None:
f"@shirino_bot USD RUB \n@shirino_bot 12 USD RUB", inline_query) f"@shirino_bot USD RUB \n@shirino_bot 12 USD RUB", inline_query)
if len(args) == 3: if len(args) == 3:
conv.amount = float(args[0]) conv.amount = float(args[0].replace(',', '.'))
conv.from_currency = args[1].upper() conv.from_currency = args[1].upper()
conv.conv_currency = args[2].upper() conv.conv_currency = args[2].upper()
conv.convert() conv.convert()
@ -108,13 +109,10 @@ async def currency(inline_query: types.InlineQuery) -> None:
await asyncio.sleep(1) await asyncio.sleep(1)
except Exception as e: except Exception:
print(e)
await inline_reply(result_id, "Invalid data format", await inline_reply(result_id, "Invalid data format",
"@shirino_bot USD RUB \n@shirino_bot 12 USD RUB", "@shirino_bot USD RUB \n@shirino_bot 12 USD RUB",
inline_query) inline_query)
except UnboundLocalError:
pass
await inline_reply(result_id, result, None, inline_query) await inline_reply(result_id, result, None, inline_query)