Skip to content

Commit 3f1316e

Browse files
author
Danil Ivanov
committed
Make it prettier
1 parent 52faacf commit 3f1316e

2 files changed

Lines changed: 14 additions & 23 deletions

File tree

bot/content.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
- [Meetup.com](https://www.meetup.com/ru-RU/spbpython/)
8282
"""
8383

84+
8485
def make_zen_md(rules, wrap=False):
8586
rules = ["- {}".format(rule) for rule in rules]
8687

@@ -91,14 +92,11 @@ def make_zen_md(rules, wrap=False):
9192
return "\n".join([chat_rules_header, *rules])
9293

9394

94-
inline_commands = (
95-
"/version", "import __hello__", "import this", "zen", "/about", "from this import"
96-
)
97-
98-
9995
def make_queries_from_rules(rules):
10096
return [
10197
f"from this import {keys[0]}" for keys, _ in rules
10298
]
10399

104-
import_queries = make_queries_from_rules(rules)
100+
inline_commands = (
101+
"/version", "import __hello__", "import this", "zen", "/about", *make_queries_from_rules(rules)
102+
)

bot/main.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,16 @@ async def chats(chat: Chat, matched):
192192
async def inline_query(query):
193193
"""Autocomplite for inline query"""
194194

195-
commands = []
196-
197-
for command in content.inline_commands:
198-
if query.query in command:
199-
commands.append(command)
200-
201-
if "from " in query.query:
202-
for command in content.import_queries:
203-
if query.query in command:
204-
commands.append(command)
205-
206-
return query.answer([{
207-
"type": "article",
208-
"title": command,
209-
"id": f"{uuid4()}",
210-
"input_message_content": {"message_text": command},
211-
} for command in commands[:7]])
195+
return query.answer([
196+
{
197+
"type": "article",
198+
"title": command,
199+
"id": f"{uuid4()}",
200+
"input_message_content": {"message_text": command},
201+
}
202+
for command in content.inline_commands
203+
if query.query in command
204+
])
212205

213206

214207
if __name__ == "__main__":

0 commit comments

Comments
 (0)