2020-11-01 22:39:15 +01:00
|
|
|
from urllib.parse import urlencode
|
|
|
|
|
|
|
|
from discord.ext import commands
|
2021-02-04 10:08:09 +01:00
|
|
|
from discord_slash import cog_ext, SlashContext, SlashCommandOptionType
|
|
|
|
from discord_slash.utils import manage_commands
|
2020-11-01 22:39:15 +01:00
|
|
|
|
2021-02-04 10:08:09 +01:00
|
|
|
from administrator import slash
|
2020-11-05 15:02:15 +01:00
|
|
|
from administrator.check import is_enabled
|
2020-11-01 22:39:15 +01:00
|
|
|
from administrator.logger import logger
|
|
|
|
|
|
|
|
|
|
|
|
extension_name = "TeX"
|
|
|
|
|
|
|
|
|
|
|
|
class TeX(commands.Cog):
|
|
|
|
def __init__(self, bot: commands.Bot):
|
|
|
|
self.bot = bot
|
|
|
|
self.polls = {}
|
2021-02-04 10:08:09 +01:00
|
|
|
slash.get_cog_commands(self)
|
2020-11-01 22:39:15 +01:00
|
|
|
|
|
|
|
def description(self):
|
|
|
|
return "Render TeX formula"
|
|
|
|
|
2021-02-04 10:08:09 +01:00
|
|
|
@cog_ext.cog_slash(name="tex", description="Render a TeX formula", options=[
|
|
|
|
manage_commands.create_option("formula", "The TeX formula", SlashCommandOptionType.STRING, True)])
|
2020-11-05 15:02:15 +01:00
|
|
|
@is_enabled()
|
2021-02-04 10:08:09 +01:00
|
|
|
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})}")
|
2020-11-01 22:39:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
def setup(bot):
|
|
|
|
logger.info(f"Loading...")
|
|
|
|
try:
|
|
|
|
bot.add_cog(TeX(bot))
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"Error loading: {e}")
|
|
|
|
else:
|
|
|
|
logger.info(f"Load successful")
|
|
|
|
|
|
|
|
|
|
|
|
def teardown(bot):
|
|
|
|
logger.info(f"Unloading...")
|
|
|
|
try:
|
|
|
|
bot.remove_cog("TeX")
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"Error unloading: {e}")
|
|
|
|
else:
|
|
|
|
logger.info(f"Unload successful")
|