Add room list debugger
This commit is contained in:
		| @@ -436,7 +436,7 @@ async function unbridgeDeletedChannel(channel, guildID) { | |||||||
| 	powerLevelContent.users ??= {} | 	powerLevelContent.users ??= {} | ||||||
| 	const bot = `@${reg.sender_localpart}:${reg.ooye.server_name}` | 	const bot = `@${reg.sender_localpart}:${reg.ooye.server_name}` | ||||||
| 	for (const mxid of Object.keys(powerLevelContent.users)) { | 	for (const mxid of Object.keys(powerLevelContent.users)) { | ||||||
| 		if (mUtils.eventSenderIsFromDiscord(mxid) && mxid !== bot) { | 		if (powerLevelContent.users[mxid] >= 100 && mUtils.eventSenderIsFromDiscord(mxid) && mxid !== bot) { | ||||||
| 			delete powerLevelContent.users[mxid] | 			delete powerLevelContent.users[mxid] | ||||||
| 			await api.sendState(roomID, "m.room.power_levels", "", powerLevelContent, mxid) | 			await api.sendState(roomID, "m.room.power_levels", "", powerLevelContent, mxid) | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -154,3 +154,40 @@ block body | |||||||
|       button.s-btn.s-btn__icon.s-btn__filled#link-button |       button.s-btn.s-btn__icon.s-btn__filled#link-button | ||||||
|         != icons.Icons.IconMerge |         != icons.Icons.IconMerge | ||||||
|         = ` Link` |         = ` Link` | ||||||
|  |  | ||||||
|  |   details.mt48 | ||||||
|  |     summary Debug room list | ||||||
|  |     .d-grid.grid__2.gx24 | ||||||
|  |       div | ||||||
|  |         h3.mt24 Channels | ||||||
|  |         p Channels are read from the channel_room table and then merged with the discord.channels memory cache to make the merged list. Anything in memory cache that's not in channel_room is considered unlinked. | ||||||
|  |       div | ||||||
|  |         h3.mt24 Rooms | ||||||
|  |         p Rooms use the same merged list as channels, based on augmented channel_room data. Then, rooms are read from the space. Anything in the space that's not merged is considered unlinked. | ||||||
|  |       div | ||||||
|  |         h3.mt24 Unavailable channels: Deleted from Discord | ||||||
|  |         .s-card.p0 | ||||||
|  |           ul.my8.ml24 | ||||||
|  |             each row in removedUncachedChannels | ||||||
|  |               li: a(href=`https://discord.com/channels/${guild_id}/${row.channel_id}`)= row.nick || row.name | ||||||
|  |         h3.mt24 Unavailable channels: Wrong type | ||||||
|  |         .s-card.p0 | ||||||
|  |           ul.my8.ml24 | ||||||
|  |             each row in removedWrongTypeChannels | ||||||
|  |               li: a(href=`https://discord.com/channels/${guild_id}/${row.channel_id}`) (#{row.type}) #{row.name} | ||||||
|  |       div- // Rooms | ||||||
|  |         h3.mt24 Unavailable rooms: Already linked | ||||||
|  |         .s-card.p0 | ||||||
|  |           ul.my8.ml24 | ||||||
|  |             each row in removedLinkedRooms | ||||||
|  |               li: a(href=`https://matrix.to/#/${row.room_id}`)= row.name | ||||||
|  |         h3.mt24 Unavailable rooms: Wrong type | ||||||
|  |         .s-card.p0 | ||||||
|  |           ul.my8.ml24 | ||||||
|  |             each row in removedWrongTypeRooms | ||||||
|  |               li: a(href=`https://matrix.to/#/${row.room_id}`) (#{row.room_type}) #{row.name} | ||||||
|  |         h3.mt24 Unavailable rooms: Archived thread | ||||||
|  |         .s-card.p0 | ||||||
|  |           ul.my8.ml24 | ||||||
|  |             each row in removedArchivedThreadRooms | ||||||
|  |               li: a(href=`https://matrix.to/#/${row.room_id}`)= row.name | ||||||
|   | |||||||
| @@ -42,6 +42,26 @@ function getAPI(event) { | |||||||
| /** @type {LRUCache<string, string>} nonce to guild id */ | /** @type {LRUCache<string, string>} nonce to guild id */ | ||||||
| const validNonce = new LRUCache({max: 200}) | const validNonce = new LRUCache({max: 200}) | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Modifies the input, removing items that don't pass the filter. Returns the items that didn't pass. | ||||||
|  |  * @param {T[]} xs | ||||||
|  |  * @param {(x: T, i?: number) => any} fn | ||||||
|  |  * @template T | ||||||
|  |  * @returns T[] | ||||||
|  |  */ | ||||||
|  | function filterTo(xs, fn) { | ||||||
|  | 	/** @type {T[]} */ | ||||||
|  | 	const filtered = [] | ||||||
|  | 	for (let i = xs.length-1; i >= 0; i--) { | ||||||
|  | 		const x = xs[i] | ||||||
|  | 		if (!fn(x, i)) { | ||||||
|  | 			filtered.unshift(x) | ||||||
|  | 			xs.splice(i, 1) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return filtered | ||||||
|  | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @param {string} guildID |  * @param {string} guildID | ||||||
|  * @param {Ty.R.Hierarchy[]} rooms |  * @param {Ty.R.Hierarchy[]} rooms | ||||||
| @@ -62,21 +82,28 @@ function getChannelRoomsLinks(guildID, rooms) { | |||||||
| 	assert(channelIDs) | 	assert(channelIDs) | ||||||
|  |  | ||||||
| 	let linkedChannels = select("channel_room", ["channel_id", "room_id", "name", "nick"], {channel_id: channelIDs}).all() | 	let linkedChannels = select("channel_room", ["channel_id", "room_id", "name", "nick"], {channel_id: channelIDs}).all() | ||||||
| 	let linkedChannelsWithDetails = linkedChannels.map(c => ({channel: discord.channels.get(c.channel_id), ...c})).filter(c => c.channel) | 	let linkedChannelsWithDetails = linkedChannels.map(c => ({channel: discord.channels.get(c.channel_id), ...c})) | ||||||
|  | 	let removedUncachedChannels = filterTo(linkedChannelsWithDetails, c => c.channel) | ||||||
| 	let linkedChannelIDs = linkedChannelsWithDetails.map(c => c.channel_id) | 	let linkedChannelIDs = linkedChannelsWithDetails.map(c => c.channel_id) | ||||||
| 	linkedChannelsWithDetails.sort((a, b) => getPosition(a.channel) - getPosition(b.channel)) | 	linkedChannelsWithDetails.sort((a, b) => getPosition(a.channel) - getPosition(b.channel)) | ||||||
|  |  | ||||||
| 	let unlinkedChannelIDs = channelIDs.filter(c => !linkedChannelIDs.includes(c)) | 	let unlinkedChannelIDs = channelIDs.filter(c => !linkedChannelIDs.includes(c)) | ||||||
| 	let unlinkedChannels = unlinkedChannelIDs.map(c => discord.channels.get(c)).filter(c => c && [0, 5].includes(c.type)) | 	let unlinkedChannels = unlinkedChannelIDs.map(c => discord.channels.get(c)) | ||||||
|  | 	let removedWrongTypeChannels = filterTo(unlinkedChannels, c => c && [0, 5].includes(c.type)) | ||||||
| 	unlinkedChannels.sort((a, b) => getPosition(a) - getPosition(b)) | 	unlinkedChannels.sort((a, b) => getPosition(a) - getPosition(b)) | ||||||
|  |  | ||||||
| 	let linkedRoomIDs = linkedChannels.map(c => c.room_id) | 	let linkedRoomIDs = linkedChannels.map(c => c.room_id) | ||||||
| 	let unlinkedRooms = rooms.filter(r => !linkedRoomIDs.includes(r.room_id) && !r.room_type) | 	let unlinkedRooms = [...rooms] | ||||||
|  | 	let removedLinkedRooms = filterTo(unlinkedRooms, r => !linkedRoomIDs.includes(r.room_id)) | ||||||
|  | 	let removedWrongTypeRooms = filterTo(unlinkedRooms, r => !r.room_type) | ||||||
| 	// https://discord.com/developers/docs/topics/threads#active-archived-threads | 	// https://discord.com/developers/docs/topics/threads#active-archived-threads | ||||||
| 	// need to filter out linked archived threads from unlinkedRooms, will just do that by comparing against the name | 	// need to filter out linked archived threads from unlinkedRooms, will just do that by comparing against the name | ||||||
| 	unlinkedRooms = unlinkedRooms.filter(r => r.name && !r.name.match(/^\[(🔒)?⛓️\]/)) | 	let removedArchivedThreadRooms = filterTo(unlinkedRooms, r => r.name && !r.name.match(/^\[(🔒)?⛓️\]/)) | ||||||
|  |  | ||||||
| 	return {linkedChannelsWithDetails, unlinkedChannels, unlinkedRooms} | 	return { | ||||||
|  | 		linkedChannelsWithDetails, unlinkedChannels, unlinkedRooms, | ||||||
|  | 		removedUncachedChannels, removedWrongTypeChannels, removedLinkedRooms, removedWrongTypeRooms, removedArchivedThreadRooms | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| as.router.get("/guild", defineEventHandler(async event => { | as.router.get("/guild", defineEventHandler(async event => { | ||||||
|   | |||||||
| @@ -63,6 +63,12 @@ as.router.post("/api/link", defineEventHandler(async event => { | |||||||
| 	// Sync room data and space child | 	// Sync room data and space child | ||||||
| 	await createRoom.syncRoom(parsedBody.discord) | 	await createRoom.syncRoom(parsedBody.discord) | ||||||
|  |  | ||||||
|  | 	// Send a notification in the room | ||||||
|  | 	await api.sendEvent(parsedBody.matrix, "m.room.message", { | ||||||
|  | 		msgtype: "m.notice", | ||||||
|  | 		body: "👋 This room is now bridged with Discord. Say hi!" | ||||||
|  | 	}) | ||||||
|  |  | ||||||
| 	setResponseHeader(event, "HX-Refresh", "true") | 	setResponseHeader(event, "HX-Refresh", "true") | ||||||
| 	return null // 204 | 	return null // 204 | ||||||
| })) | })) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Cadence Ember
					Cadence Ember