Merge branch 'main' into nextgen/cardstack

This commit is contained in:
bignutty 2025-02-12 02:09:02 +01:00
commit 8c036e714a
3 changed files with 41 additions and 34 deletions

View file

@ -4,11 +4,12 @@ const { TRANSLATE_DISPLAY_MAPPINGS, TRANSLATE_LANGUAGES, PERMISSION_GROUPS } = r
const { getMessageAttachment, validateAttachment } = require('#utils/attachment'); const { getMessageAttachment, validateAttachment } = require('#utils/attachment');
const { createEmbed } = require('#utils/embed'); const { createEmbed } = require('#utils/embed');
const { acknowledge } = require('#utils/interactions'); const { acknowledge } = require('#utils/interactions');
const { codeblock, pill, icon } = require('#utils/markdown'); const { codeblock, pill, icon, iconAsEmojiObject } = require('#utils/markdown');
const { editOrReply } = require('#utils/message'); const { editOrReply } = require('#utils/message');
const { STATICS, STATIC_ACTIONS } = require('#utils/statics'); const { STATICS, STATIC_ACTIONS } = require('#utils/statics');
const { Context, Argument } = require('detritus-client/lib/command');
const { ApplicationCommandTypes, MessageFlags, InteractionContextTypes, ApplicationIntegrationTypes } = require("detritus-client/lib/constants"); const { ApplicationCommandTypes, MessageFlags, InteractionContextTypes, ApplicationIntegrationTypes, MessageComponentTypes, InteractionCallbackTypes } = require("detritus-client/lib/constants");
const { Components } = require('detritus-client/lib/utils'); const { Components } = require('detritus-client/lib/utils');
module.exports = { module.exports = {
@ -22,6 +23,12 @@ module.exports = {
integrationTypes: [ integrationTypes: [
ApplicationIntegrationTypes.USER_INSTALL ApplicationIntegrationTypes.USER_INSTALL
], ],
/**
*
* @param {Context} context
* @param {Argument} args
* @returns
*/
run: async (context, args) => { run: async (context, args) => {
try{ try{
await acknowledge(context, false, [...PERMISSION_GROUPS.baseline_slash]); await acknowledge(context, false, [...PERMISSION_GROUPS.baseline_slash]);
@ -45,10 +52,6 @@ module.exports = {
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);
await ctx.editOrRespond({
embeds: [createEmbed("ai_custom", context, STATIC_ACTIONS.translate)]
})
let translate = await googleTranslate(context, ocr.response.body.text, "en", "auto") let translate = await googleTranslate(context, ocr.response.body.text, "en", "auto")
let fromFlag = TRANSLATE_DISPLAY_MAPPINGS[translate.response.body.language.from || sourceLanguage] || '' let fromFlag = TRANSLATE_DISPLAY_MAPPINGS[translate.response.body.language.from || sourceLanguage] || ''
@ -75,7 +78,7 @@ module.exports = {
}) })
await editOrReply(context, createEmbed("default", context, { await editOrReply(context, createEmbed("default", context, {
embeds: [{ embeds: [createEmbed("default", context, {
thumbnail: { thumbnail: {
url: attachment url: attachment
}, },
@ -84,7 +87,7 @@ module.exports = {
iconUrl: STATICS.googlelens, iconUrl: STATICS.googlelens,
text: `Google Lens • ${context.application.name} • Took ${ocr.timings}s` text: `Google Lens • ${context.application.name} • Took ${ocr.timings}s`
} }
}], })],
components components
})) }))
}catch(e){ }catch(e){

View file

@ -109,12 +109,12 @@ function createCommandPage(context, prefix, command, slashCommands) {
// These categories will be displayed to users, add them in the correct order // These categories will be displayed to users, add them in the correct order
const categories = { const categories = {
"core": `${icon("home")} Core Commands`, "core": `${icon("home")} System Commands`,
"info": `${icon("information")} Information Commands`, "info": `${icon("information")} Information Commands`,
"search": `${icon("mag")} Search Commands`, "search": `${icon("mag")} Search Commands`,
"utils": `${icon("tools")} Utility Commands`, "utils": `${icon("tools")} Utility Commands`,
"fun": `${icon("stars")} Fun Commands`, "fun": `${icon("stars")} Fun Commands`,
"mod": `${icon("shield")} "Moderation Command}` "mod": `${icon("shield")} Moderation Command`
} }
module.exports = { module.exports = {

View file

@ -48,6 +48,8 @@ module.exports.editOrReply = function(context, message, disableReference = false
} }
return context.editOrRespond(message).catch(async (e)=>{ return context.editOrRespond(message).catch(async (e)=>{
try{
const errorData = await e.response.json(); const errorData = await e.response.json();
if(MESSAGE_BLOCK_REASONS[errorData.code]){ if(MESSAGE_BLOCK_REASONS[errorData.code]){
// Delete the public response // Delete the public response
@ -74,7 +76,9 @@ module.exports.editOrReply = function(context, message, disableReference = false
context._meta.replacementMessageId = replacementMessage.id; context._meta.replacementMessageId = replacementMessage.id;
return replacementMessage; return replacementMessage;
}
}catch(e){
console.log(e)
} }
basecamp(formatErrorMessage(3, "SHARD_MESSAGE_ERROR", `\`[Shard ${context.client.shardId}]\` Command \`${context.command.name}\` failed to respond: @ \`${Date.now()}\`\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``), message); basecamp(formatErrorMessage(3, "SHARD_MESSAGE_ERROR", `\`[Shard ${context.client.shardId}]\` Command \`${context.command.name}\` failed to respond: @ \`${Date.now()}\`\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``), message);
}) })