[cmd] enlarge

This commit is contained in:
derpystuff 2022-05-25 21:53:03 +02:00
parent bf7378a1f7
commit c02eda1b2a
3 changed files with 113 additions and 3 deletions

View file

@ -0,0 +1,105 @@
const { Constants, Utils } = require("detritus-client");
const superagent = require('superagent');
const { Static } = require("../../../labscore/api/endpoints");
const { createEmbed } = require("../../../labscore/utils/embed");
const { editOrReply } = require("../../../labscore/utils/message");
const onlyEmoji = require('emoji-aware').onlyEmoji;
function toCodePoint(unicodeSurrogates) {
const r = [];
let c = 0;
let p = 0;
let i = 0;
while (i < unicodeSurrogates.length) {
c = unicodeSurrogates.charCodeAt(i++);
if (p) {
r.push((0x10000 + ((p - 0xD800) << 10) + (c - 0xDC00)).toString(16));
p = 0;
} else if (0xD800 <= c && c <= 0xDBFF) {
p = c;
} else {
r.push(c.toString(16));
}
}
return r.join('-');
}
module.exports = {
label: "emoji",
name: "enlarge",
aliases: ['e', 'emote'],
metadata: {
description: 'Enlarge Emoji.',
examples: ['enlarge 😀'],
category: 'util',
usage: 'enlarge <emoji>'
},
args: [
{name: 'type', default: 'twitter'}
],
run: async (context, args) => {
await context.triggerTyping();
const { matches } = Utils.regex(
Constants.DiscordRegexNames.EMOJI,
args.emoji
);
embeds = []
if (matches.length) {
let form = '.png'
if(matches[0].animated) form = '.gif'
return editOrReply(context, {embeds:[
createEmbed("default", context, {
description: `**${matches[0].name}**`,
image: {
url: `https://cdn.discordapp.com/emojis/${matches[0].id}${form}`
}
})
]})
} else {
const emoji = onlyEmoji(args.emoji)
if(!emoji){
return editOrReply(context, {embeds:[
createEmbed("warning", context, "No emoji found.")
]})
} else {
if(!Static[args.type.toUpperCase()]){
return editOrReply(context, {embeds:[
createEmbed("warning", context, "Invalid type.")
]})
}
const emojiCodepoint = emoji.map((e) => toCodePoint(e));
if(!emojiCodepoint.length){
return editOrReply(context, {embeds:[
createEmbed("warning", context, "No emoji found.")
]})
}
targetEmoji = emojiCodepoint[0]
if(args.type.toUpperCase() == "TWITTER"){
targetEmoji = emojiCodepoint[0].replace('-fe0f', '')
}
if(args.type.toUpperCase() == "FLUENT"){
targetEmoji = emojiCodepoint[0].replace('-fe0f', '')
}
let emojiUrl = Static.HOST + Static[args.type.toUpperCase()](targetEmoji)
try{
let e = await superagent.get(emojiUrl)
}catch(e){
return editOrReply(context, {embeds:[
createEmbed("error", context, "No image for provided emoji.")
]})
}
return editOrReply(context, {embeds:[
createEmbed("default", context, {
image: {
url: emojiUrl
}
})
]})
}
}
}
};

View file

@ -32,9 +32,13 @@ const Api = Object.freeze({
const Static = Object.freeze({ const Static = Object.freeze({
HOST: Hosts.emoji, HOST: Hosts.emoji,
TWITTER: (codepoint) => { TWITTER: (codepoint) => { return `twemoji-JedKxRr7RNYrgV9Sauy8EGAu/${codepoint}.png` },
return `twemoji-JedKxRr7RNYrgV9Sauy8EGAu/${codepoint}.png` FLUENT: (codepoint) => { return `fluent-6vbne6euaxy2y9f98iub2xtr/${codepoint}.png` },
} //APPLE: (codepoint) => { return `twemoji-JedKxRr7RNYrgV9Sauy8EGAu/${codepoint}.png` }, // TODO: host these in-house
MICROSOFT: (codepoint) => { return `microsoft-ZzRAzYE6LgxVTrQ5rvL7nLyC/${codepoint}.png` },
EMOJIONE: (codepoint) => { return `emojione-XghVAypW8jttjFL2tQFb2z7n/${codepoint}.png` },
GOOGLE: (codepoint) => { return `google-tqzSNjYw8MVMYfSBLTLTFgmw/${codepoint}.png` },
BLOBS: (codepoint) => { return `blobs-KpDmEXYD3VTC2VT6PSQAc99y/${codepoint}.png` }
}) })
module.exports = { module.exports = {

View file

@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"detritus-client": "^0.17.0-beta.12", "detritus-client": "^0.17.0-beta.12",
"dotenv": "^16.0.1", "dotenv": "^16.0.1",
"emoji-aware": "^3.1.0",
"express": "^4.17.1", "express": "^4.17.1",
"superagent": "^7.1.1" "superagent": "^7.1.1"
} }