mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-11 20:53:01 +02:00
Migrate all legacy commands to interactions
This commit is contained in:
parent
b3daa6b84c
commit
6bc3eaf866
5 changed files with 92 additions and 281 deletions
|
@ -5,7 +5,6 @@ const Ty = require("../../types")
|
|||
const {discord, sync, db, select, from} = require("../../passthrough")
|
||||
const assert = require("assert/strict")
|
||||
|
||||
|
||||
/** @type {import("../../matrix/api")} */
|
||||
const api = sync.require("../../matrix/api")
|
||||
|
||||
|
|
59
src/discord/interactions/privacy.js
Normal file
59
src/discord/interactions/privacy.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
// @ts-check
|
||||
|
||||
const DiscordTypes = require("discord-api-types/v10")
|
||||
const {discord, sync, db, select} = require("../../passthrough")
|
||||
const {id: botID} = require("../../../addbot")
|
||||
|
||||
/** @type {import("../../d2m/actions/create-space")} */
|
||||
const createSpace = sync.require("../../d2m/actions/create-space")
|
||||
|
||||
/**
|
||||
* @param {DiscordTypes.APIChatInputApplicationCommandGuildInteraction} interaction
|
||||
*/
|
||||
async function interact({id, token, data, guild_id}) {
|
||||
// Check guild is bridged
|
||||
const current = select("guild_space", "privacy_level", {guild_id}).pluck().get()
|
||||
if (current == null) return {
|
||||
type: DiscordTypes.InteractionResponseType.ChannelMessageWithSource,
|
||||
data: {
|
||||
content: "This server isn't bridged to Matrix, so you can't set the Matrix privacy level.",
|
||||
flags: DiscordTypes.MessageFlags.Ephemeral
|
||||
}
|
||||
}
|
||||
|
||||
// Get input level
|
||||
/** @type {DiscordTypes.APIApplicationCommandInteractionDataStringOption[] | undefined} */ // @ts-ignore
|
||||
const options = data.options
|
||||
const input = options?.[0].value || ""
|
||||
const levels = ["invite", "link", "directory"]
|
||||
const level = levels.findIndex(x => input === x)
|
||||
if (level === -1) {
|
||||
return discord.snow.interaction.createInteractionResponse(id, token, {
|
||||
type: DiscordTypes.InteractionResponseType.ChannelMessageWithSource,
|
||||
data: {
|
||||
content: "**Usage: `/privacy <level>`**. This will set who can join the space on Matrix-side. There are three levels:"
|
||||
+ "\n`invite`: Can only join with a direct in-app invite from another user. No shareable invite links."
|
||||
+ "\n`link`: Matrix links can be created and shared like Discord's invite links. In-app invites still work."
|
||||
+ "\n`directory`: Publicly visible in the Matrix space directory, like Server Discovery. Invites and links still work."
|
||||
+ `\n**Current privacy level: \`${levels[current]}\`**`,
|
||||
flags: DiscordTypes.MessageFlags.Ephemeral
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
await discord.snow.interaction.createInteractionResponse(id, token, {
|
||||
type: DiscordTypes.InteractionResponseType.DeferredChannelMessageWithSource,
|
||||
data: {
|
||||
flags: DiscordTypes.MessageFlags.Ephemeral
|
||||
}
|
||||
})
|
||||
|
||||
db.prepare("UPDATE guild_space SET privacy_level = ? WHERE guild_id = ?").run(level, guild_id)
|
||||
await createSpace.syncSpaceFully(guild_id) // this is inefficient but OK to call infrequently on user request
|
||||
|
||||
await discord.snow.interaction.editOriginalInteractionResponse(botID, token, {
|
||||
content: `Privacy level updated to \`${levels[level]}\`.`
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.interact = interact
|
Loading…
Add table
Add a link
Reference in a new issue