Archived
1
0
Fork 0

update slash commands

This commit is contained in:
多羅狼 2023-12-23 14:25:43 +08:00 committed by GitHub
parent 00880f05a0
commit a09a4a79e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 6 deletions

View file

@ -1,12 +1,20 @@
import colorsys
import discord
import random
from bots.discord.client import client
from bots.discord.slash_parser import slash_parser
async def auto_complete(ctx: discord.AutocompleteContext):
color_code = "#{:06x}".format(random.randint(0, 0xFFFFFF))
rgb = tuple(int(color_code[i:i+2], 16) for i in (1, 3, 5))
hsl = colorsys.rgb_to_hls(rgb[0] / 255.0, rgb[1] / 255.0, rgb[2] / 255.0)
if not ctx.options["color"]:
return ['#123456', 'rgb(12,34,56)', 'hsl(123,45%,67%)']
return [color_code,
f'rgb({",".join(map(str, rgb))})',
f'hsl({','.join(map(str, (int(hsl[0] * 360), int(hsl[1] * 100), int(hsl[2] * 100))))})']
@client.slash_command(name="color", description="Get color information.")

View file

@ -23,8 +23,8 @@ async def auto_get_lang(ctx: discord.AutocompleteContext):
@client.slash_command(name="locale", description="Set the bot running languages.")
@discord.option(name="lang", default="", description="Supported language codes.", autocomplete=auto_get_lang)
async def locale(ctx: discord.ApplicationContext, lang: str):
@discord.option(name="lang", description="Supported language codes.", autocomplete=auto_get_lang)
async def locale(ctx: discord.ApplicationContext, lang: str=None):
await slash_parser(ctx, lang)

View file

@ -14,8 +14,8 @@ dice = client.create_group("dice", "Random 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):
@discord.option(name="dc", description="Difficulty class.")
async def roll(ctx: discord.ApplicationContext, dices: str, dc: str=None):
await slash_parser(ctx, f'{dices} {dc}')

View file

@ -4,7 +4,7 @@ from bots.discord.client import client
from bots.discord.slash_parser import slash_parser
@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="amount", default="1", 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 excr(ctx: discord.ApplicationContext, amount: float, base: str, target: str):