Fix typecheck

This commit is contained in:
Cadence Ember
2026-02-11 11:31:27 +13:00
parent 33eef25cf1
commit c4909653aa
21 changed files with 117 additions and 65 deletions
+4 -3
View File
@@ -196,9 +196,10 @@ async function getInviteState(roomID, event) {
}
// Try calling sliding sync API and extracting from stripped state
let root
try {
/** @type {Ty.R.SSS} */
var root = await mreq.mreq("POST", path("/client/unstable/org.matrix.simplified_msc3575/sync", `@${reg.sender_localpart}:${reg.ooye.server_name}`, {timeout: "0"}), {
root = await mreq.mreq("POST", path("/client/unstable/org.matrix.simplified_msc3575/sync", `@${reg.sender_localpart}:${reg.ooye.server_name}`, {timeout: "0"}), {
lists: {
a: {
ranges: [[0, 999]],
@@ -239,7 +240,7 @@ async function getInviteState(roomID, event) {
name: room.name ?? null,
topic: room.topic ?? null,
avatar: room.avatar_url ?? null,
type: room.room_type
type: room.room_type ?? null
}
}
@@ -426,7 +427,7 @@ async function profileSetDisplayname(mxid, displayname, inhibitPropagate) {
/**
* @param {string} mxid
* @param {string} avatar_url
* @param {string | null | undefined} avatar_url
* @param {boolean} [inhibitPropagate]
*/
async function profileSetAvatarUrl(mxid, avatar_url, inhibitPropagate) {
+1 -1
View File
@@ -124,7 +124,7 @@ const commands = [{
if (matrixOnlyReason) {
// If uploading to Matrix, check if we have permission
const {powerLevels, powers: {[mxUtils.bot]: botPower}} = await mxUtils.getEffectivePower(event.room_id, [mxUtils.bot], api)
const requiredPower = powerLevels.events["im.ponies.room_emotes"] ?? powerLevels.state_default ?? 50
const requiredPower = powerLevels.events?.["im.ponies.room_emotes"] ?? powerLevels.state_default ?? 50
if (botPower < requiredPower) {
return api.sendEvent(event.room_id, "m.room.message", {
...ctx,
+2 -2
View File
@@ -57,12 +57,12 @@ async function onBotMembership(event, api, createRoom) {
// Check if an upgrade is pending for this room
const newRoomID = event.room_id
const oldRoomID = select("room_upgrade_pending", "old_room_id", {new_room_id: newRoomID}).pluck().get()
if (!oldRoomID) return
if (!oldRoomID) return false
const channelRow = from("channel_room").join("guild_space", "guild_id").where({room_id: oldRoomID}).select("space_id", "guild_id", "channel_id").get()
assert(channelRow) // this could only fail if the channel was unbridged or something between upgrade and joining
// Check if is join/invite
if (event.content.membership !== "invite" && event.content.membership !== "join") return
if (event.content.membership !== "invite" && event.content.membership !== "join") return false
return await roomUpgradeSema.request(async () => {
// If invited, join
+24 -3
View File
@@ -60,6 +60,26 @@ function getEventIDHash(eventID) {
return signedHash
}
class MatrixStringBuilderStack {
constructor() {
this.stack = [new MatrixStringBuilder()]
}
get msb() {
return this.stack[0]
}
bump() {
this.stack.unshift(new MatrixStringBuilder())
}
shift() {
const msb = this.stack.shift()
assert(msb)
return msb
}
}
class MatrixStringBuilder {
constructor() {
this.body = ""
@@ -228,7 +248,7 @@ function generatePermittedMediaHash(mxc) {
* @see https://matrix.org/blog/2024/06/26/sunsetting-unauthenticated-media/ background
* @see https://matrix.org/blog/2024/06/20/matrix-v1.11-release/ implementation details
* @see https://www.sqlite.org/fileformat2.html#record_format SQLite integer field size
* @param {string} mxc
* @param {string | null | undefined} mxc
* @returns {string | undefined}
*/
function getPublicUrlForMxc(mxc) {
@@ -238,7 +258,7 @@ function getPublicUrlForMxc(mxc) {
}
/**
* @param {string} mxc
* @param {string | null | undefined} mxc
* @returns {string | undefined} mxc URL with protocol stripped, e.g. "cadence.moe/abcdef1234"
*/
function makeMxcPublic(mxc) {
@@ -289,7 +309,7 @@ function roomHasAtLeastVersion(roomVersionString, desiredVersion) {
*/
function removeCreatorsFromPowerLevels(roomCreateOuter, powerLevels) {
assert(roomCreateOuter.sender)
if (roomHasAtLeastVersion(roomCreateOuter.content.room_version, 12)) {
if (roomHasAtLeastVersion(roomCreateOuter.content.room_version, 12) && powerLevels.users) {
for (const creator of (roomCreateOuter.content.additional_creators ?? []).concat(roomCreateOuter.sender)) {
delete powerLevels.users[creator]
}
@@ -385,6 +405,7 @@ module.exports.makeMxcPublic = makeMxcPublic
module.exports.getPublicUrlForMxc = getPublicUrlForMxc
module.exports.getEventIDHash = getEventIDHash
module.exports.MatrixStringBuilder = MatrixStringBuilder
module.exports.MatrixStringBuilderStack = MatrixStringBuilderStack
module.exports.getViaServers = getViaServers
module.exports.getViaServersQuery = getViaServersQuery
module.exports.roomHasAtLeastVersion = roomHasAtLeastVersion