From 6eb5da70d606fead3306949e5e3cd214d3c1ecaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Tue, 19 Dec 2023 23:59:52 +0800 Subject: [PATCH 01/11] update slash --- bots/discord/slash/arcaea.py | 8 +-- bots/discord/slash/ask.py | 2 +- bots/discord/slash/bugtracker.py | 2 +- bots/discord/slash/color.py | 2 +- bots/discord/slash/core.py | 94 ++++++++++++++++++++--------- bots/discord/slash/cytoid.py | 10 +-- bots/discord/slash/dice.py | 4 +- bots/discord/slash/exchange_rate.py | 4 +- bots/discord/slash/github.py | 8 +-- bots/discord/slash/idlist.py | 28 --------- bots/discord/slash/ip.py | 2 +- bots/discord/slash/mcplayer.py | 2 +- bots/discord/slash/mcv.py | 10 +-- bots/discord/slash/server.py | 2 +- bots/discord/slash/tweet.py | 2 +- bots/discord/slash/whois.py | 2 +- bots/discord/slash/wiki.py | 12 ++-- bots/discord/slash/wolframalpha.py | 4 +- 18 files changed, 103 insertions(+), 95 deletions(-) delete mode 100644 bots/discord/slash/idlist.py diff --git a/bots/discord/slash/arcaea.py b/bots/discord/slash/arcaea.py index 0a50364488..14d1cf8954 100644 --- a/bots/discord/slash/arcaea.py +++ b/bots/discord/slash/arcaea.py @@ -6,12 +6,12 @@ arcaea = client.create_group("arcaea", "Queries about Arcaea.") -@arcaea.command(description="Get the latest version of game apk.") +@arcaea.command(name="download", description="Get the latest version of game apk.") async def download(ctx: discord.ApplicationContext): await slash_parser(ctx, "download") -@arcaea.command(description="Random a song.") +@arcaea.command(name="random", description="Random a song.") async def random(ctx: discord.ApplicationContext): await slash_parser(ctx, "random") @@ -19,11 +19,11 @@ async def random(ctx: discord.ApplicationContext): rank = arcaea.create_subgroup("rank", "View the current daily rank of Arcaea songs.") -@rank.command(description="View the current rank of the free packs.") +@rank.command(name="free", description="View the current rank of the free packs.") async def free(ctx: discord.ApplicationContext): await slash_parser(ctx, "rank free") -@rank.command(description="View the current rank of the paid packs.") +@rank.command(name="paid", description="View the current rank of the paid packs.") async def paid(ctx: discord.ApplicationContext): await slash_parser(ctx, "rank paid") diff --git a/bots/discord/slash/ask.py b/bots/discord/slash/ask.py index 4cd3fefec9..143c3e5efe 100644 --- a/bots/discord/slash/ask.py +++ b/bots/discord/slash/ask.py @@ -4,7 +4,7 @@ from bots.discord.slash_parser import slash_parser -@client.slash_command(description="Answer your question via ChatGPT.") +@client.slash_command(name="ask", description="Answer your question via ChatGPT.") @discord.option(name="question", description="Ask ChatGPT.") async def ask(ctx: discord.ApplicationContext, question: str): await slash_parser(ctx, question) \ No newline at end of file diff --git a/bots/discord/slash/bugtracker.py b/bots/discord/slash/bugtracker.py index c874fac882..10db5cdf8e 100644 --- a/bots/discord/slash/bugtracker.py +++ b/bots/discord/slash/bugtracker.py @@ -9,7 +9,7 @@ async def auto_search(ctx: discord.AutocompleteContext): return ['BDS-', 'MCPE-', 'MCD-', 'MCL-', 'MCLG-', 'REALMS-', 'MC-', 'WEB-'] -@client.command(description="Query the corresponding ticket on Mojira.") +@client.command(name="bugtracker", description="Query the corresponding ticket on Mojira.") @discord.option(name="mojiraid", autocomplete=auto_search) async def bugtracker(ctx: discord.ApplicationContext, mojiraid: str): await slash_parser(ctx, mojiraid) diff --git a/bots/discord/slash/color.py b/bots/discord/slash/color.py index f9905bc61b..d46ac39d95 100644 --- a/bots/discord/slash/color.py +++ b/bots/discord/slash/color.py @@ -9,7 +9,7 @@ async def auto_complete(ctx: discord.AutocompleteContext): return ['#123456', 'rgb(12,34,56)', 'hsl(123,45%,67%)'] -@client.slash_command(description="Get color information.") +@client.slash_command(name="color", description="Get color information.") @discord.option(name="color", default="", autocomplete=auto_complete, description="Color information. Support for Hex, RGB, HSL color code, or name in CSS and Material Design.") async def color(ctx: discord.ApplicationContext, color: str): diff --git a/bots/discord/slash/core.py b/bots/discord/slash/core.py index aca679a95b..f9ea9005ea 100644 --- a/bots/discord/slash/core.py +++ b/bots/discord/slash/core.py @@ -3,39 +3,34 @@ from bots.discord.client import client from bots.discord.slash_parser import slash_parser -@client.slash_command(description="View details of a module.") -@discord.option(name="module", default="", description="The module you want to know about.") -async def help(ctx: discord.ApplicationContext, module: str): - await slash_parser(ctx, module) - -@client.slash_command(description="Set the bot running languages.") +@client.slash_command(name="locale", description="Set the bot running languages.") @discord.option(name="lang", default="", description="Supported language codes.") async def locale(ctx: discord.ApplicationContext, lang: str): await slash_parser(ctx, lang) -@client.slash_command(description="Make the bot stop sending message.") +@client.slash_command(name="mute", description="Make the bot stop sending message.") async def mute(ctx: discord.ApplicationContext): await slash_parser(ctx, "") -@client.slash_command(description="Get bot status.") +@client.slash_command(name="ping", description="Get bot status.") async def ping(ctx: discord.ApplicationContext): await slash_parser(ctx, "") -@client.slash_command(description="Get the number of petals in the current channel.") +@client.slash_command(name="petal", description="Get the number of petals in the current channel.") async def petal(ctx: discord.ApplicationContext): await slash_parser(ctx, "") -@client.slash_command(description="View bot version.") +@client.slash_command(name="version", description="View bot version.") async def version(ctx: discord.ApplicationContext): await slash_parser(ctx, "") -@client.slash_command(description="Get the ID of the user account that sent the command inside the bot.") +@client.slash_command(name="whoami", description="Get the ID of the user account that sent the command inside the bot.") async def whoami(ctx: discord.ApplicationContext): await slash_parser(ctx, "") @@ -43,30 +38,30 @@ async def whoami(ctx: discord.ApplicationContext): admin = client.create_group("admin", "Commands available to bot administrators.") -@admin.command(description="Set members as bot administrators.") +@admin.command(name="add", description="Set members as bot administrators.") @discord.option(name="userid", description="The user ID.") async def add(ctx: discord.ApplicationContext, userid: str): await slash_parser(ctx, f"add {userid}") -@admin.command(description="Remove bot administrator from member.") +@admin.command(name="remove", description="Remove bot administrator from member.") @discord.option(name="userid", description="The user ID.") async def remove(ctx: discord.ApplicationContext, userid: str): await slash_parser(ctx, f"remove {userid}") -@admin.command(description="View all bot administrators.") -async def list(ctx: discord.ApplicationContext): +@admin.command(name="list", description="View all bot administrators.") +async def lst(ctx: discord.ApplicationContext): await slash_parser(ctx, "list") -@admin.command(description="Limit someone to use bot in the channel.") +@admin.command(name="ban", description="Limit someone to use bot in the channel.") @discord.option(name="userid", description="The user ID.") async def ban(ctx: discord.ApplicationContext, userid: str): await slash_parser(ctx, f"ban {userid}") -@admin.command(description="Remove limit someone to use bot in the channel.") +@admin.command(name="unban", description="Remove limit someone to use bot in the channel.") @discord.option(name="userid", description="The user ID.") async def unban(ctx: discord.ApplicationContext, userid: str): await slash_parser(ctx, f"unban {userid}") @@ -75,50 +70,91 @@ async def unban(ctx: discord.ApplicationContext, userid: str): ali = client.create_group("alias", "Set custom command alias.") -@ali.command(description="Add custom command alias.") +@ali.command(name="add", description="Add custom command alias.") @discord.option(name="alias", description="The custom alias.") @discord.option(name="command", description="The command you want to refer to.") async def add(ctx: discord.ApplicationContext, alias: str, command: str): await slash_parser(ctx, f"add {alias} {command}") -@ali.command(description="Remove custom command alias.") +@ali.command(name="remove", description="Remove custom command alias.") @discord.option(name="alias", description="The custom alias.") async def remove(ctx: discord.ApplicationContext, alias: str): await slash_parser(ctx, f"remove {alias}") -@ali.command(description="View custom command alias.") -async def list(ctx: discord.ApplicationContext): +@ali.command(name="list", description="View custom command alias.") +async def lst(ctx: discord.ApplicationContext): await slash_parser(ctx, "list") -@ali.command(description="Reset custom command alias.") +@ali.command(name="reset", description="Reset custom command alias.") async def reset(ctx: discord.ApplicationContext): await slash_parser(ctx, "reset") +hlp = client.create_group("help", "Get bot help.") + + +@hlp.command(name="list", description="View help list.") +@discord.option(name="legacy", choices=[('true', 'legacy'), ('false', '')], description="Whether to use legacy mode.") +async def lst(ctx: discord.ApplicationContext, legacy: str): + await slash_parser(ctx, legacy) + + +@hlp.command(name="detail", description="View details of a module.") +@discord.option(name="module", default="", description="The module you want to know about.") +async def detail(ctx: discord.ApplicationContext, legacy: str): + await slash_parser(ctx, legacy) + + +@hlp.command(name="detail", description="View details of a module.") +@discord.option(name="module", default="", description="The module you want to know about.") +async def detail(ctx: discord.ApplicationContext, module: str): + await slash_parser(ctx, module) + + +m = client.create_group("module", "Set about modules.") + + +@m.command(name="enable", description="Enable module.") +@discord.option(name="module", description="The module name.") +async def add(ctx: discord.ApplicationContext, module: str): + await slash_parser(ctx, f"enable {module}") + + +@m.command(name="disable", description="Disable module.") +@discord.option(name="module", description="The module name.") +async def add(ctx: discord.ApplicationContext, module: str): + await slash_parser(ctx, f"disable {module}") + + +@m.command(name="list", description="View all available modules.") +async def lst(ctx: discord.ApplicationContext): + await slash_parser(ctx, "list") + + p = client.create_group("prefix", "Set custom command prefix.") -@p.command(description="Add custom command prefix.") +@p.command(name="add", description="Add custom command prefix.") @discord.option(name="prefix", description="The custom prefix.") async def add(ctx: discord.ApplicationContext, prefix: str): await slash_parser(ctx, f"add {prefix}") @p.command(description="Remove custom command prefix.") -@discord.option(name="prefix", description="The custom prefix.") +@discord.option(name="remove", name="prefix", description="The custom prefix.") async def remove(ctx: discord.ApplicationContext, prefix: str): await slash_parser(ctx, f"remove {prefix}") -@p.command(description="View custom command prefix.") -async def list(ctx: discord.ApplicationContext): +@p.command(name="list", description="View custom command prefix.") +async def lst(ctx: discord.ApplicationContext): await slash_parser(ctx, "list") -@p.command(description="Reset custom command prefix.") +@p.command(name="reset", description="Reset custom command prefix.") async def reset(ctx: discord.ApplicationContext): await slash_parser(ctx, "reset") @@ -126,12 +162,12 @@ async def reset(ctx: discord.ApplicationContext): setup = client.create_group("setup", "Set up bot actions.") -@setup.command(description="Set up whether to display input prompts.") +@setup.command(name="typing", description="Set up whether to display input prompts.") async def typing(ctx: discord.ApplicationContext): await slash_parser(ctx, "typing") -@setup.command(description="Set the time offset.") +@setup.command(name="timeoffset", description="Set the time offset.") @discord.option(name="offset", description="The timezone offset.") async def offset(ctx: discord.ApplicationContext, offset: str): await slash_parser(ctx, f"timeoffset {offset}") diff --git a/bots/discord/slash/cytoid.py b/bots/discord/slash/cytoid.py index f0bc3b8c61..df5f276caa 100644 --- a/bots/discord/slash/cytoid.py +++ b/bots/discord/slash/cytoid.py @@ -6,27 +6,27 @@ cytoid = client.create_group("cytoid", "Query about Cytoid.") -@cytoid.command(description="Query the Best 30 list.") +@cytoid.command(name="b30", description="Query the Best 30 list.") async def b30(ctx: discord.ApplicationContext): await slash_parser(ctx, "b30") -@cytoid.command(description="Query the Recent 30 list.") +@cytoid.command(name="r30", description="Query the Recent 30 list.") async def r30(ctx: discord.ApplicationContext): await slash_parser(ctx, "r30") -@cytoid.command(description="Query user profile.") +@cytoid.command(name="profile", description="Query user profile.") async def profile(ctx: discord.ApplicationContext): await slash_parser(ctx, "profile") -@cytoid.command(description="Bind user.") +@cytoid.command(name="bind", description="Bind user.") @discord.option(name="username", description="Your Cytoid username.") async def bind(ctx: discord.ApplicationContext, username: str): await slash_parser(ctx, f"bind {username}") -@cytoid.command(description="Unbind user.") +@cytoid.command(name="unbind", description="Unbind user.") async def unbind(ctx: discord.ApplicationContext): await slash_parser(ctx, "unbind") diff --git a/bots/discord/slash/dice.py b/bots/discord/slash/dice.py index e61abdb35e..dc6961f9a8 100644 --- a/bots/discord/slash/dice.py +++ b/bots/discord/slash/dice.py @@ -12,13 +12,13 @@ async def auto_complete(ctx: discord.AutocompleteContext): dice = client.create_group("dice", "Random dice.") -@dice.command(description="Roll the specified dice.") +@dice.command(name="roll", description="Roll the specified dice.") @discord.option(name="dices", autocomplete=auto_complete, description="Dice expression.") @discord.option(name="dc", default="", description="Difficulty class.") async def roll(ctx: discord.ApplicationContext, dices: str, dc: str): await slash_parser(ctx, f'{dices} {dc}') -@dice.command(description="Modify the checking rule of dc.") +@dice.command(name="rule", description="Modify the checking rule of dc.") async def rule(ctx: discord.ApplicationContext): await slash_parser(ctx, 'rule') diff --git a/bots/discord/slash/exchange_rate.py b/bots/discord/slash/exchange_rate.py index 04dd9f432d..061e5228f1 100644 --- a/bots/discord/slash/exchange_rate.py +++ b/bots/discord/slash/exchange_rate.py @@ -3,9 +3,9 @@ from bots.discord.client import client from bots.discord.slash_parser import slash_parser -@client.slash_command(description="Convert currency prices according to the exchange rate of the day.") +@client.slash_command(name="exchange_rate", description="Convert currency prices according to the exchange rate of the day.") @discord.option(name="amount", description="The amount of base currency.") @discord.option(name="base", description="The base currency unit.") @discord.option(name="target", description="The target currency unit.") -async def exchange_rate(ctx: discord.ApplicationContext, amount: float, base: str, target: str): +async def excr(ctx: discord.ApplicationContext, amount: float, base: str, target: str): await slash_parser(ctx, f"{amount}{base} {target}") diff --git a/bots/discord/slash/github.py b/bots/discord/slash/github.py index e3d11e191d..27fd349bcb 100644 --- a/bots/discord/slash/github.py +++ b/bots/discord/slash/github.py @@ -7,25 +7,25 @@ github = client.create_group("github", "Github query tool.") -@github.command(description="Trying to automatically identifying and distinguishing repo/user.") +@github.command(name="get", description="Trying to automatically identifying and distinguishing repo/user.") @discord.option(name="name", description="GitHub user or repository name.") async def get(ctx: discord.ApplicationContext, name: str): await slash_parser(ctx, name) -@github.command(description="Get GitHub repository information.") +@github.command(name="repo", description="Get GitHub repository information.") @discord.option(name="name", description="GitHub repository name.") async def repo(ctx: discord.ApplicationContext, name: str): await slash_parser(ctx, f'repo {name}') -@github.command(description="Get GitHub user or organization information.") +@github.command(name="user", description="Get GitHub user or organization information.") @discord.option(name="name", description="GitHub user name.") async def user(ctx: discord.ApplicationContext, name: str): await slash_parser(ctx, f'user {name}') -@github.command(description="Search repositories on GitHub.") +@github.command(name="search", description="Search repositories on GitHub.") @discord.option(name="query", description="Search keywords.") async def search(ctx: discord.ApplicationContext, query: str): await slash_parser(ctx, f'search {keyword}') diff --git a/bots/discord/slash/idlist.py b/bots/discord/slash/idlist.py deleted file mode 100644 index acb5fecc2f..0000000000 --- a/bots/discord/slash/idlist.py +++ /dev/null @@ -1,28 +0,0 @@ -import urllib.parse - -import discord - -from bots.discord.client import client -from bots.discord.slash_parser import slash_parser -from core.utils.http import get_url - -api = 'https://ca.projectxero.top/idlist/search' - - -async def auto_search(ctx: discord.AutocompleteContext): - title = ctx.options["keywords"] - query_options = {'q': title, 'limit': '5'} - query_url = api + '?' + urllib.parse.urlencode(query_options) - resp = await get_url(query_url, 200, fmt='json') - result_ = resp['data']['result'] - results = [title] - if result_: - for x in result_: - results.append(f'{x["enumName"]} {x["key"]}') - return results - - -@client.slash_command(description="查询MCBEID表") -@discord.option(name="keywords", description="关键词", autocomplete=auto_search) -async def idlist(ctx: discord.ApplicationContext, keywords: str): - await slash_parser(ctx, keywords) diff --git a/bots/discord/slash/ip.py b/bots/discord/slash/ip.py index 2c6932ddb3..a6ccce477f 100644 --- a/bots/discord/slash/ip.py +++ b/bots/discord/slash/ip.py @@ -4,7 +4,7 @@ from bots.discord.slash_parser import slash_parser -@client.slash_command(description="Query the information of IP.") +@client.slash_command(name="ip", description="Query the information of IP.") @discord.option(name="ip_address", description="The IP address.") async def ip(ctx: discord.ApplicationContext, ip_address: str): await slash_parser(ctx, ip_address) diff --git a/bots/discord/slash/mcplayer.py b/bots/discord/slash/mcplayer.py index babaeed3d8..665f5a1823 100644 --- a/bots/discord/slash/mcplayer.py +++ b/bots/discord/slash/mcplayer.py @@ -4,7 +4,7 @@ from bots.discord.slash_parser import slash_parser -@client.slash_command(description="Get Minecraft player information.") +@client.slash_command(name="mcplayer", description="Get Minecraft player information.") @discord.option(name="username_or_uuid", description="The name or UUID of Minecraft player.") async def mcplayer(ctx: discord.ApplicationContext, username_or_uuid: str): await slash_parser(ctx, username_or_uuid) diff --git a/bots/discord/slash/mcv.py b/bots/discord/slash/mcv.py index b41cd91a98..bd00978845 100644 --- a/bots/discord/slash/mcv.py +++ b/bots/discord/slash/mcv.py @@ -4,26 +4,26 @@ from bots.discord.slash_parser import slash_parser -@client.slash_command(description="Get the latest version of Minecraft: Java Edition in the launcher.") +@client.slash_command(name="mcv", description="Get the latest version of Minecraft: Java Edition in the launcher.") async def mcv(ctx: discord.ApplicationContext): await slash_parser(ctx, '') -@client.slash_command(description="Get the latest version of Minecraft: Bedrock Edition on Mojira.") +@client.slash_command(name="mcbv", description="Get the latest version of Minecraft: Bedrock Edition on Mojira.") async def mcbv(ctx: discord.ApplicationContext): await slash_parser(ctx, '') -@client.slash_command(description="Get the latest version of Minecraft Dungeons on Mojira.") +@client.slash_command(name="mcdv", description="Get the latest version of Minecraft Dungeons on Mojira.") async def mcdv(ctx: discord.ApplicationContext): await slash_parser(ctx, '') -@client.slash_command(description="Get the latest version of Minecraft: Education Edition in Windows Edition.") +@client.slash_command(name="mcev", description="Get the latest version of Minecraft: Education Edition in Windows Edition.") async def mcev(ctx: discord.ApplicationContext): await slash_parser(ctx, '') -@client.slash_command(description="Get the latest version of Minecraft Legends on Mojira.") +@client.slash_command(name="mclgv", description="Get the latest version of Minecraft Legends on Mojira.") async def mclgv(ctx: discord.ApplicationContext): await slash_parser(ctx, '') \ No newline at end of file diff --git a/bots/discord/slash/server.py b/bots/discord/slash/server.py index 02ea118c1d..8846884d73 100644 --- a/bots/discord/slash/server.py +++ b/bots/discord/slash/server.py @@ -10,7 +10,7 @@ async def auto_search(ctx: discord.AutocompleteContext): return [ctx.options["address"]] -@client.slash_command(description="Get Minecraft: Java/Bedrock Edition server motd.") +@client.slash_command(name="server", description="Get Minecraft: Java/Bedrock Edition server motd.") @discord.option(name="address", description="The server address.", autocomplete=auto_search) async def server(ctx: discord.ApplicationContext, address: str): await slash_parser(ctx, address) diff --git a/bots/discord/slash/tweet.py b/bots/discord/slash/tweet.py index fb1ccdf7f2..82df52e684 100644 --- a/bots/discord/slash/tweet.py +++ b/bots/discord/slash/tweet.py @@ -3,7 +3,7 @@ from bots.discord.client import client from bots.discord.slash_parser import slash_parser -@client.slash_command(description="Get tweet image from tweet ID or link.") +@client.slash_command(name="tweet", description="Get tweet image from tweet ID or link.") @discord.option(name="tweet", description="The tweet ID or tweet link.") async def tweet(ctx: discord.ApplicationContext, tweetid: str): await slash_parser(ctx, tweet) diff --git a/bots/discord/slash/whois.py b/bots/discord/slash/whois.py index 24385d99ed..f58af5533d 100644 --- a/bots/discord/slash/whois.py +++ b/bots/discord/slash/whois.py @@ -4,7 +4,7 @@ from bots.discord.slash_parser import slash_parser -@client.slash_command(description="Query the information of WHOIS.") +@client.slash_command(name="whois", description="Query the information of WHOIS.") @discord.option(name="domain", description="The domain.") async def whois(ctx: discord.ApplicationContext, domain: str): await slash_parser(ctx, domain) diff --git a/bots/discord/slash/wiki.py b/bots/discord/slash/wiki.py index a09c1557fd..45d06cc9ba 100644 --- a/bots/discord/slash/wiki.py +++ b/bots/discord/slash/wiki.py @@ -59,25 +59,25 @@ async def default_wiki(ctx: discord.AutocompleteContext): return ['https://zh.minecraft.wiki/'] -@wiki.command(description="Query a wiki page.") +@wiki.command(name="query", description="Query a wiki page.") @discord.option(name="pagename", description="The title of wiki page.", autocomplete=auto_search) async def query(ctx: discord.ApplicationContext, pagename: str): await slash_parser(ctx, pagename) -@wiki.command(name="id", description="Query a Wiki page based on page ID.") +@wiki.command(name="id", name="id", description="Query a Wiki page based on page ID.") @discord.option(name="pageid", description="The wiki page ID.") async def byid(ctx: discord.ApplicationContext, pageid: str): await slash_parser(ctx, f'id {pageid}') -@wiki.command(description="Search a wiki page.") +@wiki.command(name="search", description="Search a wiki page.") @discord.option(name="pagename", description="The title of wiki page.", autocomplete=auto_search) async def search(ctx: discord.ApplicationContext, pagename: str): await slash_parser(ctx, f'search {pagename}') -@wiki.command(name="set", description="Set up start wiki.") +@wiki.command(name="set", name="set", description="Set up start wiki.") @discord.option(name="wikiurl", description="The URL of wiki.", autocomplete=default_wiki) async def set_base(ctx: discord.ApplicationContext, wikiurl: str): await slash_parser(ctx, f'set {wikiurl}') @@ -150,11 +150,11 @@ async def reset_prefix(ctx: discord.ApplicationContext): await slash_parser(ctx, 'prefix reset') -@wiki.command(description="Toggle whether to use Fandom global Interwiki queries.") +@wiki.command(name="fandom", description="Toggle whether to use Fandom global Interwiki queries.") async def fandom(ctx: discord.ApplicationContext): await slash_parser(ctx, 'fandom') -@wiki.command(description="Toggle whether to return the edit link when the page does not exist.") +@wiki.command(name="redlink", description="Toggle whether to return the edit link when the page does not exist.") async def redlink(ctx: discord.ApplicationContext): await slash_parser(ctx, 'redlink') diff --git a/bots/discord/slash/wolframalpha.py b/bots/discord/slash/wolframalpha.py index 33651d9bac..768cf2da26 100644 --- a/bots/discord/slash/wolframalpha.py +++ b/bots/discord/slash/wolframalpha.py @@ -6,13 +6,13 @@ wolframalpha = client.create_group("wolframalpha", "Use WolframAlpha.") -@wolframalpha.command(description="Input a question or formula to search for WolframAlpha.") +@wolframalpha.command(name="query", description="Input a question or formula to search for WolframAlpha.") @discord.option(name="query", description="Enter what you want to calculate.") async def query(ctx: discord.ApplicationContext, query: str): await slash_parser(ctx, query) -@wolframalpha.command(description="Answer the question via WolframAlpha.") +@wolframalpha.command(name="ask", description="Answer the question via WolframAlpha.") @discord.option(name="question", description="Ask WolframAlpha.") async def ask(ctx: discord.ApplicationContext, question: str): await slash_parser(ctx, f"ask {question}") \ No newline at end of file From 87c5f764281b3c5d9a9447dc70f26c652d88cbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 00:03:04 +0800 Subject: [PATCH 02/11] fx --- bots/discord/slash/core.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bots/discord/slash/core.py b/bots/discord/slash/core.py index f9ea9005ea..be322fb328 100644 --- a/bots/discord/slash/core.py +++ b/bots/discord/slash/core.py @@ -102,12 +102,6 @@ async def lst(ctx: discord.ApplicationContext, legacy: str): await slash_parser(ctx, legacy) -@hlp.command(name="detail", description="View details of a module.") -@discord.option(name="module", default="", description="The module you want to know about.") -async def detail(ctx: discord.ApplicationContext, legacy: str): - await slash_parser(ctx, legacy) - - @hlp.command(name="detail", description="View details of a module.") @discord.option(name="module", default="", description="The module you want to know about.") async def detail(ctx: discord.ApplicationContext, module: str): From 1a4b59d7c4aab2887dd6e2614b76c5f6db4502ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 00:05:53 +0800 Subject: [PATCH 03/11] upd thonc --- bots/discord/slash/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bots/discord/slash/core.py b/bots/discord/slash/core.py index be322fb328..07e1eca621 100644 --- a/bots/discord/slash/core.py +++ b/bots/discord/slash/core.py @@ -97,8 +97,9 @@ async def reset(ctx: discord.ApplicationContext): @hlp.command(name="list", description="View help list.") -@discord.option(name="legacy", choices=[('true', 'legacy'), ('false', '')], description="Whether to use legacy mode.") +@discord.option(name="legacy", choices=['true', 'false'], description="Whether to use legacy mode.") async def lst(ctx: discord.ApplicationContext, legacy: str): + legacy = "legacy" if legacy == "true" else "" await slash_parser(ctx, legacy) From 34838d424872b910fd06d58a537bd882a3f7cf51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 00:10:50 +0800 Subject: [PATCH 04/11] fix --- bots/discord/slash/core.py | 4 ++-- bots/discord/slash/wiki.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bots/discord/slash/core.py b/bots/discord/slash/core.py index 07e1eca621..b6049458f0 100644 --- a/bots/discord/slash/core.py +++ b/bots/discord/slash/core.py @@ -138,8 +138,8 @@ async def add(ctx: discord.ApplicationContext, prefix: str): await slash_parser(ctx, f"add {prefix}") -@p.command(description="Remove custom command prefix.") -@discord.option(name="remove", name="prefix", description="The custom prefix.") +@p.command(name="remove", description="Remove custom command prefix.") +@discord.option(name="prefix", description="The custom prefix.") async def remove(ctx: discord.ApplicationContext, prefix: str): await slash_parser(ctx, f"remove {prefix}") diff --git a/bots/discord/slash/wiki.py b/bots/discord/slash/wiki.py index 45d06cc9ba..1c1f12de66 100644 --- a/bots/discord/slash/wiki.py +++ b/bots/discord/slash/wiki.py @@ -65,7 +65,7 @@ async def query(ctx: discord.ApplicationContext, pagename: str): await slash_parser(ctx, pagename) -@wiki.command(name="id", name="id", description="Query a Wiki page based on page ID.") +@wiki.command(name="id", description="Query a Wiki page based on page ID.") @discord.option(name="pageid", description="The wiki page ID.") async def byid(ctx: discord.ApplicationContext, pageid: str): await slash_parser(ctx, f'id {pageid}') @@ -77,7 +77,7 @@ async def search(ctx: discord.ApplicationContext, pagename: str): await slash_parser(ctx, f'search {pagename}') -@wiki.command(name="set", name="set", description="Set up start wiki.") +@wiki.command(name="set", description="Set up start wiki.") @discord.option(name="wikiurl", description="The URL of wiki.", autocomplete=default_wiki) async def set_base(ctx: discord.ApplicationContext, wikiurl: str): await slash_parser(ctx, f'set {wikiurl}') @@ -105,7 +105,7 @@ async def iw_list(ctx: discord.ApplicationContext, legacy: str): await slash_parser(ctx, f'iw list {legacy}') -@iw.command(name="show", description="Get the API address corresponding to the set Interwiki.") +@iw.command(name="get", description="Get the API address corresponding to the set Interwiki.") @discord.option(name="interwiki", description="The custom Interwiki.", autocomplete=auto_get_custom_iw_list) async def get(ctx: discord.ApplicationContext, interwiki: str): await slash_parser(ctx, f'iw get {interwiki}') From 01db6c4959ba903249e84d0c5231324c6dd86fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 00:28:51 +0800 Subject: [PATCH 05/11] update --- bots/discord/slash/core.py | 42 +++++++++++++++++++++++++-------- bots/discord/slash/wiki.py | 3 ++- modules/wiki/locales/en_us.json | 4 ++-- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/bots/discord/slash/core.py b/bots/discord/slash/core.py index b6049458f0..3162ac688e 100644 --- a/bots/discord/slash/core.py +++ b/bots/discord/slash/core.py @@ -2,10 +2,28 @@ from bots.discord.client import client from bots.discord.slash_parser import slash_parser +from core.loader import ModulesManager +from core.utils.i18n import get_available_locales + +async def auto_get_module_list(ctx: discord.AutocompleteContext): + module_ = [] + module_list = ModulesManager.return_modules_list() + + for x in module_list: + if x not (module_list[x].required_superuser or module_list[x].required_base_superuser): + module_.append(x) + + return module_ + + +async def auto_get_lang(ctx: discord.AutocompleteContext): + + if not ctx.options["lang"]: + return get_available_locales() @client.slash_command(name="locale", description="Set the bot running languages.") -@discord.option(name="lang", default="", description="Supported language codes.") +@discord.option(name="lang", default="", description="Supported language codes.", autocomplete=auto_get_lang) async def locale(ctx: discord.ApplicationContext, lang: str): await slash_parser(ctx, lang) @@ -84,8 +102,10 @@ async def remove(ctx: discord.ApplicationContext, alias: str): @ali.command(name="list", description="View custom command alias.") -async def lst(ctx: discord.ApplicationContext): - await slash_parser(ctx, "list") +@discord.option(name="legacy", choices=['true', 'false'], description="Whether to use legacy mode.") +async def lst(ctx: discord.ApplicationContext, legacy: str): + legacy = "legacy" if legacy == "true" else "" + await slash_parser(ctx, f"list {legacy}") @ali.command(name="reset", description="Reset custom command alias.") @@ -104,7 +124,7 @@ async def lst(ctx: discord.ApplicationContext, legacy: str): @hlp.command(name="detail", description="View details of a module.") -@discord.option(name="module", default="", description="The module you want to know about.") +@discord.option(name="module", description="The module you want to know about.", autocomplete=auto_get_module_list) async def detail(ctx: discord.ApplicationContext, module: str): await slash_parser(ctx, module) @@ -112,21 +132,23 @@ async def detail(ctx: discord.ApplicationContext, module: str): m = client.create_group("module", "Set about modules.") -@m.command(name="enable", description="Enable module.") -@discord.option(name="module", description="The module name.") +@m.command(name="enable", description="Enable module(s).") +@discord.option(name="module", description="The modules you want to enable.", autocomplete=auto_get_module_list) async def add(ctx: discord.ApplicationContext, module: str): await slash_parser(ctx, f"enable {module}") -@m.command(name="disable", description="Disable module.") -@discord.option(name="module", description="The module name.") +@m.command(name="disable", description="Disable module(s).") +@discord.option(name="module", description="The modules you want to disable.", autocomplete=auto_get_module_list) async def add(ctx: discord.ApplicationContext, module: str): await slash_parser(ctx, f"disable {module}") @m.command(name="list", description="View all available modules.") -async def lst(ctx: discord.ApplicationContext): - await slash_parser(ctx, "list") +@discord.option(name="legacy", choices=['true', 'false'], description="Whether to use legacy mode.") +async def lst(ctx: discord.ApplicationContext, legacy: str): + legacy = "legacy" if legacy == "true" else "" + await slash_parser(ctx, f"list {legacy}") p = client.create_group("prefix", "Set custom command prefix.") diff --git a/bots/discord/slash/wiki.py b/bots/discord/slash/wiki.py index 1c1f12de66..bb52948304 100644 --- a/bots/discord/slash/wiki.py +++ b/bots/discord/slash/wiki.py @@ -100,8 +100,9 @@ async def iwremove(ctx: discord.ApplicationContext, interwiki: str): @iw.command(name="list", description="Lists the currently configured Interwiki.") -@discord.option(name="legacy", choices=[('true', 'legacy'), ('false', '')], description="Whether to use legacy mode.") +@discord.option(name="legacy", choices=['true', 'false'], description="Whether to use legacy mode.") async def iw_list(ctx: discord.ApplicationContext, legacy: str): + legacy = "legacy" if legacy == "true" else "" await slash_parser(ctx, f'iw list {legacy}') diff --git a/modules/wiki/locales/en_us.json b/modules/wiki/locales/en_us.json index 70386d5652..1e4564d61e 100644 --- a/modules/wiki/locales/en_us.json +++ b/modules/wiki/locales/en_us.json @@ -4,11 +4,11 @@ "wiki.help": "Query a wiki page.", "wiki.help.ab": "Get recent abuse logs for the default wiki.", "wiki.help.ab.legacy": "Get recent abuse logs for the default wiki. (Legacy)", - "wiki.help.fandom": "Toggles whether to use Fandom global Interwiki queries.", + "wiki.help.fandom": "Toggle whether to use Fandom global Interwiki queries.", "wiki.help.headers.remove": "Remove custom request headers.", "wiki.help.headers.reset": "Reset custom request headers.", "wiki.help.headers.add": "Add custom request headers.", - "wiki.help.headers.show": "Lists the currently set request headers.", + "wiki.help.headers.show": "View the currently set request headers.", "wiki.help.id": "Query a Wiki page based on page ID.", "wiki.help.iw.add": "Add custom Interwiki.", "wiki.help.iw.get": "Get the API address corresponding to the set Interwiki.", From dca6e19539b20301969ce49af50d996f66a4a46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 00:30:22 +0800 Subject: [PATCH 06/11] fix --- bots/discord/slash/core.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bots/discord/slash/core.py b/bots/discord/slash/core.py index 3162ac688e..a14b3dd088 100644 --- a/bots/discord/slash/core.py +++ b/bots/discord/slash/core.py @@ -10,14 +10,13 @@ async def auto_get_module_list(ctx: discord.AutocompleteContext): module_list = ModulesManager.return_modules_list() for x in module_list: - if x not (module_list[x].required_superuser or module_list[x].required_base_superuser): - module_.append(x) + if x not (module_list[x].required_superuser or module_list[x].required_base_superuser): + module_.append(x) return module_ async def auto_get_lang(ctx: discord.AutocompleteContext): - if not ctx.options["lang"]: return get_available_locales() From 54cfd9eabba905dac69d7c580aaa87410e12357f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 00:34:44 +0800 Subject: [PATCH 07/11] * --- bots/discord/slash/core.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/bots/discord/slash/core.py b/bots/discord/slash/core.py index a14b3dd088..ff82d8ed48 100644 --- a/bots/discord/slash/core.py +++ b/bots/discord/slash/core.py @@ -5,15 +5,6 @@ from core.loader import ModulesManager from core.utils.i18n import get_available_locales -async def auto_get_module_list(ctx: discord.AutocompleteContext): - module_ = [] - module_list = ModulesManager.return_modules_list() - - for x in module_list: - if x not (module_list[x].required_superuser or module_list[x].required_base_superuser): - module_.append(x) - - return module_ async def auto_get_lang(ctx: discord.AutocompleteContext): @@ -123,7 +114,7 @@ async def lst(ctx: discord.ApplicationContext, legacy: str): @hlp.command(name="detail", description="View details of a module.") -@discord.option(name="module", description="The module you want to know about.", autocomplete=auto_get_module_list) +@discord.option(name="module", description="The module you want to know about.") async def detail(ctx: discord.ApplicationContext, module: str): await slash_parser(ctx, module) @@ -132,13 +123,13 @@ async def detail(ctx: discord.ApplicationContext, module: str): @m.command(name="enable", description="Enable module(s).") -@discord.option(name="module", description="The modules you want to enable.", autocomplete=auto_get_module_list) +@discord.option(name="module", description="The modules you want to enable.") async def add(ctx: discord.ApplicationContext, module: str): await slash_parser(ctx, f"enable {module}") @m.command(name="disable", description="Disable module(s).") -@discord.option(name="module", description="The modules you want to disable.", autocomplete=auto_get_module_list) +@discord.option(name="module", description="The modules you want to disable.") async def add(ctx: discord.ApplicationContext, module: str): await slash_parser(ctx, f"disable {module}") From 692077c0c340b61c810ef480c524a37db1fdd24e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 00:41:43 +0800 Subject: [PATCH 08/11] upd --- bots/discord/slash/core.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bots/discord/slash/core.py b/bots/discord/slash/core.py index ff82d8ed48..3c79a63f05 100644 --- a/bots/discord/slash/core.py +++ b/bots/discord/slash/core.py @@ -5,6 +5,16 @@ from core.loader import ModulesManager from core.utils.i18n import get_available_locales +async def auto_get_module_list(ctx: discord.AutocompleteContext): + module_list = ModulesManager.return_modules_list() + module_ = [] + for x in module_list: + if x[0] == '_': + continue + if module_list[x].required_superuser or module_list[x].required_base_superuser: + continue + module_.append(module_list[x]) + return module_ async def auto_get_lang(ctx: discord.AutocompleteContext): @@ -114,7 +124,7 @@ async def lst(ctx: discord.ApplicationContext, legacy: str): @hlp.command(name="detail", description="View details of a module.") -@discord.option(name="module", description="The module you want to know about.") +@discord.option(name="module", description="The module you want to know about.", autocomplete=auto_get_module_list) async def detail(ctx: discord.ApplicationContext, module: str): await slash_parser(ctx, module) @@ -123,13 +133,13 @@ async def detail(ctx: discord.ApplicationContext, module: str): @m.command(name="enable", description="Enable module(s).") -@discord.option(name="module", description="The modules you want to enable.") +@discord.option(name="module", description="The modules you want to enable.", autocomplete=auto_get_module_list) async def add(ctx: discord.ApplicationContext, module: str): await slash_parser(ctx, f"enable {module}") @m.command(name="disable", description="Disable module(s).") -@discord.option(name="module", description="The modules you want to disable.") +@discord.option(name="module", description="The modules you want to disable.", autocomplete=auto_get_module_list) async def add(ctx: discord.ApplicationContext, module: str): await slash_parser(ctx, f"disable {module}") From 0565c40a2e4337834d8d5b21a409cd6f9bafd15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 00:47:27 +0800 Subject: [PATCH 09/11] upd change true/false --- bots/discord/slash/core.py | 6 +++--- bots/discord/slash/wiki.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bots/discord/slash/core.py b/bots/discord/slash/core.py index 3c79a63f05..2b508febc0 100644 --- a/bots/discord/slash/core.py +++ b/bots/discord/slash/core.py @@ -102,7 +102,7 @@ async def remove(ctx: discord.ApplicationContext, alias: str): @ali.command(name="list", description="View custom command alias.") -@discord.option(name="legacy", choices=['true', 'false'], description="Whether to use legacy mode.") +@discord.option(name="legacy", choices=['false', 'true'], description="Whether to use legacy mode.") async def lst(ctx: discord.ApplicationContext, legacy: str): legacy = "legacy" if legacy == "true" else "" await slash_parser(ctx, f"list {legacy}") @@ -117,7 +117,7 @@ async def reset(ctx: discord.ApplicationContext): @hlp.command(name="list", description="View help list.") -@discord.option(name="legacy", choices=['true', 'false'], description="Whether to use legacy mode.") +@discord.option(name="legacy", choices=['false', 'true'], description="Whether to use legacy mode.") async def lst(ctx: discord.ApplicationContext, legacy: str): legacy = "legacy" if legacy == "true" else "" await slash_parser(ctx, legacy) @@ -145,7 +145,7 @@ async def add(ctx: discord.ApplicationContext, module: str): @m.command(name="list", description="View all available modules.") -@discord.option(name="legacy", choices=['true', 'false'], description="Whether to use legacy mode.") +@discord.option(name="legacy", choices=['false', 'true'], description="Whether to use legacy mode.") async def lst(ctx: discord.ApplicationContext, legacy: str): legacy = "legacy" if legacy == "true" else "" await slash_parser(ctx, f"list {legacy}") diff --git a/bots/discord/slash/wiki.py b/bots/discord/slash/wiki.py index bb52948304..d2df9cf9ab 100644 --- a/bots/discord/slash/wiki.py +++ b/bots/discord/slash/wiki.py @@ -100,7 +100,7 @@ async def iwremove(ctx: discord.ApplicationContext, interwiki: str): @iw.command(name="list", description="Lists the currently configured Interwiki.") -@discord.option(name="legacy", choices=['true', 'false'], description="Whether to use legacy mode.") +@discord.option(name="legacy", choices=['false', 'true'], description="Whether to use legacy mode.") async def iw_list(ctx: discord.ApplicationContext, legacy: str): legacy = "legacy" if legacy == "true" else "" await slash_parser(ctx, f'iw list {legacy}') From 29674d4778b4062fd63e6892069b06fa8c1d9e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 00:53:31 +0800 Subject: [PATCH 10/11] fix --- bots/discord/slash/tweet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bots/discord/slash/tweet.py b/bots/discord/slash/tweet.py index 82df52e684..ff037e8845 100644 --- a/bots/discord/slash/tweet.py +++ b/bots/discord/slash/tweet.py @@ -4,6 +4,6 @@ from bots.discord.slash_parser import slash_parser @client.slash_command(name="tweet", description="Get tweet image from tweet ID or link.") -@discord.option(name="tweet", description="The tweet ID or tweet link.") +@discord.option(name="tweetid", description="The tweet ID or tweet link.") async def tweet(ctx: discord.ApplicationContext, tweetid: str): await slash_parser(ctx, tweet) From 307940c2e46b0c9a34998f17134663489b6c7030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Wed, 20 Dec 2023 01:01:02 +0800 Subject: [PATCH 11/11] upd --- modules/core/alias.py | 4 ++-- modules/core/utils.py | 2 +- modules/maimai/__init__.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/core/alias.py b/modules/core/alias.py index c007cd1941..40300724fe 100644 --- a/modules/core/alias.py +++ b/modules/core/alias.py @@ -1,4 +1,4 @@ -from core.builtins import Bot, Image, command_prefix +from core.builtins import Bot, Image from core.component import module from core.utils.image_table import image_table_render, ImageTable @@ -25,7 +25,7 @@ async def set_alias(msg: Bot.MessageSession): break if not has_prefix: await msg.finish(msg.locale.t("core.message.alias.add.invalid_prefix")) - command = command_prefix[0] + command[1:] + command = msg.prefixes[0] + command[1:] aliases[alias] = command msg.data.edit_option('command_alias', aliases) await msg.finish(msg.locale.t("core.message.alias.add.success", alias=alias, command=command)) diff --git a/modules/core/utils.py b/modules/core/utils.py index e185e1f9cb..bd2b286aa1 100644 --- a/modules/core/utils.py +++ b/modules/core/utils.py @@ -132,7 +132,7 @@ async def config_ban(msg: Bot.MessageSession): async def _(msg: Bot.MessageSession): avaliable_lang = msg.locale.t("message.delimiter").join(get_available_locales()) await msg.finish( - f"{msg.locale.t('core.message.locale')}{msg.locale.t('language')}\n{msg.locale.t('core.message.locale.set.prompt', langlist=avaliable_lang, prefix=command_prefix[0])}") + f"{msg.locale.t('core.message.locale')}{msg.locale.t('language')}\n{msg.locale.t('core.message.locale.set.prompt', langlist=avaliable_lang, prefix=msg.prefixes[0])}") @locale.command(' {{core.help.locale.set}}', required_admin=True) diff --git a/modules/maimai/__init__.py b/modules/maimai/__init__.py index 05855f30a9..e25e7db4a6 100644 --- a/modules/maimai/__init__.py +++ b/modules/maimai/__init__.py @@ -2,7 +2,7 @@ import traceback from config import Config -from core.builtins import Bot, command_prefix, Plain, Image as BImage +from core.builtins import Bot, Plain, Image as BImage from core.scheduler import CronTrigger from core.utils.image import msgchain2image from modules.maimai.libraries.maimai_best_50 import generate @@ -454,7 +454,7 @@ async def _(msg: Bot.MessageSession, diff: str, sid: str, score: float): b2t_2000_great=b2t_2000_great, b2t_2000_great_prop=b2t_2000_great_prop)}''') except ValueError: - await msg.finish(msg.locale.t('maimai.message.scoreline.error', prefix=command_prefix[0])) + await msg.finish(msg.locale.t('maimai.message.scoreline.error', prefix=msg.prefixes[0])) @mai.command('rating {{maimai.help.rating}}')