diff --git a/commands/message/fun/emojimix.js b/commands/message/fun/emojimix.js deleted file mode 100644 index dc49636..0000000 --- a/commands/message/fun/emojimix.js +++ /dev/null @@ -1,65 +0,0 @@ -const { Constants } = require("detritus-client"); -const Permissions = Constants.Permissions; - -const { createEmbed } = require('../../../labscore/utils/embed') -const { editOrReply } = require('../../../labscore/utils/message') - -const { emojiKitchen } = require('../../../labscore/api') - -const onlyEmoji = require('emoji-aware').onlyEmoji; - -module.exports = { - label: "emoji", - name: "emoji", - aliases: ["em"], - metadata: { - description: 'mix two emoji', - examples: ['emoji 🐱🍞'], - category: 'fun', - usage: 'emoji ' - }, - ratelimit: { - type: 'guild', - limit: 1, - duration: 2000 - }, - permissionsClient: [Permissions.EMBED_LINKS], - run: async (context, args) => { - await context.triggerTyping(); - - const emojis = onlyEmoji(args.emoji) - - if(emojis.length <= 1) return editOrReply(context, createEmbed("warning", context, "You need at least two emoji to mix.")) - - try{ - let em = await emojiKitchen(emojis) - if(!em.body.results[0]){ - try{ - await emojiKitchen([emojis[0]]) - }catch(e){ - return editOrReply(context, createEmbed("error", context, `Invalid Emoji (${emojis[0]})`)) - } - try{ - await emojiKitchen([emojis[1]]) - }catch(e){ - return editOrReply(context, createEmbed("error", context, `Invalid Emoji (${emojis[1]})`)) - } - return editOrReply(context, createEmbed("error", context, "Combination not supported")) - } - return editOrReply(context, createEmbed("image", context, { url: em.body.results[0].url })) - - }catch(e){ - console.log(e) - return context.editOrReply({ - embed: { - author: { - iconUrl: context.message.author.avatarUrl, - name: `${context.message.author.username}#${context.message.author.discriminator}` - }, - color: Colors.error, - description: `${Icons.error} You need two emoji to mix.`, - } - }) - } - } -}; \ No newline at end of file diff --git a/commands/message/utils/emoji.js b/commands/message/utils/emoji.js new file mode 100644 index 0000000..42f2166 --- /dev/null +++ b/commands/message/utils/emoji.js @@ -0,0 +1,133 @@ +const { Constants, Utils } = require("detritus-client"); +const superagent = require('superagent'); +const { emojipedia, emojiKitchen } = require("../../../labscore/api"); + +const { Static } = require("../../../labscore/api/endpoints"); +const { SUPPORTED_EMOJI_PLATFORMS, EMOJI_PLATFORM_ALIASES } = require("../../../labscore/constants"); +const { createEmbed } = require("../../../labscore/utils/embed"); +const { editOrReply } = require("../../../labscore/utils/message"); +const { STATICS } = require("../../../labscore/utils/statics"); + +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: "emoji", + aliases: ['e', 'emote', 'enlarge', 'em', 'emojimix'], + metadata: { + description: 'Enlarge Emoji.', + examples: ['enlarge 😀', 'emojimix 🐱 🍞'], + category: 'utils', + usage: '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.") + ]}) + } + + // Emoji Mixing + if(emoji.length >= 2){ + try{ + let em = await emojiKitchen(emoji) + if(!em.body.results[0]){ + try{ + await emojiKitchen([emoji[0]]) + }catch(e){ + return editOrReply(context, createEmbed("error", context, `Invalid Emoji (${emoji[0]})`)) + } + try{ + await emojiKitchen([emoji[1]]) + }catch(e){ + return editOrReply(context, createEmbed("error", context, `Invalid Emoji (${emoji[1]})`)) + } + return editOrReply(context, createEmbed("error", context, "Combination not supported")) + } + return editOrReply(context, createEmbed("image", context, { url: em.body.results[0].url })) + + }catch(e){ + console.log(e) + return context.editOrReply({ + embed: { + author: { + iconUrl: context.message.author.avatarUrl, + name: `${context.message.author.username}#${context.message.author.discriminator}` + }, + color: Colors.error, + description: `${Icons.error} You need two emoji to mix.`, + } + }) + } + } + + // Regular Emoji Handling + if(!SUPPORTED_EMOJI_PLATFORMS.includes(args.type.toLowerCase())){ + if(!EMOJI_PLATFORM_ALIASES[args.type.toLowerCase()]) return await editOrReply(context, createEmbed("warning", context, "Invalid emoji type")) + args.type = EMOJI_PLATFORM_ALIASES[args.type.toLowerCase()] + } + if(emoji.length == 0) return await editOrReply(context, createEmbed("warning", context, "You need to specify an emoji to enlarge")) + let emojipediaResult = await emojipedia(context, emoji[0]) + emojipediaResult = emojipediaResult.response.body + if(!emojipediaResult.data.vendor_images[args.type]) return await editOrReply(context, createEmbed("error", context, "No image of specified emoji for the requested type")) + + emojiUrl = emojipediaResult.data.vendor_images[args.type] + + return editOrReply(context, {embeds:[ + createEmbed("default", context, { + description: `${emojipediaResult.data.emoji} • **${emojipediaResult.data.name}**`, + image: { + url: emojiUrl + }, + footer: { + iconUrl: STATICS.emojipedia, + text: `Emojipedia • ${context.application.name}` + } + }) + ]}) + + } + } +}; \ No newline at end of file diff --git a/commands/message/utils/enlarge.js b/commands/message/utils/enlarge.js deleted file mode 100644 index b325b65..0000000 --- a/commands/message/utils/enlarge.js +++ /dev/null @@ -1,113 +0,0 @@ -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: 'utils', - usage: 'enlarge ' - }, - args: [ - {name: 'type', default: 'twitter'} - ], - run: async (context, args) => { - 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', '') - } - let emojiUrl; - switch(args.type.toUpperCase()){ - case "FLUENT": - emojiUrl = `https://raw.githubusercontent.com/justsomederpystuff/fluent-emoji/main/emoji/${targetEmoji}.png` - break; - case "APPLE": - emojiUrl = `https://raw.githubusercontent.com/iamcal/emoji-data/master/img-apple-160/${targetEmoji}.png` - break; - default: - emojiUrl = Static.HOST + Static[args.type.toUpperCase()](targetEmoji) - break; - } - - 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 - } - }) - ]}) - } - } - } -}; \ No newline at end of file diff --git a/labscore/api/endpoints.js b/labscore/api/endpoints.js index 6b5b879..f3699e1 100644 --- a/labscore/api/endpoints.js +++ b/labscore/api/endpoints.js @@ -1,7 +1,6 @@ const Hosts = Object.freeze({ prod: "https://labscore-v2.vercel.app", local: "http://localhost", - emoji: "https://derpystuff.gitlab.io/webstorage3/container/", statics: "https://derpystuff.gitlab.io/webstorage4/v2/" }) @@ -45,24 +44,12 @@ const Api = Object.freeze({ TTS_TIKTOK: '/tts/tiktok', TTS_VOICEFORGE: '/tts/voiceforge', + UTILS_EMOJIPEDIA: '/utils/emojipedia', UTILS_INFERKIT: '/utils/inferkit', UTILS_SCREENSHOT: '/utils/screenshot', }) -const Static = Object.freeze({ - HOST: Hosts.emoji, - - TWITTER: (codepoint) => { return `twemoji-JedKxRr7RNYrgV9Sauy8EGAu/${codepoint}.png` }, - FLUENT: (codepoint) => { return `` }, - APPLE: (codepoint) => { return `` }, - 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 = { Api, - Static, Hosts } \ No newline at end of file diff --git a/labscore/api/index.js b/labscore/api/index.js index 145a7e8..099f704 100644 --- a/labscore/api/index.js +++ b/labscore/api/index.js @@ -250,6 +250,12 @@ module.exports.voiceforge = async function(context, text, voice){ }) } +module.exports.emojipedia = async function(context, emoji){ + return await request(Api.UTILS_EMOJIPEDIA, "GET", {}, { + emoji: emoji + }) +} + module.exports.inferkit = async function(context, input){ return await request(Api.UTILS_INFERKIT, "GET", {}, { input: input @@ -263,10 +269,6 @@ module.exports.screenshot = async function(context, url, nsfw){ }) } -module.exports.emojiTwitter = async function(codepoint){ - return Static.HOST + Static.TWITTER(codepoint) -} - module.exports.emojiKitchen = async function(emoji){ return await superagent.get("https://tenor.googleapis.com/v2/featured").query({ key: process.env.GOOGLE_TENOR_KEY, diff --git a/labscore/constants.js b/labscore/constants.js index f99cc83..9d6ca9d 100644 --- a/labscore/constants.js +++ b/labscore/constants.js @@ -558,4 +558,31 @@ module.exports.TRANSLATE_LANGUAGES = Object.freeze({ 'yi': 'Yiddish', 'yo': 'Yoruba', 'zu': 'Zulu' -}) \ No newline at end of file +}) + +module.exports.SUPPORTED_EMOJI_PLATFORMS = [ + "apple", + "google", + "samsung", + "joypixels", + "microsoft", + "facebook", + "twitter", + "whatsapp", + "lg", + "mozilla", + "htc", + "emojidex", + "messenger", + "openmoji", + "skype", + "sony", + "noto-emoji", + "toss-face", + "microsoft-teams" +] + +module.exports.EMOJI_PLATFORM_ALIASES = { + "fluent": "microsoft-teams", + "twemoji": "twitter" +} \ No newline at end of file diff --git a/labscore/utils/statics.js b/labscore/utils/statics.js index 36c575f..f755185 100644 --- a/labscore/utils/statics.js +++ b/labscore/utils/statics.js @@ -8,6 +8,10 @@ const Statics = Object.freeze({ file: "brands/bing.png", revision: 0 }, + emojipedia: { + file: "brands/emojipedia.png", + revision: 1 + }, genius: { file: "brands/genius.png", revision: 0 @@ -81,6 +85,7 @@ module.exports.STATICS = Object.freeze({ bing: staticAsset(Statics.brands.bing), genius: staticAsset(Statics.brands.genius), google: staticAsset(Statics.brands.google), + emojipedia: staticAsset(Statics.brands.emojipedia), inferkit: staticAsset(Statics.brands.inferkit), makesweet: staticAsset(Statics.brands.makesweet), photofunia: staticAsset(Statics.brands.photofunia),