diff --git a/ubot/loader.py b/ubot/loader.py index 11b5af1..caf21cd 100644 --- a/ubot/loader.py +++ b/ubot/loader.py @@ -63,14 +63,14 @@ class Loader(): def decorator(func): if args.get("hide_help", False): if func.__module__.split(".")[-1] in self.help_hidden_dict: - self.help_hidden_dict[func.__module__.split(".")[-1]] += [pattern] + self.help_hidden_dict[func.__module__.split(".")[-1]] += [[pattern, args.get('help', None)]] else: - self.help_hidden_dict[func.__module__.split(".")[-1]] = [pattern] + self.help_hidden_dict[func.__module__.split(".")[-1]] = [[pattern, args.get('help', None)]] else: if func.__module__.split(".")[-1] in self.help_dict: - self.help_dict[func.__module__.split(".")[-1]] += [pattern] + self.help_dict[func.__module__.split(".")[-1]] += [[pattern, args.get('help', None)]] else: - self.help_dict[func.__module__.split(".")[-1]] = [pattern] + self.help_dict[func.__module__.split(".")[-1]] = [[pattern, args.get('help', None)]] self.command_handler.incoming_commands.append({ "pattern": pattern, @@ -103,14 +103,14 @@ class Loader(): for pattern in pattern_list: if args.get("hide_help", False): if func.__module__.split(".")[-1] in self.help_hidden_dict: - self.help_hidden_dict[func.__module__.split(".")[-1]] += [pattern] + self.help_hidden_dict[func.__module__.split(".")[-1]] += [[pattern, args.get('help', None)]] else: - self.help_hidden_dict[func.__module__.split(".")[-1]] = [pattern] + self.help_hidden_dict[func.__module__.split(".")[-1]] = [[pattern, args.get('help', None)]] else: if func.__module__.split(".")[-1] in self.help_dict: - self.help_dict[func.__module__.split(".")[-1]] += [pattern] + self.help_dict[func.__module__.split(".")[-1]] += [[pattern, args.get('help', None)]] else: - self.help_dict[func.__module__.split(".")[-1]] = [pattern] + self.help_dict[func.__module__.split(".")[-1]] = [[pattern, args.get('help', None)]] self.command_handler.incoming_commands.append({ "pattern": pattern, diff --git a/ubot/modules/catdog.py b/ubot/modules/catdog.py index 3634a72..826bbd5 100644 --- a/ubot/modules/catdog.py +++ b/ubot/modules/catdog.py @@ -55,7 +55,7 @@ async def tori_atsume(): return tori -@ldr.add("shibe") +@ldr.add("shibe", help="Fetches an image of a shibe.") async def shibe(event): shibe_inu = await shibe_inu_atsume() @@ -66,7 +66,7 @@ async def shibe(event): await event.reply(file=shibe_inu[0]) -@ldr.add("bird") +@ldr.add("bird", help="Fetches an image of a bird.") async def bird(event): tori = await tori_atsume() @@ -77,7 +77,7 @@ async def bird(event): await event.reply(file=tori[0]) -@ldr.add_list(["cat", "pussy"], pattern_extra="(gif|)(f|)") +@ldr.add_list(["cat", "pussy"], pattern_extra="(gif|)(f|)", help="Fetches an image of a cat.") async def cat(event): neko = await neko_atsume(GIFPARAM if event.other_args[0] else IMGPARAM) @@ -88,7 +88,7 @@ async def cat(event): await event.reply(file=neko[0]["url"], force_document=bool(event.other_args[1])) -@ldr.add_list(["dog", "bitch"], pattern_extra="(gif|)(f|)") +@ldr.add_list(["dog", "bitch"], pattern_extra="(gif|)(f|)", help="Fetches an image of a dog.") async def dog(event): inu = await inu_atsume(GIFPARAM if event.other_args[0] else IMGPARAM) diff --git a/ubot/modules/danbooru.py b/ubot/modules/danbooru.py index f0ff57c..878ac6f 100644 --- a/ubot/modules/danbooru.py +++ b/ubot/modules/danbooru.py @@ -9,6 +9,7 @@ from ubot.micro_bot import ldr DAN_URL = "http://danbooru.donmai.us/posts.json" DAN_SAUCE_URL = "https://danbooru.donmai.us/posts/" dan_button_dict = {} +help_string = "Fetches images from Danbooru, takes tags as arguments." @ldr.add("danping", sudo=True, hide_help=True) @@ -23,8 +24,8 @@ async def danbooru_ping(event): await event.reply(f"Danbooru response time -> **{time_taken_ms}**ms") -@ldr.add_list(["dan", "danx", "danq"], pattern_extra="(f|)", nsfw=True, userlocking=True) -@ldr.add("dans", pattern_extra="(f|)", userlocking=True) +@ldr.add_list(["dan", "danx", "danq"], pattern_extra="(f|)", nsfw=True, userlocking=True, help=help_string) +@ldr.add("dans", pattern_extra="(f|)", userlocking=True, help=help_string) async def danbooru(event): safety_arg = event.command[-1] as_file = bool(event.other_args[0]) diff --git a/ubot/modules/deepfry.py b/ubot/modules/deepfry.py index b350477..bebd84e 100644 --- a/ubot/modules/deepfry.py +++ b/ubot/modules/deepfry.py @@ -33,7 +33,7 @@ from PIL import Image, ImageEnhance from ubot.micro_bot import ldr -@ldr.add("deepfry", pattern_extra="(f|)", userlocking=True) +@ldr.add("deepfry", pattern_extra="(f|)", userlocking=True, help="Deepfries images, takes a number of passes as an argument.") async def deepfryer(event): as_file = bool(event.other_args[0]) diff --git a/ubot/modules/evaluation.py b/ubot/modules/evaluation.py index a5101bb..6b5799e 100644 --- a/ubot/modules/evaluation.py +++ b/ubot/modules/evaluation.py @@ -94,7 +94,7 @@ async def userprofilegetter(event): await event.reply(f"**Full Name:** {userfullname}\n**Username:** @{username}\n**User ID:** {userid}") -@ldr.add("stickpng") +@ldr.add("stickpng", help="Converts stickers to PNG files.") async def stickertopng(event): reply = await event.get_reply_message() @@ -115,7 +115,7 @@ async def stickertopng(event): await event.reply(file=sticker_png_io, force_document=True) -@ldr.add("stickflip") +@ldr.add("stickflip", help="Flips stickers horizontally.") async def flipsticker(event): reply = await event.get_reply_message() @@ -137,7 +137,7 @@ async def flipsticker(event): await event.reply(file=sticker_flipped_io) -@ldr.add("stickimg") +@ldr.add("stickimg", help="Converts images to sticker sized PNG files.") async def createsticker(event): if event.is_reply: reply_message = await event.get_reply_message() diff --git a/ubot/modules/fourchan.py b/ubot/modules/fourchan.py index 86a50bb..970ab11 100644 --- a/ubot/modules/fourchan.py +++ b/ubot/modules/fourchan.py @@ -11,7 +11,7 @@ VALID_ENDS = (".mp4", ".jpg", ".jpeg", ".png", ".gif") NSFW_BOARDS = ['aco', 'b', 'bant', 'd', 'e', 'f', 'gif', 'h', 'hc', 'hm', 'hr', 'i', 'ic', 'pol', 'r', 'r9k', 's', 's4s', 'soc', 't', 'trash', 'u', 'wg', 'y'] -@ldr.add("4c", pattern_extra="(f|)", userlocking=True, pass_nsfw=True) +@ldr.add("4c", pattern_extra="(f|)", userlocking=True, pass_nsfw=True, help="Fetches images from 4chan, requires a board name as an argument.") async def fourchan(event): if not event.args: await event.reply(f"Syntax: {ldr.prefix()}4c(f|) ") diff --git a/ubot/modules/gelbooru.py b/ubot/modules/gelbooru.py index 2f8b76f..dcc56aa 100644 --- a/ubot/modules/gelbooru.py +++ b/ubot/modules/gelbooru.py @@ -9,10 +9,11 @@ from ubot.micro_bot import ldr GEL_URL = "https://gelbooru.com/index.php" GEL_SAUCE_URL = "https://gelbooru.com/index.php?page=post&s=view&id=" gel_button_dict = {} +help_string = "Fetches images from Gelbooru, takes tags as arguments." @ldr.add("gelping", sudo=True, hide_help=True) -async def danbooru_ping(event): +async def gelbooru_ping(event): params = {"page": "dapi", "s": "post", "q": "index", @@ -27,8 +28,8 @@ async def danbooru_ping(event): await event.reply(f"Gelbooru response time -> **{time_taken_ms}**ms") -@ldr.add_list(["gel", "gelx", "gelq"], pattern_extra="(f|)", nsfw=True, userlocking=True) -@ldr.add("gels", pattern_extra="(f|)", userlocking=True) +@ldr.add_list(["gel", "gelx", "gelq"], pattern_extra="(f|)", nsfw=True, userlocking=True, help=help_string) +@ldr.add("gels", pattern_extra="(f|)", userlocking=True, help=help_string) async def gelbooru(event): safety_arg = event.command[-1] as_file = bool(event.other_args[0]) diff --git a/ubot/modules/reddit.py b/ubot/modules/reddit.py index 8ea4d85..3f57043 100644 --- a/ubot/modules/reddit.py +++ b/ubot/modules/reddit.py @@ -114,7 +114,9 @@ async def bodyfetcher(event, sub): await event.reply(f"Failed to find any valid content on **r/{sub}**!") -@ldr.add_list(["redi", "redb", "redt"], userlocking=True, pass_nsfw=True) +@ldr.add("redi", userlocking=True, pass_nsfw=True, help="Fetches images from Reddit, requires a subreddit name as an argument.") +@ldr.add("redb", userlocking=True, pass_nsfw=True, help="Fetches text from Reddit, requires a subreddit name as an argument.") +@ldr.add("redt", userlocking=True, pass_nsfw=True, help="Fetches titles from Reddit, requires a subreddit name as an argument.") async def redimg(event): sub = event.args.replace(" ", "_") fetch_type = event.command[-1] diff --git a/ubot/modules/sankaku.py b/ubot/modules/sankaku.py index 1aef09d..7aff822 100644 --- a/ubot/modules/sankaku.py +++ b/ubot/modules/sankaku.py @@ -9,6 +9,7 @@ from ubot.micro_bot import ldr SAN_URL = "https://capi-v2.sankakucomplex.com/posts" SAN_SAUCE_URL = "https://beta.sankakucomplex.com/post/show/" san_button_dict = {} +help_string = "Fetches images from Sankaku Complex, takes tags as arguments." @ldr.add("sanping", sudo=True, hide_help=True) @@ -24,8 +25,8 @@ async def sankaku_ping(event): await event.reply(f"Sankaku response time -> **{time_taken_ms}**ms") -@ldr.add_list(["san", "sanx", "sanq"], pattern_extra="(f|)", nsfw=True, userlocking=True) -@ldr.add("sans", pattern_extra="(f|)", userlocking=True) +@ldr.add_list(["san", "sanx", "sanq"], pattern_extra="(f|)", nsfw=True, userlocking=True, help=help_string) +@ldr.add("sans", pattern_extra="(f|)", userlocking=True, help=help_string) async def sankaku(event): safety_arg = event.command[-1] as_file = bool(event.other_args[0]) diff --git a/ubot/modules/scrapers.py b/ubot/modules/scrapers.py index 4c190fb..a3f0b3e 100644 --- a/ubot/modules/scrapers.py +++ b/ubot/modules/scrapers.py @@ -14,7 +14,7 @@ from ubot.micro_bot import ldr os.environ["HOWDOI_SEARCH_ENGINE"] = "bing" -@ldr.add("dadjoke") +@ldr.add("dadjoke", help="Fetches the most funny shit you've ever read.") async def dadjoke(event): async with ldr.aioclient.get("https://icanhazdadjoke.com/", headers={"Accept": "application/json"}) as response: if response.status == 200: @@ -26,7 +26,7 @@ async def dadjoke(event): await event.reply(dad_joke) -@ldr.add("fact") +@ldr.add("fact", help="Fetches random facts.") async def randomfact(event): async with ldr.aioclient.get("https://uselessfacts.jsph.pl/random.json", params={"language": "en"}) as response: if response.status == 200: @@ -38,7 +38,7 @@ async def randomfact(event): await event.reply(random_fact) -@ldr.add("fakeword") +@ldr.add("fakeword", help="Fetches random fake words.") async def fakeword(event): async with ldr.aioclient.get("https://www.thisworddoesnotexist.com/api/random_word.json") as response: if response.status == 200: @@ -53,7 +53,7 @@ async def fakeword(event): await event.reply(f"**{word}:** __{definition}__\n\n**Example:** __{example}__") -@ldr.add("pokemon", pattern_extra="(s|)") +@ldr.add("pokemon", pattern_extra="(s|)", help="Fetches Pokemon sprites, requires a name or ID as an argument.") async def pokemon_image(event): if not event.args: await event.reply("Specify a Pokémon name!") @@ -100,7 +100,7 @@ async def howdoi_cmd(event): await event.reply(f"**Query:**\n{event.args}\n**Answer:**\n{response}") -@ldr.add("tts") +@ldr.add("tts", help="Text to speech.") async def text_to_speech(event): text, reply = await ldr.get_text(event, return_msg=True) @@ -125,7 +125,7 @@ async def text_to_speech(event): await event.client.send_file(event.chat_id, tts_bytesio, voice_note=True, reply_to=reply) -@ldr.add("ip") +@ldr.add("ip", help="IP lookup.") async def ip_lookup(event): ip = await ldr.get_text(event) @@ -164,7 +164,7 @@ async def ip_lookup(event): await event.reply(text) -@ldr.add("corona") +@ldr.add("corona", help="Fetches Coronavirus stats, takes an optional country name as an argument.") async def corona(event): if event.args: async with ldr.aioclient.get(f"https://corona.lmao.ninja/v2/countries/{event.args}") as response: diff --git a/ubot/modules/system.py b/ubot/modules/system.py index d2478e1..de398f0 100644 --- a/ubot/modules/system.py +++ b/ubot/modules/system.py @@ -5,7 +5,7 @@ from time import time_ns from ubot.micro_bot import ldr -@ldr.add("del") +@ldr.add("del", help="Deletes messages from this bot, it's a safety feature.") async def delete_message(event): message_to_delete = await event.get_reply_message() @@ -15,13 +15,24 @@ async def delete_message(event): @ldr.add("help") async def help_cmd(event): + if event.args: + for key, value in ldr.help_dict.items(): + for info in value: + if event.args == info[0]: + if info[1]: + await event.reply(f"Help for **{info[0]}**: __{info[1]}__") + return + + await event.reply(f"**{info[0]}** doesn't have a help string.") + return + prefix = ldr.prefix() help_string = "" for key, value in ldr.help_dict.items(): help_string += f"\n**{key}**: " for info in value: - help_string += f"{prefix}{info}, " + help_string += f"{prefix}{info[0]}, " help_string = help_string.rstrip(", ") await event.reply(f"**Available commands:**\n{help_string}") @@ -29,12 +40,23 @@ async def help_cmd(event): @ldr.add("sudohelp", sudo=True) async def sudohelp(event): + if event.args: + for key, value in ldr.help_hidden_dict.items(): + for info in value: + if event.args == info[0]: + if info[1]: + await event.reply(f"Help for **{info[0]}**: __{info[1]}__") + return + + await event.reply(f"**{info[0]}** doesn't have a help string.") + return + help_string = "" for key, value in ldr.help_hidden_dict.items(): help_string += f"\n**{key}**: " for info in value: - help_string += f"`{info}`, " + help_string += f"`{info[0]}`, " help_string = help_string.rstrip(", ") await event.reply(f"**Available (hidden) commands:**\n{help_string}") @@ -53,7 +75,7 @@ async def bot_repo(event): await event.reply("https://github.com/Nick80835/microbot") -@ldr.add("nsfw", admin=True) +@ldr.add("nsfw", admin=True, help="Enables or disables NSFW commands for a chat, requires admin.") async def nsfw_toggle(event): if not event.args or event.args not in ("on", "off"): if str(event.chat.id) not in ldr.settings.get_list("nsfw_blacklist"): diff --git a/ubot/modules/urbandict.py b/ubot/modules/urbandict.py index 2018626..f611b25 100644 --- a/ubot/modules/urbandict.py +++ b/ubot/modules/urbandict.py @@ -8,7 +8,7 @@ UD_QUERY_URL = 'http://api.urbandictionary.com/v0/define' UD_RANDOM_URL = 'http://api.urbandictionary.com/v0/random' -@ldr.add("ud") +@ldr.add("ud", help="Fetches words from Urban Dictionary, takes an optional word as an argument.") async def urban_dict(event): udquery = event.args