Skip to content

Commit 99d2aea

Browse files
authored
Merge pull request #1 from monkrobot/inline-bot
Inline bot
2 parents 28b4d91 + f7ac960 commit 99d2aea

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

bot/content.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@
3636
"Unless it is started by a link to Habrahabr.",
3737
],
3838
],
39-
[[], ["Politeness counts."]], # from this import politeness
39+
[["politeness"], ["Politeness counts."]], # from this import politeness
4040
[
41-
[], # from this import bad_mood
41+
["mood"], # from this import bad_mood
4242
["Bad mood is not a good reason to break the rules."],
4343
],
4444
[["ask"], ["Don't ask to ask just ask."]], # from this import ask
4545
[
46-
[], # from this import voice
46+
["voice"], # from this import voice
4747
[
4848
"Text message is better than voice message.",
4949
"Unless it is voice conference.",
5050
],
5151
],
52-
[[], ["Git repos are one honking great idea — let's do more of those!"]],
52+
[["git"], ["Git repos are one honking great idea — let's do more of those!"]],
5353
]
5454

5555
help_test = """

bot/main.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from datetime import timedelta, datetime
44
from urllib.parse import quote
5+
from uuid import uuid4
56

67
from aiotg import Chat, aiohttp
78

@@ -209,6 +210,34 @@ async def chats(chat: Chat, matched):
209210
)
210211

211212

213+
functions = ['/version', 'import __hello__',
214+
'import this', 'zen', '/about',
215+
'from this import hi', 'from this import gist',
216+
'from this import long_better', 'from this import correct',
217+
'from this import offtopic', 'from this import politeness',
218+
'from this import ask', 'from this import mood',
219+
'from this import voice', 'from this import git']
220+
221+
222+
@bot.inline
223+
async def inline_query(query):
224+
"""Find autocomplite for inline query"""
225+
226+
results = []
227+
228+
for func in functions:
229+
if query.query in func:
230+
results.append({
231+
"type": "article",
232+
"title": func,
233+
"id": "{}".format(uuid4()),
234+
"input_message_content": {"message_text": func},
235+
}
236+
)
237+
return query.answer(results)
238+
239+
212240
if __name__ == "__main__":
213241
logger.info("Running...")
214242
bot.run(debug=DEBUG)
243+

0 commit comments

Comments
 (0)