2023-05-04 20:25:00 +00:00
|
|
|
// @ts-check
|
|
|
|
|
2023-08-19 06:39:23 +00:00
|
|
|
const assert = require("assert")
|
2023-05-04 20:25:00 +00:00
|
|
|
const passthrough = require("../../passthrough")
|
|
|
|
const { sync, db } = passthrough
|
2023-05-08 11:37:51 +00:00
|
|
|
/** @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
|
|
|
|
*/
|
2023-05-08 12:58:46 +00:00
|
|
|
async function createSpace(guild) {
|
2023-08-19 06:39:23 +00:00
|
|
|
assert(guild.name)
|
2023-07-01 13:40:54 +00:00
|
|
|
const roomID = await api.createRoom({
|
2023-05-04 20:25:00 +00:00
|
|
|
name: guild.name,
|
2023-08-19 06:39:23 +00:00
|
|
|
preset: "private_chat", // cannot join space unless invited
|
2023-05-04 20:25:00 +00:00
|
|
|
visibility: "private",
|
|
|
|
power_level_content_override: {
|
2023-08-19 06:39:23 +00:00
|
|
|
events_default: 100, // space can only be managed by bridge
|
|
|
|
invite: 0 // any existing member can invite others
|
2023-05-04 20:25:00 +00:00
|
|
|
},
|
|
|
|
invite: ["@cadence:cadence.moe"], // TODO
|
|
|
|
topic: guild.description || undefined,
|
|
|
|
creation_content: {
|
|
|
|
type: "m.space"
|
|
|
|
},
|
|
|
|
initial_state: [
|
|
|
|
{
|
|
|
|
type: "m.room.guest_access",
|
|
|
|
state_key: "",
|
|
|
|
content: {
|
2023-08-19 06:39:23 +00:00
|
|
|
guest_access: "can_join" // guests can join space if other conditions are met
|
2023-05-04 20:25:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "m.room.history_visibility",
|
|
|
|
content: {
|
2023-08-19 06:39:23 +00:00
|
|
|
history_visibility: "invited" // any events sent after user was invited are visible
|
2023-05-04 20:25:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2023-05-08 12:58:46 +00:00
|
|
|
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
|