2
0
mirror of https://github.com/Nick80835/microbot synced 2025-09-01 15:05:48 +00:00

implement kinda quirky inline stuff

This commit is contained in:
Nick80835
2020-05-16 17:52:29 -04:00
parent 024624e48f
commit 6a819878ea
5 changed files with 127 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-or-later
import asyncio
from re import escape, search
from telethon import events
@@ -10,9 +11,11 @@ class CommandHandler():
self.username = client.loop.run_until_complete(client.get_me()).username
self.pattern_template = "(?is)^{0}{1}(?: |$|_|@{2}(?: |$|_))(.*)"
self.incoming_commands = {}
self.inline_photo_commands = {}
self.logger = logger
self.settings = settings
client.add_event_handler(self.handle_incoming, events.NewMessage(incoming=True))
client.add_event_handler(self.handle_inline_photo, events.InlineQuery())
async def handle_incoming(self, event):
if event.via_bot_id:
@@ -38,3 +41,33 @@ class CommandHandler():
self.logger.warn(f"{value['function'].__name__} - {exception}")
await event.reply(f"`An error occurred in {value['function'].__name__}: {exception}`")
raise exception
async def handle_inline_photo(self, event):
print(str(event))
builder = event.builder
result_list = []
fetch_coros = []
async def exec_coro(coro):
this_url = await coro
if this_url:
try:
return await builder.photo(this_url)
except:
return
else:
return
for _, value in self.inline_photo_commands.items():
fetch_coros += [exec_coro(value["function"](event.text))]
for result in await asyncio.gather(*fetch_coros):
if result:
result_list += [result]
try:
await event.answer(result_list)
except:
pass