Rewrite in Telethon #1

Merged
Lonami merged 3 commits from Lonami/xkcdtextbot:master into master 2019-05-11 18:26:41 +00:00
1 changed files with 8 additions and 2 deletions
Showing only changes of commit f474f3cd59 - Show all commits

10
bot.py
View File

@ -1,5 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import asyncio
from os import environ from os import environ
from collections import namedtuple from collections import namedtuple
from json import loads from json import loads
@ -79,11 +80,16 @@ async def inlinequery(event):
"""Handle the inline query.""" """Handle the inline query."""
# TODO show transcript in result but not message? # TODO show transcript in result but not message?
builder = event.builder builder = event.builder
await event.answer([builder.article( result = await asyncio.gather(*(builder.article(
title=xkcd.title, title=xkcd.title,
url=xkcd.link, url=xkcd.link,
text=MSG_FMT_STR.format(number=xkcd.number, link=xkcd.link, title=xkcd.title, alt=xkcd.alt) text=MSG_FMT_STR.format(number=xkcd.number, link=xkcd.link, title=xkcd.title, alt=xkcd.alt)
) for xkcd in get_xkcds(event.text)]) ) for xkcd in get_xkcds(event.text)))
# FIXME get_xkcds returns duplicates, which lead to the same result ID
# Build a dict by their ID to remove the duplicates
result = list({r.id: r for r in result}.values())
await event.answer(result)
def main(): def main():