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 import Embed
|
||||||
from discord.ext import commands
|
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.check import is_enabled
|
||||||
from administrator.logger import logger
|
from administrator.logger import logger
|
||||||
|
|
||||||
|
@ -14,26 +17,16 @@ class TeX(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.polls = {}
|
self.polls = {}
|
||||||
|
slash.get_cog_commands(self)
|
||||||
|
|
||||||
def description(self):
|
def description(self):
|
||||||
return "Render TeX formula"
|
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()
|
@is_enabled()
|
||||||
async def tex(self, ctx: commands.Context):
|
async def tex(self, ctx: SlashContext, formula: str):
|
||||||
if ctx.message.content.count("`") == 2:
|
await ctx.send(content=f"https://chart.apis.google.com/chart?cht=tx&chs=40&{urlencode({'chl': formula})}")
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
|
Reference in a new issue