mirror of
https://github.com/Nick80835/microbot
synced 2025-09-03 16:05:49 +00:00
make source caption generation simpler
This commit is contained in:
@@ -50,7 +50,11 @@ async def booru(event):
|
|||||||
|
|
||||||
for image in images:
|
for image in images:
|
||||||
try:
|
try:
|
||||||
await event.reply(f"[sauce]({image[1]}) [original sauce]({image[2]})" if image[2] else f"[sauce]({image[1]})", file=image[0], force_document=bool(event.other_args[1]))
|
await event.reply(
|
||||||
|
gen_source_string(image[1], image[2]),
|
||||||
|
file=image[0],
|
||||||
|
force_document=bool(event.other_args[1])
|
||||||
|
)
|
||||||
return
|
return
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@@ -65,7 +69,7 @@ async def booru(event):
|
|||||||
@ldr.add_inline_photo("yan(s|x|q|)", default="yan", extra=yan_api)
|
@ldr.add_inline_photo("yan(s|x|q|)", default="yan", extra=yan_api)
|
||||||
async def booru_inline(event):
|
async def booru_inline(event):
|
||||||
posts = await event.extra.get_random_posts(event.args, 3, event.other_args[0])
|
posts = await event.extra.get_random_posts(event.args, 3, event.other_args[0])
|
||||||
return [[post.file_url, f"[sauce]({post.sauce}) [original sauce]({post.source})" if post.source else f"[sauce]({post.sauce})"] for post in posts if post.file_url] if posts else None
|
return [[post.file_url, gen_source_string(post.sauce, post.source)] for post in posts if post.file_url] if posts else None
|
||||||
|
|
||||||
|
|
||||||
@ldr.add_dict(button_commands, pattern_extra="(s)", help=help_str, userlocking=True)
|
@ldr.add_dict(button_commands, pattern_extra="(s)", help=help_str, userlocking=True)
|
||||||
@@ -86,7 +90,7 @@ async def booru_buttons(event):
|
|||||||
event.extra[1][f"{event.chat.id}_{event.id}"] = [0, images]
|
event.extra[1][f"{event.chat.id}_{event.id}"] = [0, images]
|
||||||
|
|
||||||
await event.reply(
|
await event.reply(
|
||||||
f"[sauce]({images[0][1]}) [original sauce]({images[0][2]})" if images[0][2] else f"[sauce]({images[0][1]})",
|
gen_source_string(images[0][1], images[0][2]),
|
||||||
file=images[0][0],
|
file=images[0][0],
|
||||||
buttons=[Button.inline('➡️', f'{event.extra[2]}*{event.chat.id}_{event.id}*r')]
|
buttons=[Button.inline('➡️', f'{event.extra[2]}*{event.chat.id}_{event.id}*r')]
|
||||||
)
|
)
|
||||||
@@ -133,9 +137,16 @@ async def booru_buttons_callback(event):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await event.edit(
|
await event.edit(
|
||||||
f"[sauce]({this_image[1]}) [original sauce]({this_image[2]})" if this_image[2] else f"[sauce]({this_image[1]})",
|
gen_source_string(this_image[1], this_image[2]),
|
||||||
file=this_image[0],
|
file=this_image[0],
|
||||||
buttons=buttons
|
buttons=buttons
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def gen_source_string(source: str, orig_source: str) -> str:
|
||||||
|
if orig_source and orig_source.startswith("http"):
|
||||||
|
return f"[source]({source}) - [original source]({orig_source})"
|
||||||
|
else:
|
||||||
|
return f"[source]({source})"
|
||||||
|
Reference in New Issue
Block a user