mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-10 15:13:04 -04:00
add emoji platform vendor to emoji command
This commit is contained in:
parent
6217210907
commit
939fef9b33
2 changed files with 137 additions and 56 deletions
|
@ -49,12 +49,6 @@ module.exports = {
|
||||||
description: 'Emoji to enlarge. Use two built-in emoji to mix them.',
|
description: 'Emoji to enlarge. Use two built-in emoji to mix them.',
|
||||||
type: ApplicationCommandOptionTypes.TEXT,
|
type: ApplicationCommandOptionTypes.TEXT,
|
||||||
required: true
|
required: true
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'type',
|
|
||||||
description: '(For built-in emoji) Emoji platform (twitter, apple, etc).',
|
|
||||||
type: ApplicationCommandOptionTypes.TEXT,
|
|
||||||
required: false
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
run: async (context, args) => {
|
run: async (context, args) => {
|
||||||
|
@ -114,11 +108,6 @@ module.exports = {
|
||||||
// Regular Emoji Handling
|
// Regular Emoji Handling
|
||||||
if(emoji.length == 0) return await editOrReply(context, createEmbed("warning", context, "You need to specify an emoji to enlarge."))
|
if(emoji.length == 0) return await editOrReply(context, createEmbed("warning", context, "You need to specify an emoji to enlarge."))
|
||||||
|
|
||||||
if(!args.type) args.type = "twitter";
|
|
||||||
args.type = args.type.toLowerCase()
|
|
||||||
|
|
||||||
if(!EMOJIPEDIA_PLATFORM_TYPES.includes(args.type) && EMOJIPEDIA_PLATFORM_TYPE_ALIASES[args.type]) args.type = EMOJIPEDIA_PLATFORM_TYPE_ALIASES[args.type]
|
|
||||||
|
|
||||||
let res;
|
let res;
|
||||||
try{
|
try{
|
||||||
res = await emojipedia(context, emoji[0])
|
res = await emojipedia(context, emoji[0])
|
||||||
|
@ -128,30 +117,22 @@ module.exports = {
|
||||||
return await editOrReply(context, createEmbed("error", context, `No emoji data available for ${emoji[0]}.`))
|
return await editOrReply(context, createEmbed("error", context, `No emoji data available for ${emoji[0]}.`))
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!res.data.platforms[args.type]){
|
|
||||||
let embed = createEmbed("error", context, "No emoji image available for platform '" + args.type + "'.")
|
|
||||||
embed.footer = {
|
|
||||||
text: "Available platforms: " + Object.keys(res.data.platforms).join(', ').substr(0, 2000)
|
|
||||||
}
|
|
||||||
return await editOrReply(context, embed)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the high-res emojipedia icon, if available
|
// Use the high-res emojipedia icon, if available
|
||||||
let ico = `https://abs.twimg.com/emoji/v2/72x72/${toCodePoint(emoji[0])}.png`
|
let ico = `https://abs.twimg.com/emoji/v2/72x72/${toCodePoint(emoji[0])}.png`
|
||||||
if(!res.data.platforms["twitter"]) ico = res.data.platforms[args.type].images[0].src
|
ico = res.data.platforms["twitter"].images[0].src
|
||||||
else ico = res.data.platforms["twitter"].images[0].src
|
|
||||||
|
|
||||||
const platformEmoji = res.data.platforms[args.type]
|
const DEFAULT_PLATFORM = "twitter"
|
||||||
|
let platformEmoji = res.data.platforms["twitter"]
|
||||||
|
|
||||||
if(platformEmoji.images.length == 1) return editOrReply(context, createEmbed("default", context, {
|
if(platformEmoji.images.length == 1) return editOrReply(context, createEmbed("default", context, {
|
||||||
author: {
|
author: {
|
||||||
iconUrl: ico,
|
iconUrl: ico,
|
||||||
name: `${res.data.name} • ${res.data.platforms[args.type].images[0].version}`,
|
name: `${res.data.name} • ${res.data.platforms[DEFAULT_PLATFORM].images[0].version}`,
|
||||||
url: res.data.link
|
url: res.data.link
|
||||||
},
|
},
|
||||||
description: res.data.codes.map((c)=>pill(c)).join(' '),
|
description: res.data.codes.map((c)=>pill(c)).join(' '),
|
||||||
image: {
|
image: {
|
||||||
url: res.data.platforms[args.type].images[0].src
|
url: res.data.platforms[DEFAULT_PLATFORM].images[0].src
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
iconUrl: STATICS.emojipedia,
|
iconUrl: STATICS.emojipedia,
|
||||||
|
@ -159,21 +140,54 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
let currentView ;
|
let currentView;
|
||||||
|
let currentPlatform = "twitter";
|
||||||
|
let currentRevision = "";
|
||||||
|
|
||||||
const components = new Components({
|
const components = new Components({
|
||||||
timeout: 100000,
|
timeout: 100000,
|
||||||
run: async (ctx) => {
|
run: async (ctx) => {
|
||||||
if (ctx.userId !== context.userId) return await ctx.respond(InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE);
|
if (ctx.userId !== context.userId) return await ctx.respond(InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE);
|
||||||
|
|
||||||
const emojiAsset = platformEmoji.images.filter((p)=>{
|
|
||||||
return p.id == ctx.data.values[0]
|
|
||||||
})
|
|
||||||
|
|
||||||
// this sucks but works, ensures the newly selected option stays selected
|
// this sucks but works, ensures the newly selected option stays selected
|
||||||
for (let i = 0; i < components.components[0].components[0].options.length; i++) {
|
// update 25/03/24 - it sucks even more now
|
||||||
components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value == ctx.data.values[0])
|
console.log(ctx.data)
|
||||||
|
|
||||||
|
|
||||||
|
if(ctx.data.customId == "emoji-type"){
|
||||||
|
currentPlatform = ctx.data.values[0];
|
||||||
|
currentRevision = res.data.platforms[currentPlatform].images[0].id
|
||||||
|
|
||||||
|
for (let i = 0; i < components.components[0].components[0].options.length; i++) {
|
||||||
|
components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value == currentPlatform)
|
||||||
|
}
|
||||||
|
|
||||||
|
let newVersionOptions = res.data.platforms[currentPlatform].images.map((r) => {
|
||||||
|
return {
|
||||||
|
label: r.version,
|
||||||
|
value: r.id,
|
||||||
|
default: (r.id == res.data.platforms[currentPlatform].images[0].id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
components.components[1].components[0].options = newVersionOptions
|
||||||
|
|
||||||
|
console.log("new type is " + currentPlatform + " with version " + currentRevision)
|
||||||
|
} else if(ctx.data.customId == "emoji-version"){
|
||||||
|
|
||||||
|
for (let i = 0; i < components.components[1].components[0].options.length; i++) {
|
||||||
|
components.components[1].components[0].options[i].default = (components.components[1].components[0].options[i].value == ctx.data.values[0])
|
||||||
|
}
|
||||||
|
currentRevision = ctx.data.values[0];
|
||||||
|
console.log("new version is " + currentRevision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("getting asset for " + currentPlatform + " ver " + currentRevision);
|
||||||
|
const emojiAsset = res.data.platforms[currentPlatform].images.filter((p)=>{
|
||||||
|
return p.id == currentRevision
|
||||||
|
})
|
||||||
|
console.log("got asset: " + emojiAsset)
|
||||||
|
|
||||||
currentView = createEmbed("default", context, {
|
currentView = createEmbed("default", context, {
|
||||||
author: {
|
author: {
|
||||||
iconUrl: ico,
|
iconUrl: ico,
|
||||||
|
@ -189,40 +203,53 @@ module.exports = {
|
||||||
text: `Emojipedia • ${context.application.name}`
|
text: `Emojipedia • ${context.application.name}`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log("acknowledging for plat " + currentPlatform + " and ver " + currentRevision)
|
||||||
await ctx.editOrRespond({embeds: [currentView], components})
|
await ctx.editOrRespond({embeds: [currentView], components})
|
||||||
|
console.log("acknowledged")
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let selectOptions = res.data.platforms[args.type].images.map((r) => {
|
let selectOptions = res.data.platforms[currentPlatform].images.map((r) => {
|
||||||
return {
|
return {
|
||||||
label: r.version,
|
label: r.version,
|
||||||
value: r.id,
|
value: r.id,
|
||||||
default: (r.id == res.data.platforms[args.type].images[0].id)
|
default: (r.id == res.data.platforms[DEFAULT_PLATFORM].images[0].id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
currentRevision = res.data.platforms[DEFAULT_PLATFORM].images[0].id
|
||||||
|
|
||||||
|
let selectTypeOptions = Object.keys(res.data.platforms).map((r) => {
|
||||||
|
let pl = res.data.platforms[r]
|
||||||
|
return {
|
||||||
|
label: pl.name,
|
||||||
|
value: r,
|
||||||
|
default: (r == "twitter")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
components.addSelectMenu({
|
||||||
|
placeholder: "Select platform type",
|
||||||
|
customId: "emoji-type",
|
||||||
|
options: selectTypeOptions
|
||||||
|
})
|
||||||
|
|
||||||
components.addSelectMenu({
|
components.addSelectMenu({
|
||||||
placeholder: "Select emoji revision",
|
placeholder: "Select emoji revision",
|
||||||
customId: "emoji-version",
|
customId: "emoji-version",
|
||||||
options: selectOptions
|
options: selectOptions
|
||||||
})
|
})
|
||||||
|
|
||||||
setTimeout(()=>{
|
|
||||||
editOrReply(context, {
|
|
||||||
embeds:[currentView],
|
|
||||||
components:[]
|
|
||||||
})
|
|
||||||
}, 100000)
|
|
||||||
|
|
||||||
currentView = createEmbed("default", context, {
|
currentView = createEmbed("default", context, {
|
||||||
author: {
|
author: {
|
||||||
iconUrl: ico,
|
iconUrl: ico,
|
||||||
name: `${res.data.name} • ${res.data.platforms[args.type].images[0].version}`,
|
name: `${res.data.name} • ${res.data.platforms[DEFAULT_PLATFORM].images[0].version}`,
|
||||||
url: res.data.link
|
url: res.data.link
|
||||||
},
|
},
|
||||||
description: res.data.codes.map((c)=>pill(c)).join(' '),
|
description: res.data.codes.map((c)=>pill(c)).join(' '),
|
||||||
image: {
|
image: {
|
||||||
url: res.data.platforms[args.type].images[0].src
|
url: res.data.platforms[DEFAULT_PLATFORM].images[0].src
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
iconUrl: STATICS.emojipedia,
|
iconUrl: STATICS.emojipedia,
|
||||||
|
|
|
@ -148,17 +148,18 @@ module.exports = {
|
||||||
if(!res.data.platforms["twitter"]) ico = res.data.platforms[args.type].images[0].src
|
if(!res.data.platforms["twitter"]) ico = res.data.platforms[args.type].images[0].src
|
||||||
else ico = res.data.platforms["twitter"].images[0].src
|
else ico = res.data.platforms["twitter"].images[0].src
|
||||||
|
|
||||||
const platformEmoji = res.data.platforms[args.type]
|
const DEFAULT_PLATFORM = args.type
|
||||||
|
let platformEmoji = res.data.platforms[DEFAULT_PLATFORM]
|
||||||
|
|
||||||
if(platformEmoji.images.length == 1) return editOrReply(context, createEmbed("default", context, {
|
if(platformEmoji.images.length == 1) return editOrReply(context, createEmbed("default", context, {
|
||||||
author: {
|
author: {
|
||||||
iconUrl: ico,
|
iconUrl: ico,
|
||||||
name: `${res.data.name} • ${res.data.platforms[args.type].images[0].version}`,
|
name: `${res.data.name} • ${res.data.platforms[DEFAULT_PLATFORM].images[0].version}`,
|
||||||
url: res.data.link
|
url: res.data.link
|
||||||
},
|
},
|
||||||
description: res.data.codes.map((c)=>pill(c)).join(' '),
|
description: res.data.codes.map((c)=>pill(c)).join(' '),
|
||||||
image: {
|
image: {
|
||||||
url: res.data.platforms[args.type].images[0].src
|
url: res.data.platforms[DEFAULT_PLATFORM].images[0].src
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
iconUrl: STATICS.emojipedia,
|
iconUrl: STATICS.emojipedia,
|
||||||
|
@ -166,21 +167,54 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
let currentView ;
|
let currentView;
|
||||||
|
let currentPlatform = args.type;
|
||||||
|
let currentRevision = "";
|
||||||
|
|
||||||
const components = new Components({
|
const components = new Components({
|
||||||
timeout: 100000,
|
timeout: 100000,
|
||||||
run: async (ctx) => {
|
run: async (ctx) => {
|
||||||
if (ctx.userId !== context.userId) return await ctx.respond(InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE);
|
if (ctx.userId !== context.userId) return await ctx.respond(InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE);
|
||||||
|
|
||||||
const emojiAsset = platformEmoji.images.filter((p)=>{
|
|
||||||
return p.id == ctx.data.values[0]
|
|
||||||
})
|
|
||||||
|
|
||||||
// this sucks but works, ensures the newly selected option stays selected
|
// this sucks but works, ensures the newly selected option stays selected
|
||||||
for (let i = 0; i < components.components[0].components[0].options.length; i++) {
|
// update 25/03/24 - it sucks even more now
|
||||||
components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value == ctx.data.values[0])
|
console.log(ctx.data)
|
||||||
|
|
||||||
|
|
||||||
|
if(ctx.data.customId == "emoji-type"){
|
||||||
|
currentPlatform = ctx.data.values[0];
|
||||||
|
currentRevision = res.data.platforms[currentPlatform].images[0].id
|
||||||
|
|
||||||
|
for (let i = 0; i < components.components[0].components[0].options.length; i++) {
|
||||||
|
components.components[0].components[0].options[i].default = (components.components[0].components[0].options[i].value == currentPlatform)
|
||||||
|
}
|
||||||
|
|
||||||
|
let newVersionOptions = res.data.platforms[currentPlatform].images.map((r) => {
|
||||||
|
return {
|
||||||
|
label: r.version,
|
||||||
|
value: r.id,
|
||||||
|
default: (r.id == res.data.platforms[currentPlatform].images[0].id)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
components.components[1].components[0].options = newVersionOptions
|
||||||
|
|
||||||
|
console.log("new type is " + currentPlatform + " with version " + currentRevision)
|
||||||
|
} else if(ctx.data.customId == "emoji-version"){
|
||||||
|
|
||||||
|
for (let i = 0; i < components.components[1].components[0].options.length; i++) {
|
||||||
|
components.components[1].components[0].options[i].default = (components.components[1].components[0].options[i].value == ctx.data.values[0])
|
||||||
|
}
|
||||||
|
currentRevision = ctx.data.values[0];
|
||||||
|
console.log("new version is " + currentRevision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("getting asset for " + currentPlatform + " ver " + currentRevision);
|
||||||
|
const emojiAsset = res.data.platforms[currentPlatform].images.filter((p)=>{
|
||||||
|
return p.id == currentRevision
|
||||||
|
})
|
||||||
|
console.log("got asset: " + emojiAsset)
|
||||||
|
|
||||||
currentView = createEmbed("default", context, {
|
currentView = createEmbed("default", context, {
|
||||||
author: {
|
author: {
|
||||||
iconUrl: ico,
|
iconUrl: ico,
|
||||||
|
@ -196,18 +230,38 @@ module.exports = {
|
||||||
text: `Emojipedia • ${context.application.name}`
|
text: `Emojipedia • ${context.application.name}`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log("acknowledging for plat " + currentPlatform + " and ver " + currentRevision)
|
||||||
await ctx.editOrRespond({embeds: [currentView], components})
|
await ctx.editOrRespond({embeds: [currentView], components})
|
||||||
|
console.log("acknowledged")
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let selectOptions = res.data.platforms[args.type].images.map((r) => {
|
let selectOptions = res.data.platforms[currentPlatform].images.map((r) => {
|
||||||
return {
|
return {
|
||||||
label: r.version,
|
label: r.version,
|
||||||
value: r.id,
|
value: r.id,
|
||||||
default: (r.id == res.data.platforms[args.type].images[0].id)
|
default: (r.id == res.data.platforms[DEFAULT_PLATFORM].images[0].id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
currentRevision = res.data.platforms[DEFAULT_PLATFORM].images[0].id
|
||||||
|
|
||||||
|
let selectTypeOptions = Object.keys(res.data.platforms).map((r) => {
|
||||||
|
let pl = res.data.platforms[r]
|
||||||
|
return {
|
||||||
|
label: pl.name,
|
||||||
|
value: r,
|
||||||
|
default: (r == DEFAULT_PLATFORM)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
components.addSelectMenu({
|
||||||
|
placeholder: "Select platform type",
|
||||||
|
customId: "emoji-type",
|
||||||
|
options: selectTypeOptions
|
||||||
|
})
|
||||||
|
|
||||||
components.addSelectMenu({
|
components.addSelectMenu({
|
||||||
placeholder: "Select emoji revision",
|
placeholder: "Select emoji revision",
|
||||||
customId: "emoji-version",
|
customId: "emoji-version",
|
||||||
|
@ -224,12 +278,12 @@ module.exports = {
|
||||||
currentView = createEmbed("default", context, {
|
currentView = createEmbed("default", context, {
|
||||||
author: {
|
author: {
|
||||||
iconUrl: ico,
|
iconUrl: ico,
|
||||||
name: `${res.data.name} • ${res.data.platforms[args.type].images[0].version}`,
|
name: `${res.data.name} • ${res.data.platforms[DEFAULT_PLATFORM].images[0].version}`,
|
||||||
url: res.data.link
|
url: res.data.link
|
||||||
},
|
},
|
||||||
description: res.data.codes.map((c)=>pill(c)).join(' '),
|
description: res.data.codes.map((c)=>pill(c)).join(' '),
|
||||||
image: {
|
image: {
|
||||||
url: res.data.platforms[args.type].images[0].src
|
url: res.data.platforms[DEFAULT_PLATFORM].images[0].src
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
iconUrl: STATICS.emojipedia,
|
iconUrl: STATICS.emojipedia,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue