From 8b77808950d4e1ce21c868513c2b4a5b4ed81d3c Mon Sep 17 00:00:00 2001 From: bignutty <3515180-bignutty@users.noreply.gitlab.com> Date: Fri, 17 May 2024 22:04:55 +0200 Subject: [PATCH] automod fix --- labscore/logging.js | 2 ++ labscore/utils/message.js | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/labscore/logging.js b/labscore/logging.js index 4eeffcb..4c9d9f8 100644 --- a/labscore/logging.js +++ b/labscore/logging.js @@ -26,6 +26,8 @@ module.exports.maintower = async function (packages, type){ } module.exports.basecamp = async function (log, content = ""){ + // This begins the list of errors that i simply cannot fix. thank you discord. + if(content.includes(`"code": 200000`)) return; try{ let res = await superagent.post(MAINTOWER_BASE_URL + 'basecamp') .set({ diff --git a/labscore/utils/message.js b/labscore/utils/message.js index 8e01998..9333468 100644 --- a/labscore/utils/message.js +++ b/labscore/utils/message.js @@ -1,6 +1,7 @@ -const { Permissions } = require("detritus-client/lib/constants") +const { Permissions, InteractionCallbackTypes, MessageFlags } = require("detritus-client/lib/constants") const { basecamp } = require("../logging") const { STATICS } = require("./statics") +const { createEmbed } = require("./embed") module.exports.editOrReply = function(context, message, disableReference = false){ // Apply message_reference @@ -15,12 +16,44 @@ module.exports.editOrReply = function(context, message, disableReference = false // Handle responses for interaction context if(context.editOrRespond){ return context.editOrRespond(message).catch((e)=>{ + /* + Discord in their infinite wisdom decided that *bots* should + be the one to handle automod errors on their own, deciding + against adding a notice/response type for their frontend. + + This is the awesome solution to this problem, that isn't + actually very awesome and actually sucks a lot. + */ + if(e.code == 200000){ + try{ + let embedResponse = createEmbed("error", context, "Response was filtered by AutoMod.") + embedResponse.description = `Try running the command somewhere else or ask server admins for help.` + return context.editOrRespond({ + allowedMentions: { parse: [], repliedUser: false }, + embeds: [ + embedResponse + ] + }) + }catch(e){ + /* + another error? suck it. + there is genuinely nothing left that we can do. + + create followup message has an awesome 'hack' that prevents + the bot from creating a new ephemeral followup response + if the original one isn't/couldn't be acknowledged. + + https://discord.com/developers/docs/interactions/receiving-and-responding#create-followup-message + */ + } + } basecamp(`<:ico_w3:1086624963047460874>\`[${process.env.HOSTNAME}]\` **\` 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) }) } // Only respond if the command is still available and we have permissions to respond. - if(!context.message.deleted && context.channel.can(Permissions.SEND_MESSAGES)) return context.editOrReply(message).catch((e)=> + if(!context.message.deleted && context.channel.can(Permissions.SEND_MESSAGES)) return context.editOrReply(message).catch((e)=>{ + console.log(e.status) basecamp(`<:ico_w3:1086624963047460874>\`[${process.env.HOSTNAME}]\` **\` SHARD_MESSAGE_ERROR \`** \`[Shard ${context.client.shardId}]\` Command \`${context.message?.content}\` failed to reply: @ \`${Date.now()}\`\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``, message) - ) +}) } \ No newline at end of file