update slash commands
This commit is contained in:
parent
00880f05a0
commit
a09a4a79e8
4 changed files with 14 additions and 6 deletions
|
@ -1,12 +1,20 @@
|
||||||
|
import colorsys
|
||||||
import discord
|
import discord
|
||||||
|
import random
|
||||||
|
|
||||||
from bots.discord.client import client
|
from bots.discord.client import client
|
||||||
from bots.discord.slash_parser import slash_parser
|
from bots.discord.slash_parser import slash_parser
|
||||||
|
|
||||||
|
|
||||||
async def auto_complete(ctx: discord.AutocompleteContext):
|
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"]:
|
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.")
|
@client.slash_command(name="color", description="Get color information.")
|
||||||
|
|
|
@ -23,8 +23,8 @@ async def auto_get_lang(ctx: discord.AutocompleteContext):
|
||||||
|
|
||||||
|
|
||||||
@client.slash_command(name="locale", 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.", autocomplete=auto_get_lang)
|
@discord.option(name="lang", description="Supported language codes.", autocomplete=auto_get_lang)
|
||||||
async def locale(ctx: discord.ApplicationContext, lang: str):
|
async def locale(ctx: discord.ApplicationContext, lang: str=None):
|
||||||
await slash_parser(ctx, lang)
|
await slash_parser(ctx, lang)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ dice = client.create_group("dice", "Random dice.")
|
||||||
|
|
||||||
@dice.command(name="roll", 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="dices", autocomplete=auto_complete, description="Dice expression.")
|
||||||
@discord.option(name="dc", default="", description="Difficulty class.")
|
@discord.option(name="dc", description="Difficulty class.")
|
||||||
async def roll(ctx: discord.ApplicationContext, dices: str, dc: str):
|
async def roll(ctx: discord.ApplicationContext, dices: str, dc: str=None):
|
||||||
await slash_parser(ctx, f'{dices} {dc}')
|
await slash_parser(ctx, f'{dices} {dc}')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ from bots.discord.client import client
|
||||||
from bots.discord.slash_parser import slash_parser
|
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.")
|
@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="base", description="The base currency unit.")
|
||||||
@discord.option(name="target", description="The target currency unit.")
|
@discord.option(name="target", description="The target currency unit.")
|
||||||
async def excr(ctx: discord.ApplicationContext, amount: float, base: str, target: str):
|
async def excr(ctx: discord.ApplicationContext, amount: float, base: str, target: str):
|
||||||
|
|
Reference in a new issue