forked from cadence/out-of-your-element
Why did I make it this way??? #13
3 changed files with 20 additions and 11 deletions
|
|
@ -35,10 +35,10 @@ function getDiscordParseCallbacks(message, guild, useHTML, spoilers = []) {
|
||||||
/** @param {{id: string, type: "discordUser"}} node */
|
/** @param {{id: string, type: "discordUser"}} node */
|
||||||
user: node => {
|
user: node => {
|
||||||
const mxid = select("sim", "mxid", {user_id: node.id}).pluck().get()
|
const mxid = select("sim", "mxid", {user_id: node.id}).pluck().get()
|
||||||
const interaction = message.interaction_metadata || message.interaction
|
const interactionMetadata = message.interaction_metadata
|
||||||
const username = message.mentions?.find(ment => ment.id === node.id)?.username
|
const username = message.mentions?.find(ment => ment.id === node.id)?.username
|
||||||
|| message.referenced_message?.mentions?.find(ment => ment.id === node.id)?.username
|
|| message.referenced_message?.mentions?.find(ment => ment.id === node.id)?.username
|
||||||
|| (interaction?.user.id === node.id ? interaction.user.username : null)
|
|| (interactionMetadata?.user.id === node.id ? interactionMetadata.user.username : null)
|
||||||
|| (message.author?.id === node.id ? message.author.username : null)
|
|| (message.author?.id === node.id ? message.author.username : null)
|
||||||
|| "unknown-user"
|
|| "unknown-user"
|
||||||
if (mxid && useHTML) {
|
if (mxid && useHTML) {
|
||||||
|
|
@ -357,9 +357,8 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
const interaction = message.interaction_metadata || message.interaction
|
let isInteraction = (message.type === DiscordTypes.MessageType.ChatInputCommand || message.type === DiscordTypes.MessageType.ContextMenuCommand) && message.interaction && "name" in message.interaction
|
||||||
const isInteraction = message.type === DiscordTypes.MessageType.ChatInputCommand && !!interaction && "name" in interaction
|
let isThinkingInteraction = isInteraction && !!((message.flags || 0) & DiscordTypes.MessageFlags.Loading)
|
||||||
const isThinkingInteraction = isInteraction && !!((message.flags || 0) & DiscordTypes.MessageFlags.Loading)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@type {{room?: boolean, user_ids?: string[]}}
|
@type {{room?: boolean, user_ids?: string[]}}
|
||||||
|
|
@ -400,6 +399,16 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
} else if (message.referenced_message) {
|
} else if (message.referenced_message) {
|
||||||
repliedToUnknownEvent = true
|
repliedToUnknownEvent = true
|
||||||
}
|
}
|
||||||
|
} else if (message.type === DiscordTypes.MessageType.ContextMenuCommand && message.interaction && message.message_reference?.message_id) {
|
||||||
|
// It could be a /plu/ral emulated reply
|
||||||
|
if (message.interaction.name.startsWith("Reply ") && message.content.startsWith("-# [↪](")) {
|
||||||
|
const row = await getHistoricalEventRow(message.message_reference?.message_id)
|
||||||
|
if (row && "event_id" in row) {
|
||||||
|
repliedToEventRow = Object.assign(row, {channel_id: row.reference_channel_id})
|
||||||
|
message.content = message.content.replace(/^.*\n/, "")
|
||||||
|
isInteraction = false // declutter
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (dUtils.isWebhookMessage(message) && message.embeds[0]?.author?.name?.endsWith("↩️")) {
|
} else if (dUtils.isWebhookMessage(message) && message.embeds[0]?.author?.name?.endsWith("↩️")) {
|
||||||
// It could be a PluralKit emulated reply, let's see if it has a message link
|
// It could be a PluralKit emulated reply, let's see if it has a message link
|
||||||
const isEmulatedReplyToText = message.embeds[0].description?.startsWith("**[Reply to:]")
|
const isEmulatedReplyToText = message.embeds[0].description?.startsWith("**[Reply to:]")
|
||||||
|
|
@ -685,8 +694,8 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInteraction && !isThinkingInteraction && events.length === 0) {
|
if (isInteraction && !isThinkingInteraction && message.interaction && events.length === 0) {
|
||||||
const formattedInteraction = getFormattedInteraction(interaction, false)
|
const formattedInteraction = getFormattedInteraction(message.interaction, false)
|
||||||
body = `${formattedInteraction.body}\n${body}`
|
body = `${formattedInteraction.body}\n${body}`
|
||||||
html = `${formattedInteraction.html}${html}`
|
html = `${formattedInteraction.html}${html}`
|
||||||
}
|
}
|
||||||
|
|
@ -782,8 +791,8 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
events.push(...forwardedEvents)
|
events.push(...forwardedEvents)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isThinkingInteraction) {
|
if (isInteraction && isThinkingInteraction && message.interaction) {
|
||||||
const formattedInteraction = getFormattedInteraction(interaction, true)
|
const formattedInteraction = getFormattedInteraction(message.interaction, true)
|
||||||
await addTextEvent(formattedInteraction.body, formattedInteraction.html, "m.notice")
|
await addTextEvent(formattedInteraction.body, formattedInteraction.html, "m.notice")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@ CREATE TABLE "role_default" (
|
||||||
"guild_id" TEXT NOT NULL,
|
"guild_id" TEXT NOT NULL,
|
||||||
"role_id" TEXT NOT NULL,
|
"role_id" TEXT NOT NULL,
|
||||||
PRIMARY KEY ("guild_id", "role_id")
|
PRIMARY KEY ("guild_id", "role_id")
|
||||||
);
|
) WITHOUT ROWID;
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ function hasAllPermissions(resolvedPermissions, permissionsToCheckFor) {
|
||||||
* @param {DiscordTypes.APIMessage} message
|
* @param {DiscordTypes.APIMessage} message
|
||||||
*/
|
*/
|
||||||
function isWebhookMessage(message) {
|
function isWebhookMessage(message) {
|
||||||
return message.webhook_id && message.type !== DiscordTypes.MessageType.ChatInputCommand
|
return message.webhook_id && message.type !== DiscordTypes.MessageType.ChatInputCommand && message.type !== DiscordTypes.MessageType.ContextMenuCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue