From 7165286718b7a54ab845198fc54a5b4b90e263a8 Mon Sep 17 00:00:00 2001 From: Alex Den Date: Fri, 10 Jul 2020 15:08:09 +0300 Subject: [PATCH 1/2] add inline bot --- bot/content.py | 8 ++++---- bot/main.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/bot/content.py b/bot/content.py index e48fb98..6abeb8c 100644 --- a/bot/content.py +++ b/bot/content.py @@ -36,20 +36,20 @@ "Unless it is started by a link to Habrahabr.", ], ], - [[], ["Politeness counts."]], # from this import politeness + [["politeness"], ["Politeness counts."]], # from this import politeness [ - [], # from this import bad_mood + ["mood"], # from this import bad_mood ["Bad mood is not a good reason to break the rules."], ], [["ask"], ["Don't ask to ask just ask."]], # from this import ask [ - [], # from this import voice + ["voice"], # from this import voice [ "Text message is better than voice message.", "Unless it is voice conference.", ], ], - [[], ["Git repos are one honking great idea — let's do more of those!"]], + [["git"], ["Git repos are one honking great idea — let's do more of those!"]], ] help_test = """ diff --git a/bot/main.py b/bot/main.py index 58b9fba..1b25d23 100644 --- a/bot/main.py +++ b/bot/main.py @@ -2,6 +2,7 @@ import logging from datetime import timedelta, datetime from urllib.parse import quote +from uuid import uuid4 from aiotg import Chat, aiohttp @@ -209,6 +210,35 @@ async def chats(chat: Chat, matched): ) +functions = ['/version', 'import __hello__', + 'import this', 'zen', '/about', + 'from this import hi', 'from this import gist', + 'from this import long_better', 'from this import correct', + 'from this import offtopic', 'from this import politeness', + 'from this import ask', 'from this import mood', + 'from this import voice', 'from this import git'] + + +@bot.inline +async def inline_query(query): + """Find autocomplite for inline query""" + + results = [] + + for func in functions: + if query.query in func: + results.append({ + "type": "article", + "title": func, + "id": "{}".format(uuid4()), + "input_message_content": {"message_text": func}, + } + ) + return query.answer(results) + + if __name__ == "__main__": logger.info("Running...") bot.run(debug=DEBUG) + bot.run() + \ No newline at end of file From f7ac9609bd76e131a2095f895c5abf3105301d9a Mon Sep 17 00:00:00 2001 From: Alex Den Date: Fri, 10 Jul 2020 15:17:36 +0300 Subject: [PATCH 2/2] return bot run --- bot/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot/main.py b/bot/main.py index 1b25d23..8b564b7 100644 --- a/bot/main.py +++ b/bot/main.py @@ -240,5 +240,4 @@ async def inline_query(query): if __name__ == "__main__": logger.info("Running...") bot.run(debug=DEBUG) - bot.run() \ No newline at end of file