out-of-your-element/d2m/actions/create-space.js

46 lines
1,019 B
JavaScript
Raw Normal View History

2023-05-04 20:25:00 +00:00
// @ts-check
const passthrough = require("../../passthrough")
const { sync, db } = passthrough
/** @type {import("../../matrix/api")} */
const api = sync.require("../../matrix/api")
2023-05-04 20:25:00 +00:00
/**
* @param {import("discord-api-types/v10").RESTGetAPIGuildResult} guild
*/
async function createSpace(guild) {
2023-07-01 13:40:54 +00:00
const roomID = await api.createRoom({
2023-05-04 20:25:00 +00:00
name: guild.name,
preset: "private_chat",
visibility: "private",
power_level_content_override: {
events_default: 100,
invite: 50
},
invite: ["@cadence:cadence.moe"], // TODO
topic: guild.description || undefined,
creation_content: {
type: "m.space"
},
initial_state: [
{
type: "m.room.guest_access",
state_key: "",
content: {
guest_access: "can_join"
}
},
{
type: "m.room.history_visibility",
content: {
history_visibility: "invited"
}
}
]
})
db.prepare("INSERT INTO guild_space (guild_id, space_id) VALUES (?, ?)").run(guild.id, roomID)
return roomID
2023-05-04 20:25:00 +00:00
}
module.exports.createSpace = createSpace