mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-11 15:43:03 -04:00
various fixes
This commit is contained in:
parent
a7fcad82a9
commit
ddbef1267e
3 changed files with 27 additions and 115 deletions
|
@ -1,77 +0,0 @@
|
||||||
const { REWRITE_STYLES } = require('#constants');
|
|
||||||
|
|
||||||
const { createEmbed } = require('#utils/embed');
|
|
||||||
const { iconPill, codeblock } = require('#utils/markdown');
|
|
||||||
|
|
||||||
const { InteractionCallbackTypes, ApplicationCommandOptionTypes, MessageFlags } = require('detritus-client/lib/constants');
|
|
||||||
|
|
||||||
const superagent = require('superagent')
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
description: 'Use AI to rewrite your messages.',
|
|
||||||
name: 'rewrite',
|
|
||||||
guildIds: ["409840884713127956"],
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
name: 'message',
|
|
||||||
description: 'Message to rewrite',
|
|
||||||
type: ApplicationCommandOptionTypes.STRING,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'style',
|
|
||||||
description: 'Style to use',
|
|
||||||
choices: REWRITE_STYLES,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
],
|
|
||||||
run: async (context, args) => {
|
|
||||||
|
|
||||||
await context.respond({data: { flags: MessageFlags.EPHEMERAL }, type: InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE})
|
|
||||||
|
|
||||||
try{
|
|
||||||
// Use the last 10 chat messages as context for the rewrite
|
|
||||||
let messageContext = [];
|
|
||||||
const messages = await context.channel.fetchMessages({limit: 10});
|
|
||||||
|
|
||||||
for(const m of messages){
|
|
||||||
if(!m[1].content) continue;
|
|
||||||
let ctx = {
|
|
||||||
username: m[1].author.username,
|
|
||||||
content: m[1].content
|
|
||||||
}
|
|
||||||
|
|
||||||
if(m[1].content.length > 200) ctx.content = ctx.content.substr(0, 200) + "..."
|
|
||||||
|
|
||||||
messageContext.push(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the custom message rewriting api
|
|
||||||
// TODO: move this once monolith/pelican is ready
|
|
||||||
let res = await superagent.post(`${process.env.AI_SERVER}/boulevard:rewriteMessage`)
|
|
||||||
.set({
|
|
||||||
Authorization: process.env.AI_SERVER_KEY
|
|
||||||
})
|
|
||||||
.send({
|
|
||||||
input: args.message,
|
|
||||||
style: args.style,
|
|
||||||
context: messageContext
|
|
||||||
})
|
|
||||||
|
|
||||||
let input = args.message
|
|
||||||
if(input.length >= 50) input = input.substr(0, 50) + "..."
|
|
||||||
|
|
||||||
if(!res.body.output) return context.editOrRespond({ embeds: [createEmbed("error", context, "Unable to generate rewrite. Try again later.")], flags: MessageFlags.EPHEMERAL })
|
|
||||||
|
|
||||||
return context.editOrRespond({ embeds: [createEmbed("defaultNoFooter", context, {
|
|
||||||
description: `${iconPill("generativeai_text", input)}\n${res.body.output.map((o)=> codeblock("text", [o.replace(/\nRewritten: .*?/gs, '')])).join(' ')}`
|
|
||||||
})], flags: MessageFlags.EPHEMERAL })
|
|
||||||
}catch(e){
|
|
||||||
console.log(e)
|
|
||||||
await context.editOrRespond({
|
|
||||||
embeds: [createEmbed("error", context, "Unable to generate text. Try again later.")],
|
|
||||||
flags: MessageFlags.EPHEMERAL
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -119,7 +119,7 @@ module.exports = {
|
||||||
|
|
||||||
// Regular Emoji Handling
|
// Regular Emoji Handling
|
||||||
ingest("emoji_enlarge", "slash_command_ran");
|
ingest("emoji_enlarge", "slash_command_ran");
|
||||||
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."))
|
||||||
|
|
||||||
let res;
|
let res;
|
||||||
try{
|
try{
|
||||||
|
@ -131,31 +131,18 @@ module.exports = {
|
||||||
|
|
||||||
if(Object.keys(res.data.platforms).length === 0) return await editOrReply(context, createEmbed("error", context, "No images available for this emoji."));
|
if(Object.keys(res.data.platforms).length === 0) return await editOrReply(context, createEmbed("error", context, "No images available for this emoji."));
|
||||||
|
|
||||||
|
let currentPlatform = "twitter";
|
||||||
|
|
||||||
|
if(!res.data.platforms[currentPlatform]) currentPlatform = Object.keys(res.data.platforms)[0]
|
||||||
|
else currentPlatform = "twitter"
|
||||||
|
|
||||||
// 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`
|
||||||
ico = res.data.platforms["twitter"].images[0].src
|
if(res.data.platforms[currentPlatform]) ico = res.data.platforms[currentPlatform].images[0].src
|
||||||
|
|
||||||
const DEFAULT_PLATFORM = "twitter"
|
const DEFAULT_PLATFORM = currentPlatform
|
||||||
let platformEmoji = res.data.platforms["twitter"]
|
|
||||||
|
|
||||||
if(platformEmoji.images.length == 1) return editOrReply(context, createEmbed("default", context, {
|
|
||||||
author: {
|
|
||||||
iconUrl: ico,
|
|
||||||
name: `${res.data.name} • ${res.data.platforms[DEFAULT_PLATFORM].images[0].version}`,
|
|
||||||
url: res.data.link
|
|
||||||
},
|
|
||||||
description: res.data.codes.map((c)=>pill(c)).join(' '),
|
|
||||||
image: {
|
|
||||||
url: res.data.platforms[DEFAULT_PLATFORM].images[0].src || STATIC_ASSETS.emoji_placeholder
|
|
||||||
},
|
|
||||||
footer: {
|
|
||||||
iconUrl: STATICS.emojipedia,
|
|
||||||
text: `Emojipedia • ${context.application.name}`
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
let currentView;
|
let currentView;
|
||||||
let currentPlatform = "twitter";
|
|
||||||
let currentRevision = "";
|
let currentRevision = "";
|
||||||
|
|
||||||
const components = new Components({
|
const components = new Components({
|
||||||
|
@ -166,34 +153,32 @@ module.exports = {
|
||||||
// this sucks but works, ensures the newly selected option stays selected
|
// this sucks but works, ensures the newly selected option stays selected
|
||||||
// update 25/03/24 - it sucks even more now
|
// update 25/03/24 - it sucks even more now
|
||||||
|
|
||||||
if(ctx.data.customId == "emoji-type"){
|
if(ctx.data.customId === "emoji-type"){
|
||||||
currentPlatform = ctx.data.values[0];
|
currentPlatform = ctx.data.values[0];
|
||||||
currentRevision = res.data.platforms[currentPlatform].images[0].id
|
currentRevision = res.data.platforms[currentPlatform].images[0].id
|
||||||
|
|
||||||
for (let i = 0; i < components.components[0].components[0].options.length; i++) {
|
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)
|
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) => {
|
components.components[1].components[0].options = 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[currentPlatform].images[0].id)
|
default: (r.id === res.data.platforms[currentPlatform].images[0].id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
components.components[1].components[0].options = newVersionOptions
|
} else if(ctx.data.customId === "emoji-version"){
|
||||||
|
|
||||||
} else if(ctx.data.customId == "emoji-version"){
|
|
||||||
|
|
||||||
for (let i = 0; i < components.components[1].components[0].options.length; i++) {
|
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])
|
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];
|
currentRevision = ctx.data.values[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const emojiAsset = res.data.platforms[currentPlatform].images.filter((p)=>{
|
const emojiAsset = res.data.platforms[currentPlatform].images.filter((p)=>{
|
||||||
return p.id == currentRevision
|
return p.id === currentRevision
|
||||||
})
|
})
|
||||||
|
|
||||||
currentView = createEmbed("default", context, {
|
currentView = createEmbed("default", context, {
|
||||||
|
@ -220,7 +205,7 @@ module.exports = {
|
||||||
return {
|
return {
|
||||||
label: r.version,
|
label: r.version,
|
||||||
value: r.id,
|
value: r.id,
|
||||||
default: (r.id == res.data.platforms[DEFAULT_PLATFORM].images[0].id)
|
default: (r.id === res.data.platforms[DEFAULT_PLATFORM].images[0].id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -231,20 +216,22 @@ module.exports = {
|
||||||
return {
|
return {
|
||||||
label: pl.name,
|
label: pl.name,
|
||||||
value: r,
|
value: r,
|
||||||
default: (r == "twitter")
|
default: (r === DEFAULT_PLATFORM)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
components.addSelectMenu({
|
components.addSelectMenu({
|
||||||
placeholder: "Select platform type",
|
placeholder: "Select platform type",
|
||||||
customId: "emoji-type",
|
customId: "emoji-type",
|
||||||
options: selectTypeOptions
|
options: selectTypeOptions,
|
||||||
|
disabled: (res.data.platforms.length === 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
components.addSelectMenu({
|
components.addSelectMenu({
|
||||||
placeholder: "Select emoji revision",
|
placeholder: "Select emoji revision",
|
||||||
customId: "emoji-version",
|
customId: "emoji-version",
|
||||||
options: selectOptions
|
options: selectOptions,
|
||||||
|
disabled: (res.data.platforms[DEFAULT_PLATFORM].images.length === 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
currentView = createEmbed("default", context, {
|
currentView = createEmbed("default", context, {
|
||||||
|
|
|
@ -7,6 +7,8 @@ const { Permissions } = require("detritus-client/lib/constants");
|
||||||
|
|
||||||
const superagent = require('superagent');
|
const superagent = require('superagent');
|
||||||
|
|
||||||
|
const { Routes } = require('detritus-client-rest/lib/endpoints');
|
||||||
|
|
||||||
const applicationFlags = {
|
const applicationFlags = {
|
||||||
EMBEDDED_RELEASED: 1,
|
EMBEDDED_RELEASED: 1,
|
||||||
GATEWAY_PRESENCE: 12,
|
GATEWAY_PRESENCE: 12,
|
||||||
|
@ -59,14 +61,14 @@ module.exports = {
|
||||||
let application;
|
let application;
|
||||||
let assets;
|
let assets;
|
||||||
try{
|
try{
|
||||||
application = await superagent.get(`https://discord.com/api/v9/applications/${id}/rpc`)
|
application = await superagent.get(`${Routes.URL}/api/v9/applications/${id}/rpc`)
|
||||||
application = application.body
|
application = application.body
|
||||||
}catch(e){
|
}catch(e){
|
||||||
return editOrReply(context, createEmbed("warning", context, "Invalid Application"))
|
return editOrReply(context, createEmbed("warning", context, "Invalid Application"))
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
assets = await superagent.get(`https://discord.com/api/oauth2/applications/${id}/assets`)
|
assets = await superagent.get(`${Routes.URL}/api/oauth2/applications/${id}/assets`)
|
||||||
assets = assets.body
|
assets = assets.body
|
||||||
}catch(e){
|
}catch(e){
|
||||||
// :)
|
// :)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue