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

57 lines
1.6 KiB
Python
Raw Normal View History

2020-11-01 22:39:15 +01:00
from urllib.parse import urlencode
from discord import Embed
from discord.ext import commands
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 = {}
def description(self):
return "Render TeX formula"
@commands.group("tex", pass_context=True)
@is_enabled()
2020-11-01 22:39:15 +01:00
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)
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")