mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
latex command
This commit is contained in:
parent
e1743b7a71
commit
e946bf0c24
1 changed files with 51 additions and 0 deletions
51
commands/message/utils/latex.js
Normal file
51
commands/message/utils/latex.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
const { paginator } = require("../../../labscore/client");
|
||||
const { createEmbed, page, formatPaginationEmbeds } = require("../../../labscore/utils/embed");
|
||||
const { codeblock } = require("../../../labscore/utils/markdown");
|
||||
const { editOrReply } = require("../../../labscore/utils/message");
|
||||
|
||||
const { Permissions } = require("detritus-client/lib/constants");
|
||||
|
||||
const TEX_REGEX = /(\$.*?\$)/g
|
||||
const TEX_URL = `https://latex.codecogs.com/png.image?\\inline&space;\\huge&space;\\dpi{200}&space;\\color{white}`
|
||||
|
||||
module.exports = {
|
||||
name: 'latex',
|
||||
aliases: ['tex'],
|
||||
label: 'content',
|
||||
metadata: {
|
||||
description: 'Renders LaTeX expressions.\nReply to a message to render TeX from it.',
|
||||
description_short: 'LaTeX preview.',
|
||||
category: 'utils',
|
||||
usage: 'latex <expression>'
|
||||
},
|
||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.READ_MESSAGE_HISTORY, Permissions.USE_EXTERNAL_EMOJIS],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
|
||||
let content = args.content
|
||||
if (context.message.messageReference) {
|
||||
let msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
|
||||
if(msg.content && msg.content.length) content = msg.content
|
||||
if(msg.embeds?.length) for(const e of msg.embeds) if(e[1].description?.length) { content += '\n' + e[1].description; break; }
|
||||
}
|
||||
|
||||
let texBlocks = content.match(TEX_REGEX);
|
||||
|
||||
let pages = [];
|
||||
for(const t of texBlocks){
|
||||
let description;
|
||||
if(args.content.includes('-i')) description = codeblock("tex", [t])
|
||||
pages.push(page(createEmbed("default", context, {
|
||||
description,
|
||||
image: {
|
||||
url: TEX_URL + encodeURIComponent(t.substr(1,t.length - 2))
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
return await paginator.createPaginator({
|
||||
context,
|
||||
pages: formatPaginationEmbeds(pages)
|
||||
});
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue