diff --git a/ubot/modules/booru.py b/ubot/modules/booru.py new file mode 100644 index 0000000..d169fbe --- /dev/null +++ b/ubot/modules/booru.py @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +from asyncbooru import Danbooru, Gelbooru, Konachan, Sankaku, Yandere +from ubot import ldr + +commands = { + ("dan", "danx", "danq", "dans"): Danbooru(ldr.aioclient), + ("gel", "gelx", "gelq", "gels"): Gelbooru(ldr.aioclient), + ("kon", "konx", "konq", "kons"): Konachan(ldr.aioclient), + ("san", "sanx", "sanq", "sans"): Sankaku(ldr.aioclient), + ("yan", "yanx", "yanq", "yans"): Yandere(ldr.aioclient) +} + + +@ldr.add_dict(commands, pattern_extra="(f|)", help="Fetches images from Danbooru, Gelbooru, Konachan, Sankaku Complex and Yandere, takes tags as arguments.") +async def booru(event): + await event.edit(f"`Processing…`") + safety_arg = event.command[-1] + as_file = bool(event.other_args[0]) + post = await event.extra.get_random_post(event.args, safety_arg) + + if not post or not post.file_url: + await event.edit(f"`No results for query: `**{event.args}**") + return + + try: + await event.client.send_message(event.chat_id, f"[sauce]({post.sauce})", file=post.file_url, force_document=as_file) + await event.delete() + except: + await event.edit(f"`Failed to fetch media for query: `**{event.args}**") diff --git a/ubot/modules/danbooru.py b/ubot/modules/danbooru.py deleted file mode 100644 index 3169fe8..0000000 --- a/ubot/modules/danbooru.py +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -from asyncbooru import Danbooru -from ubot import ldr - -danbooru_api = Danbooru(ldr.aioclient) - - -@ldr.add_list(["dan", "danx", "danq", "dans"], pattern_extra="(f|)", help="Fetches images from Danbooru, takes tags as arguments.") -async def danbooru(event): - await event.edit(f"`Processing…`") - safety_arg = event.command[-1] - as_file = bool(event.other_args[0]) - post = await danbooru_api.get_random_post(event.args, safety_arg) - - if not post or not post.file_url: - await event.edit(f"`No results for query: `**{event.args}**") - return - - try: - await event.client.send_message(event.chat_id, f"[sauce]({post.sauce})", file=post.file_url, force_document=as_file) - await event.delete() - except: - await event.edit(f"`Failed to fetch media for query: `**{event.args}**") diff --git a/ubot/modules/gelbooru.py b/ubot/modules/gelbooru.py deleted file mode 100644 index c49fa88..0000000 --- a/ubot/modules/gelbooru.py +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -from asyncbooru import Gelbooru -from ubot import ldr - -gelbooru_api = Gelbooru(ldr.aioclient) - - -@ldr.add_list(["gel", "gelx", "gelq", "gels"], pattern_extra="(f|)", help="Fetches images from Gelbooru, takes tags as arguments.") -async def gelbooru(event): - await event.edit(f"`Processing…`") - safety_arg = event.command[-1] - as_file = bool(event.other_args[0]) - post = await gelbooru_api.get_random_post(event.args, safety_arg) - - if not post or not post.file_url: - await event.edit(f"`No results for query: `**{event.args}**") - return - - try: - await event.client.send_message(event.chat_id, f"[sauce]({post.sauce})", file=post.file_url, force_document=as_file) - await event.delete() - except: - await event.edit(f"`Failed to fetch media for query: `**{event.args}**") diff --git a/ubot/modules/konachan.py b/ubot/modules/konachan.py deleted file mode 100644 index 43c18ed..0000000 --- a/ubot/modules/konachan.py +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -from asyncbooru import Konachan -from ubot import ldr - -konachan_api = Konachan(ldr.aioclient) - - -@ldr.add_list(["kon", "konx", "konq", "kons"], pattern_extra="(f|)", help="Fetches images from Konachan, takes tags as arguments.") -async def konachan(event): - await event.edit(f"`Processing…`") - safety_arg = event.command[-1] - as_file = bool(event.other_args[0]) - post = await konachan_api.get_random_post(event.args, safety_arg) - - if not post or not post.file_url: - await event.edit(f"`No results for query: `**{event.args}**") - return - - try: - await event.client.send_message(event.chat_id, f"[sauce]({post.sauce})", file=post.file_url, force_document=as_file) - await event.delete() - except: - await event.edit(f"`Failed to fetch media for query: `**{event.args}**") diff --git a/ubot/modules/sankaku.py b/ubot/modules/sankaku.py deleted file mode 100644 index abde621..0000000 --- a/ubot/modules/sankaku.py +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -from asyncbooru import Sankaku -from ubot import ldr - -sankaku_api = Sankaku(ldr.aioclient) - - -@ldr.add_list(["san", "sanx", "sanq", "sans"], pattern_extra="(f|)", help="Fetches images from Sankaku Complex, takes tags as arguments.") -async def sankaku(event): - await event.edit(f"`Processing…`") - safety_arg = event.command[-1] - as_file = bool(event.other_args[0]) - post = await sankaku_api.get_random_post(event.args, safety_arg) - - if not post or not post.file_url: - await event.edit(f"`No results for query: `**{event.args}**") - return - - try: - await event.client.send_message(event.chat_id, f"[sauce]({post.sauce})", file=post.file_url, force_document=as_file) - await event.delete() - except: - await event.edit(f"`Failed to fetch media for query: `**{event.args}**") diff --git a/ubot/modules/yandere.py b/ubot/modules/yandere.py deleted file mode 100644 index 6d60811..0000000 --- a/ubot/modules/yandere.py +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -from asyncbooru import Yandere -from ubot import ldr - -yandere_api = Yandere(ldr.aioclient) - - -@ldr.add_list(["yan", "yanx", "yanq", "yans"], pattern_extra="(f|)", help="Fetches images from Yande.re, takes tags as arguments.") -async def yandere(event): - await event.edit(f"`Processing…`") - safety_arg = event.command[-1] - as_file = bool(event.other_args[0]) - post = await yandere_api.get_random_post(event.args, safety_arg) - - if not post or not post.file_url: - await event.edit(f"`No results for query: `**{event.args}**") - return - - try: - await event.client.send_message(event.chat_id, f"[sauce]({post.sauce})", file=post.file_url, force_document=as_file) - await event.delete() - except: - await event.edit(f"`Failed to fetch media for query: `**{event.args}**")