mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 13:43:06 -04:00
172 lines
No EOL
5.7 KiB
JavaScript
172 lines
No EOL
5.7 KiB
JavaScript
const { emojipedia } = require("#api");
|
|
const { PERMISSION_GROUPS } = require("#constants");
|
|
|
|
const { createEmbed } = require("#utils/embed");
|
|
const { pill, smallIconPill } = require("#utils/markdown");
|
|
const { editOrReply } = require("#utils/message");
|
|
const { STATICS, STATIC_ASSETS } = require("#utils/statics");
|
|
|
|
const { InteractionCallbackTypes, MessageComponentButtonStyles } = require("detritus-client/lib/constants");
|
|
const { Components } = require("detritus-client/lib/utils");
|
|
|
|
const onlyEmoji = require('emoji-aware').onlyEmoji;
|
|
|
|
function toCodePoint(unicodeSurrogates, sep) {
|
|
var
|
|
r = [],
|
|
c = 0,
|
|
p = 0,
|
|
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(sep || '-');
|
|
}
|
|
|
|
module.exports = {
|
|
label: "emoji",
|
|
name: "emojipedia",
|
|
aliases: ["emojiinfo", "ei"],
|
|
metadata: {
|
|
description: `${smallIconPill("reply", "Supports Replies")}\n\nDisplays more detailed information about emoji. Only supports unicode emoji.`,
|
|
description_short: 'Detailed information about an emoji.',
|
|
examples: ['ei 😀'],
|
|
category: 'utils',
|
|
usage: 'emojipedia <emoji>',
|
|
slashCommand: "emojipedia"
|
|
},
|
|
permissionsClient: [...PERMISSION_GROUPS.baseline],
|
|
run: async (context, args) => {
|
|
await context.triggerTyping()
|
|
let msg = context.message;
|
|
if (context.message.messageReference) {
|
|
msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
|
|
args.emoji = msg.content
|
|
}
|
|
|
|
const emoji = onlyEmoji(args.emoji)
|
|
if(!emoji){
|
|
return editOrReply(context,
|
|
createEmbed("warning", context, "No emoji found.")
|
|
)
|
|
}
|
|
|
|
// Regular Emoji Handling
|
|
if(emoji.length == 0) return await editOrReply(context, createEmbed("warning", context, "You need to specify an emoji to enlarge."))
|
|
|
|
let res;
|
|
try{
|
|
res = await emojipedia(context, emoji[0])
|
|
res = res.response.body
|
|
}catch(e){
|
|
return await editOrReply(context, createEmbed("error", context, `No emoji data available for ${emoji[0]}.`))
|
|
}
|
|
|
|
|
|
const components = new Components({
|
|
timeout: 100000,
|
|
run: async (ctx) => {
|
|
if (ctx.userId !== context.userId) return await ctx.respond(InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE);
|
|
|
|
let newView = await emojipedia(context, ctx.data.customId)
|
|
newView = newView.response.body
|
|
|
|
let newIcon;
|
|
if(newView.data.platforms["twitter"]) newIcon = newView.data.platforms["twitter"].images[0].src;
|
|
if(newView.data.platforms["discord"]) newIcon = newView.data.platforms["discord"].images[0].src;
|
|
if(!newIcon && Object.values(newView.data.platforms).length >= 1) newIcon = Object.values(newView.data.platforms)[0].images[0].src
|
|
|
|
currentView = createEmbed("default", context, {
|
|
author: {
|
|
// TODO: emoji_placeholder_small
|
|
iconUrl: newIcon || STATIC_ASSETS.emoji_placeholder_large,
|
|
name: `${newView.data.name} `,
|
|
url: newView.data.link
|
|
},
|
|
description: newView.data.codes.map((c)=>pill(c)).join(' ') + "\n\n" + newView.data.metadata.description,
|
|
image: {
|
|
url: newIcon || STATIC_ASSETS.emoji_placeholder
|
|
},
|
|
footer: {
|
|
iconUrl: STATICS.emojipedia,
|
|
text: `Emojipedia • ${context.application.name}`
|
|
}
|
|
})
|
|
|
|
if(newView.data.metadata.version?.emoji){
|
|
currentView.author.name += `• Emoji ${newView.data.metadata.version.emoji}`
|
|
}
|
|
|
|
components.clear();
|
|
if(newView.data.metadata.similar) for(const e of newView.data.metadata.similar.splice(0, 5)){
|
|
components.addButton({
|
|
customId: e,
|
|
emoji: e,
|
|
style: MessageComponentButtonStyles.SECONDARY
|
|
})
|
|
}
|
|
|
|
if(!newView.data.metadata.similar) return await ctx.editOrRespond({embeds: [currentView]})
|
|
|
|
await ctx.editOrRespond({embeds: [currentView], components})
|
|
}
|
|
})
|
|
|
|
if(res.data.metadata.similar) for(const e of res.data.metadata.similar.splice(0, 5)){
|
|
components.addButton({
|
|
customId: e,
|
|
emoji: e,
|
|
style: MessageComponentButtonStyles.SECONDARY
|
|
})
|
|
}
|
|
|
|
setTimeout(()=>{
|
|
editOrReply(context, {
|
|
embeds:[currentView],
|
|
components:[]
|
|
})
|
|
}, 100000)
|
|
|
|
// Use the high-res emojipedia icon, if available
|
|
let ico;
|
|
if(res.data.platforms["twitter"]) ico = res.data.platforms["twitter"].images[0].src
|
|
if(res.data.platforms["discord"]) ico = res.data.platforms["discord"].images[0].src
|
|
if(!ico && Object.values(res.data.platforms).length >= 1) ico = Object.values(res.data.platforms)[0].images[0].src
|
|
|
|
currentView = createEmbed("default", context, {
|
|
author: {
|
|
// TODO: emoji_placeholder_small
|
|
iconUrl: ico || STATIC_ASSETS.emoji_placeholder_large,
|
|
name: `${res.data.name} `,
|
|
url: res.data.link
|
|
},
|
|
description: res.data.codes.map((c)=>pill(c)).join(' ') + "\n\n" + res.data.metadata.description,
|
|
image: {
|
|
url: ico || STATIC_ASSETS.emoji_placeholder
|
|
},
|
|
footer: {
|
|
iconUrl: STATICS.emojipedia,
|
|
text: `Emojipedia • ${context.application.name}`
|
|
}
|
|
})
|
|
|
|
if(res.data.metadata.version?.emoji){
|
|
currentView.author.name += `• Emoji ${res.data.metadata.version.emoji}`
|
|
}
|
|
|
|
if(!res.data.metadata.similar) return await editOrReply(context, currentView)
|
|
|
|
return editOrReply(context, {
|
|
embeds: [currentView],
|
|
components
|
|
})
|
|
}
|
|
}; |