Compare commits

...

2 commits

View file

@ -57,7 +57,7 @@ async function bridgeThread(event) {
return true; return true;
} }
catch (e){ catch (e){
if (e.message?.includes("50024")){ if (e.message?.includes("50024")){ // see: https://docs.discord.com/developers/topics/opcodes-and-status-codes
api.sendEvent(event.room_id, "m.room.message", { api.sendEvent(event.room_id, "m.room.message", {
body: "Hey, please don't do that! This room is already a thread on Discord - trying to embed threads inside it will not work. The user will just see a regular reply.", body: "Hey, please don't do that! This room is already a thread on Discord - trying to embed threads inside it will not work. The user will just see a regular reply.",
"m.mentions": { "user_ids": [event.sender]}, "m.mentions": { "user_ids": [event.sender]},
@ -82,15 +82,16 @@ async function bridgeThread(event) {
*/ */
async function handleForums(event) { async function handleForums(event) {
if (event.content.body === "/thread") return false; //Let the help be shown normally if (event.content.body === "/thread") return false; //Let the help be shown normally
const row = from("channel_room").where({room_id: event.room_id}).select("channel_id").get() const row = from("channel_room").where({room_id: event.room_id}).select("channel_id").get()
/** @type {string}*/ //@ts-ignore the possibility that it's undefined: get() will return back an undefined if it's fed one (so that's undefined-safe), and createThreadWithoutMessage() won't be reached because "undefined" is neither DiscordTypes.ChannelType.GuildMedia nor DiscordTypes.ChannelType.GuildForum, so the guard clause kicks in. /** @type {string}*/ //@ts-ignore the possibility that it's undefined - get() will return back an undefined if it's fed one (so that's undefined-safe), and createThreadWithoutMessage() won't be reached because "undefined" is neither DiscordTypes.ChannelType.GuildMedia nor DiscordTypes.ChannelType.GuildForum, so the guard clause kicks in.
let channelID = row?.channel_id let channelID = row?.channel_id
const type = discord.channels.get(channelID)?.type const type = discord.channels.get(channelID)?.type
if (type != DiscordTypes.ChannelType.GuildForum && type != DiscordTypes.ChannelType.GuildMedia) return false if (type != DiscordTypes.ChannelType.GuildForum && type != DiscordTypes.ChannelType.GuildMedia) return false
const name = computeName(event) const name = computeName(event)
await discord.snow.channel.createThreadWithoutMessage(channelID, {name: name.name, type:11}) //@ts-ignore the presence of message:{} and the absence of type:11 - that's intended for threads in Forum channels (*and no, createThreadWithMessage wouldn't work here, either - that one takes an ALREADY EXISTING message ID, whereas this needs a new message)
await discord.snow.channel.createThreadWithoutMessage(channelID, {name: name.name, message:{content:"heyy~"}})
if (!name.truncated) api.redactEvent(event.room_id, event.event_id) //Don't destroy people's texts - only remove if no truncation is guaranteed. if (!name.truncated) api.redactEvent(event.room_id, event.event_id) //Don't destroy people's texts - only remove if no truncation is guaranteed.
return true return true
} }