mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-10 20:32:50 +02:00
Highly experimental message interactions
This commit is contained in:
parent
b8793dae0f
commit
be405d3eed
9 changed files with 491 additions and 4 deletions
90
discord/register-interactions.js
Normal file
90
discord/register-interactions.js
Normal file
|
@ -0,0 +1,90 @@
|
|||
// @ts-check
|
||||
|
||||
const DiscordTypes = require("discord-api-types/v10")
|
||||
const {discord, sync, db, select} = require("../passthrough")
|
||||
const {id} = require("../addbot")
|
||||
|
||||
const matrixInfo = sync.require("./interactions/matrix-info.js")
|
||||
const invite = sync.require("./interactions/invite.js")
|
||||
const permissions = sync.require("./interactions/permissions.js")
|
||||
const bridge = sync.require("./interactions/bridge.js")
|
||||
|
||||
discord.snow.interaction.bulkOverwriteApplicationCommands(id, [{
|
||||
name: "Matrix info",
|
||||
contexts: [DiscordTypes.InteractionContextType.Guild],
|
||||
type: DiscordTypes.ApplicationCommandType.Message,
|
||||
}, {
|
||||
name: "Permissions",
|
||||
contexts: [DiscordTypes.InteractionContextType.Guild],
|
||||
type: DiscordTypes.ApplicationCommandType.Message,
|
||||
default_member_permissions: String(DiscordTypes.PermissionFlagsBits.KickMembers)
|
||||
}, {
|
||||
name: "invite",
|
||||
contexts: [DiscordTypes.InteractionContextType.Guild],
|
||||
type: DiscordTypes.ApplicationCommandType.ChatInput,
|
||||
description: "Invite a Matrix user to this Discord server",
|
||||
default_member_permissions: String(DiscordTypes.PermissionFlagsBits.CreateInstantInvite),
|
||||
options: [
|
||||
{
|
||||
type: DiscordTypes.ApplicationCommandOptionType.String,
|
||||
description: "The Matrix user to invite, e.g. @username:example.org",
|
||||
name: "user"
|
||||
}
|
||||
]
|
||||
}, {
|
||||
name: "bridge",
|
||||
contexts: [DiscordTypes.InteractionContextType.Guild],
|
||||
type: DiscordTypes.ApplicationCommandType.ChatInput,
|
||||
description: "Start bridging this channel to a Matrix room.",
|
||||
default_member_permissions: String(DiscordTypes.PermissionFlagsBits.ManageChannels),
|
||||
options: [
|
||||
{
|
||||
type: DiscordTypes.ApplicationCommandOptionType.String,
|
||||
description: "Destination room to bridge to.",
|
||||
name: "room",
|
||||
autocomplete: true
|
||||
}
|
||||
]
|
||||
}])
|
||||
|
||||
async function dispatchInteraction(interaction) {
|
||||
const id = interaction.data.custom_id || interaction.data.name
|
||||
try {
|
||||
console.log(interaction)
|
||||
if (id === "Matrix info") {
|
||||
await matrixInfo.interact(interaction)
|
||||
} else if (id === "invite") {
|
||||
await invite.interact(interaction)
|
||||
} else if (id === "invite_channel") {
|
||||
await invite.interactButton(interaction)
|
||||
} else if (id === "Permissions") {
|
||||
await permissions.interact(interaction)
|
||||
} else if (id === "permissions_edit") {
|
||||
await permissions.interactEdit(interaction)
|
||||
} else if (id === "bridge") {
|
||||
await bridge.interact(interaction)
|
||||
} else {
|
||||
throw new Error(`Unknown interaction ${id}`)
|
||||
}
|
||||
} catch (e) {
|
||||
let stackLines = null
|
||||
if (e.stack) {
|
||||
stackLines = e.stack.split("\n")
|
||||
let cloudstormLine = stackLines.findIndex(l => l.includes("/node_modules/cloudstorm/"))
|
||||
if (cloudstormLine !== -1) {
|
||||
stackLines = stackLines.slice(0, cloudstormLine - 2)
|
||||
}
|
||||
}
|
||||
discord.snow.interaction.createInteractionResponse(interaction.id, interaction.token, {
|
||||
type: DiscordTypes.InteractionResponseType.ChannelMessageWithSource,
|
||||
data: {
|
||||
content: `Interaction failed: **${id}**`
|
||||
+ `\nError trace:\n\`\`\`\n${stackLines.join("\n")}\`\`\``
|
||||
+ `Interaction data:\n\`\`\`\n${JSON.stringify(interaction.data, null, 2)}\`\`\``,
|
||||
flags: DiscordTypes.MessageFlags.Ephemeral
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.dispatchInteraction = dispatchInteraction
|
Loading…
Add table
Add a link
Reference in a new issue