forked from cadence/out-of-your-element
Compare commits
2 commits
d52794e22c
...
e95df09c5d
| Author | SHA1 | Date | |
|---|---|---|---|
| e95df09c5d | |||
| 2d82734a06 |
1 changed files with 5 additions and 4 deletions
|
|
@ -57,7 +57,7 @@ async function bridgeThread(event) {
|
|||
return true;
|
||||
}
|
||||
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", {
|
||||
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]},
|
||||
|
|
@ -84,13 +84,14 @@ async function handleForums(event) {
|
|||
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()
|
||||
/** @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
|
||||
const type = discord.channels.get(channelID)?.type
|
||||
if (type != DiscordTypes.ChannelType.GuildForum && type != DiscordTypes.ChannelType.GuildMedia) return false
|
||||
|
||||
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.
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue