1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
Administrator-py/extensions/tex.py

49 lines
1.3 KiB
Python
Raw Permalink Normal View History

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
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)])
@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")