mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 21:53:07 -04:00
emojis baby
This commit is contained in:
parent
9acb1d5ec5
commit
83e13c81ad
7 changed files with 173 additions and 197 deletions
|
@ -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 <emoji to mix>'
|
||||
},
|
||||
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.`,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
133
commands/message/utils/emoji.js
Normal file
133
commands/message/utils/emoji.js
Normal file
|
@ -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 <emoji> [<emoji to mix>]'
|
||||
},
|
||||
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}`
|
||||
}
|
||||
})
|
||||
]})
|
||||
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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 <emoji>'
|
||||
},
|
||||
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
|
||||
}
|
||||
})
|
||||
]})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -559,3 +559,30 @@ module.exports.TRANSLATE_LANGUAGES = Object.freeze({
|
|||
'yo': 'Yoruba',
|
||||
'zu': 'Zulu'
|
||||
})
|
||||
|
||||
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"
|
||||
}
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue