|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
| 3 | +import string |
3 | 4 | import logging |
4 | 5 | from aiohttp import web |
5 | 6 | from aiotg import Bot, Chat, InlineQuery |
@@ -51,26 +52,27 @@ def empty_suggest(chat: Chat, _) -> None: |
51 | 52 |
|
52 | 53 |
|
53 | 54 | @bot.inline |
54 | | -def shrug_shoulders(request: InlineQuery) -> None: |
55 | | - str_from_bin = bin_to_str(request.query) |
56 | | - str_from_hex = hex_to_str(request.query) |
57 | | - |
| 55 | +def inline_request_handler(request: InlineQuery) -> None: |
58 | 56 | results = InlineQueryResultsBuilder() |
59 | 57 | add_article = get_articles_generator_for(results) |
60 | 58 |
|
61 | | - if str_from_bin: |
62 | | - add_article("Притвориться человеком", str_from_bin) |
63 | | - elif str_from_hex: |
64 | | - add_article("Просто текст", str_from_hex) |
65 | | - else: |
66 | | - lentach_logo = "{} ¯\_(ツ)_/¯".format(request.query).lstrip() |
67 | | - add_article("Пожать плечами", lentach_logo) |
68 | | - |
69 | | - if request.query: |
70 | | - binary = str_to_bin(request.query) |
71 | | - hex_str = str_to_hex(request.query) |
72 | | - add_article("Говорить, как робот", binary) |
73 | | - add_article("Типа программист", hex_str) |
| 59 | + if all(map(lambda char: char in (0, 1), request.query)): |
| 60 | + str_from_bin = bin_to_str(request.query) |
| 61 | + if str_from_bin: |
| 62 | + add_article("Притвориться человеком", str_from_bin) |
| 63 | + elif all(map(lambda char: char in string.hexdigits, request.query)): |
| 64 | + str_from_hex = hex_to_str(request.query) |
| 65 | + if str_from_hex: |
| 66 | + add_article("Просто текст", str_from_hex) |
| 67 | + elif all(map(lambda char: char in string.ascii_letters + string.digits + '+/=', request.query)): |
| 68 | + str_from_base64 = base64_to_str(request.query) |
| 69 | + if str_from_base64: |
| 70 | + add_article("Дешифровка", str_from_base64) |
| 71 | + elif request.query: |
| 72 | + add_article("Проблемы с раскладкой?", switch_keyboard_layout(request.query)) |
| 73 | + add_article("Говорить, как робот", str_to_bin(request.query)) |
| 74 | + add_article("Типа программист", str_to_hex(request.query)) |
| 75 | + add_article("Шифровка", str_to_base64(request.query)) |
74 | 76 |
|
75 | 77 | request.answer(results.build_list()) |
76 | 78 |
|
|
0 commit comments