mirror of
https://github.com/Nick80835/microbot
synced 2025-08-31 14:38:04 +00:00
add inline sauce links
This commit is contained in:
@@ -5,6 +5,8 @@ from re import escape, search
|
||||
|
||||
from telethon import events, types
|
||||
|
||||
from .fixes import inline_photos
|
||||
|
||||
|
||||
class CommandHandler():
|
||||
def __init__(self, client, logger, settings):
|
||||
@@ -85,16 +87,19 @@ class CommandHandler():
|
||||
event.pattern_match = pattern_match
|
||||
event.args = pattern_match.groups()[-1]
|
||||
|
||||
url_list = await value["function"](event)
|
||||
photo_list = await value["function"](event)
|
||||
|
||||
if not url_list:
|
||||
if not photo_list:
|
||||
return
|
||||
|
||||
photo_coros = []
|
||||
|
||||
for url in url_list:
|
||||
for photo in photo_list:
|
||||
try:
|
||||
photo_coros += [self.try_coro(builder.photo(url))]
|
||||
if isinstance(photo, list):
|
||||
photo_coros += [self.try_coro(inline_photos.photo(event.client, photo[0], text=photo[1]))]
|
||||
else:
|
||||
photo_coros += [self.try_coro(builder.photo(photo))]
|
||||
except:
|
||||
pass
|
||||
|
||||
|
37
ubot/fixes/inline_photos.py
Normal file
37
ubot/fixes/inline_photos.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import hashlib
|
||||
|
||||
from telethon import Button, utils
|
||||
from telethon.tl import functions, types
|
||||
|
||||
|
||||
async def photo(client, file, text='', parse_mode=None, buttons=None):
|
||||
try:
|
||||
fh = utils.get_input_photo(file)
|
||||
except TypeError:
|
||||
_, media, _ = await client._file_to_media(file, allow_cache=True, as_image=True)
|
||||
|
||||
if isinstance(media, types.InputPhoto):
|
||||
fh = media
|
||||
else:
|
||||
r = await client(functions.messages.UploadMediaRequest(types.InputPeerSelf(), media=media))
|
||||
fh = utils.get_input_photo(r.photo)
|
||||
|
||||
markup = None
|
||||
msg_entities = None
|
||||
|
||||
if buttons:
|
||||
markup = client.build_reply_markup(buttons, inline_only=True)
|
||||
|
||||
if text:
|
||||
text, msg_entities = await client._parse_message_text(text, parse_mode or client.parse_mode)
|
||||
|
||||
result = types.InputBotInlineResultPhoto(
|
||||
id='',
|
||||
type='photo',
|
||||
photo=fh,
|
||||
send_message=types.InputBotInlineMessageMediaAuto(text, entities=msg_entities, reply_markup=markup)
|
||||
)
|
||||
|
||||
result.id = hashlib.sha256(bytes(result)).hexdigest()
|
||||
|
||||
return result
|
@@ -99,7 +99,7 @@ async def danbooru_inline(event):
|
||||
|
||||
for post in response:
|
||||
if 'file_url' in post.keys():
|
||||
valid_urls.append(post['file_url'])
|
||||
valid_urls.append([post['file_url'], f"[sauce]({DAN_SAUCE_URL}{post['id']})"])
|
||||
|
||||
if not valid_urls:
|
||||
return None
|
||||
|
@@ -107,7 +107,7 @@ async def gelbooru_inline(event):
|
||||
|
||||
for post in response:
|
||||
if 'file_url' in post.keys():
|
||||
valid_urls.append(post['file_url'])
|
||||
valid_urls.append([post['file_url'], f"[sauce]({GEL_SAUCE_URL}{post['id']})"])
|
||||
|
||||
if not valid_urls:
|
||||
return None
|
||||
|
@@ -100,7 +100,7 @@ async def sankaku_inline(event):
|
||||
|
||||
for post in response:
|
||||
if 'file_url' in post.keys():
|
||||
valid_urls.append(post['file_url'])
|
||||
valid_urls.append([post['file_url'], f"[sauce]({SAN_SAUCE_URL}{post['id']})"])
|
||||
|
||||
if not valid_urls:
|
||||
return None
|
||||
|
Reference in New Issue
Block a user