forked from cadence/out-of-your-element
		
	Add Discord command for setting privacy level
This commit is contained in:
		
							parent
							
								
									e84e0d28db
								
							
						
					
					
						commit
						3a6b40e27d
					
				
					 2 changed files with 36 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -154,7 +154,7 @@ function syncSpace(guild) {
 | 
			
		|||
 | 
			
		||||
/**
 | 
			
		||||
 * Inefficiently force the space and its existing child rooms to be fully updated.
 | 
			
		||||
 * Should not need to be called as part of the bridge's normal operation.
 | 
			
		||||
 * Prefer not to call this as part of the bridge's normal operation.
 | 
			
		||||
 */
 | 
			
		||||
async function syncSpaceFully(guildID) {
 | 
			
		||||
	/** @ts-ignore @type {DiscordTypes.APIGuild} */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,8 @@ const {discord, sync, db, select} = require("../passthrough")
 | 
			
		|||
const api = sync.require("../matrix/api")
 | 
			
		||||
/** @type {import("../matrix/file")} */
 | 
			
		||||
const file = sync.require("../matrix/file")
 | 
			
		||||
/** @type {import("../d2m/actions/create-space")} */
 | 
			
		||||
const createSpace = sync.require("../d2m/actions/create-space")
 | 
			
		||||
/** @type {import("./utils")} */
 | 
			
		||||
const utils = sync.require("./utils")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -212,6 +214,39 @@ const commands = [{
 | 
			
		|||
			})
 | 
			
		||||
		}
 | 
			
		||||
	)
 | 
			
		||||
}, {
 | 
			
		||||
	aliases: ["privacy", "discoverable", "publish", "published"],
 | 
			
		||||
	execute: replyctx(
 | 
			
		||||
		async (message, channel, guild, ctx) => {
 | 
			
		||||
			const current = select("guild_space", "privacy_level", {guild_id: guild.id}).pluck().get()
 | 
			
		||||
			if (current == null) {
 | 
			
		||||
				return discord.snow.channel.createMessage(channel.id, {
 | 
			
		||||
					...ctx,
 | 
			
		||||
					content: "This server isn't bridged to the other side."
 | 
			
		||||
				})
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			const levels = ["invite", "link", "directory"]
 | 
			
		||||
			const level = levels.findIndex(x => message.content.includes(x))
 | 
			
		||||
			if (level === -1) {
 | 
			
		||||
				return discord.snow.channel.createMessage(channel.id, {
 | 
			
		||||
					...ctx,
 | 
			
		||||
					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 Matrix user, or the //invite command."
 | 
			
		||||
						+ "\n`link`: Matrix links can be created and shared like Discord's invite links. `invite` features also work."
 | 
			
		||||
						+ "\n`directory`: Publishes to the Matrix in-app directory, like Server Discovery. Preview enabled. `invite` and `link` also work."
 | 
			
		||||
						+ `\n**Current privacy level: \`${levels[current]}\`**`
 | 
			
		||||
				})
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			db.prepare("UPDATE guild_space SET privacy_level = ? WHERE guild_id = ?").run(level, guild.id)
 | 
			
		||||
			discord.snow.channel.createMessage(channel.id, {
 | 
			
		||||
				...ctx,
 | 
			
		||||
				content: `Privacy level updated to \`${levels[level]}\`. Changes will apply shortly.`
 | 
			
		||||
			})
 | 
			
		||||
			await createSpace.syncSpaceFully(guild.id)
 | 
			
		||||
		}
 | 
			
		||||
	)
 | 
			
		||||
}]
 | 
			
		||||
 | 
			
		||||
/** @type {CommandExecute} */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue