mirror of
https://github.com/Redume/Shirino.git
synced 2024-11-23 08:46:21 +03:00
Переделаны ответы, меньше говнокода
This commit is contained in:
parent
f13ff07de7
commit
bc9098cd14
1 changed files with 28 additions and 35 deletions
63
main.py
63
main.py
|
@ -13,6 +13,7 @@ import requests
|
|||
from aiogram import Dispatcher, types, Bot
|
||||
import aiohttp.client_exceptions
|
||||
from pydantic.v1 import BaseSettings
|
||||
from selenium.webdriver.common.actions import interaction
|
||||
|
||||
# Constants
|
||||
DDG_URL = 'https://duckduckgo.com/js/spice/currency'
|
||||
|
@ -172,25 +173,14 @@ def rotate_token(lst: List[str], active: List[int]) -> None:
|
|||
active[0] = (active[0] + 1) % len(lst)
|
||||
|
||||
|
||||
@dp.inline_query()
|
||||
async def currency(inline_query: types.InlineQuery) -> None:
|
||||
query = inline_query.query
|
||||
async def inline_reply(result_id: str, title: str, description: str or None, inline_query: types.InlineQuery) -> None:
|
||||
article: List[Optional[types.InlineQueryResultArticle]] = [None]
|
||||
|
||||
args = query.split()
|
||||
|
||||
result_id = hashlib.md5(query.encode()).hexdigest()
|
||||
conv = CurrencyConverter()
|
||||
|
||||
try:
|
||||
log.debug(len(args))
|
||||
if len(args) <= 1:
|
||||
article[0] = types.InlineQueryResultArticle(
|
||||
id=result_id,
|
||||
title="Требуется 2, либо 3 аргумента",
|
||||
description=f"@shirino_bot USD RUB \n@shirino_bot 12 USD RUB",
|
||||
title=title,
|
||||
description=description,
|
||||
input_message_content=types.InputTextMessageContent(
|
||||
message_text="Требуется 2, либо 3 аргумента"
|
||||
message_text=title
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -199,6 +189,23 @@ async def currency(inline_query: types.InlineQuery) -> None:
|
|||
cache_time=1,
|
||||
is_personal=True,
|
||||
)
|
||||
|
||||
|
||||
@dp.inline_query()
|
||||
async def currency(inline_query: types.InlineQuery) -> None:
|
||||
query = inline_query.query
|
||||
args = query.split()
|
||||
|
||||
result_id = hashlib.md5(query.encode()).hexdigest()
|
||||
conv = CurrencyConverter()
|
||||
|
||||
try:
|
||||
log.debug(len(args))
|
||||
if len(args) <= 1:
|
||||
await inline_reply(result_id,
|
||||
"Требуется 2, либо 3 аргумента",
|
||||
f"@shirino_bot USD RUB \n@shirino_bot 12 USD RUB", inline_query)
|
||||
|
||||
if len(args) == 3:
|
||||
conv.amount = float(args[0])
|
||||
conv.from_currency = args[1].upper()
|
||||
|
@ -215,13 +222,11 @@ async def currency(inline_query: types.InlineQuery) -> None:
|
|||
)
|
||||
|
||||
except aiohttp.client_exceptions.ClientError as ex:
|
||||
article[0] = types.InlineQueryResultArticle(
|
||||
id=result_id,
|
||||
title="Rate-limit от API Telegram, повторите запрос позже.",
|
||||
input_message_content=types.InputTextMessageContent(
|
||||
message_text="Rate-limit от API Telegram, повторите запрос позже.",
|
||||
)
|
||||
)
|
||||
await inline_reply(result,
|
||||
"Rate-limit от API Telegram, повторите запрос позже",
|
||||
None,
|
||||
inline_query)
|
||||
|
||||
log.debug(ex)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
@ -229,19 +234,7 @@ async def currency(inline_query: types.InlineQuery) -> None:
|
|||
log.debug(ex)
|
||||
result = f'{type(ex).__name__}: {ex}'
|
||||
|
||||
article[0] = types.InlineQueryResultArticle(
|
||||
id=result_id,
|
||||
title=result,
|
||||
input_message_content=types.InputTextMessageContent(
|
||||
message_text=result,
|
||||
),
|
||||
)
|
||||
|
||||
await inline_query.answer(
|
||||
article, # type: ignore
|
||||
cache_time=1,
|
||||
is_personal=True,
|
||||
)
|
||||
await inline_reply(result, result, None, inline_query)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
|
Loading…
Add table
Reference in a new issue