Switch tex to slash commands
This commit is contained in:
parent
dfd33875b6
commit
deb2d9aa34
1 changed files with 8 additions and 15 deletions
|
@ -2,7 +2,10 @@ from urllib.parse import urlencode
|
|||
|
||||
from discord import Embed
|
||||
from discord.ext import commands
|
||||
from discord_slash import cog_ext, SlashContext, SlashCommandOptionType
|
||||
from discord_slash.utils import manage_commands
|
||||
|
||||
from administrator import slash
|
||||
from administrator.check import is_enabled
|
||||
from administrator.logger import logger
|
||||
|
||||
|
@ -14,26 +17,16 @@ class TeX(commands.Cog):
|
|||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
self.polls = {}
|
||||
slash.get_cog_commands(self)
|
||||
|
||||
def description(self):
|
||||
return "Render TeX formula"
|
||||
|
||||
@commands.group("tex", pass_context=True)
|
||||
@cog_ext.cog_slash(name="tex", description="Render a TeX formula", options=[
|
||||
manage_commands.create_option("formula", "The TeX formula", SlashCommandOptionType.STRING, True)])
|
||||
@is_enabled()
|
||||
async def tex(self, ctx: commands.Context):
|
||||
if ctx.message.content.count("`") == 2:
|
||||
start = ctx.message.content.find("`")
|
||||
end = ctx.message.content.find("`", start+1)
|
||||
command = ctx.message.content[start+1:end]
|
||||
await ctx.send(f"https://chart.apis.google.com/chart?cht=tx&chs=40&{urlencode({'chl': command})}")
|
||||
elif ctx.invoked_subcommand is None:
|
||||
await ctx.invoke(self.tex_help)
|
||||
|
||||
@tex.group("help", pass_context=True)
|
||||
async def tex_help(self, ctx: commands.Context):
|
||||
embed = Embed(title="TeX help")
|
||||
embed.add_field(name="tex \`formula\`", value="Render a TeX formula", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
async def tex(self, ctx: SlashContext, formula: str):
|
||||
await ctx.send(content=f"https://chart.apis.google.com/chart?cht=tx&chs=40&{urlencode({'chl': formula})}")
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
|
Reference in a new issue