WIP: feature: threads'n'forums #74

Draft
Guzio wants to merge 109 commits from Guzio/out-of-your-element:mergable-fr-fr into main
Showing only changes of commit e95df09c5d - Show all commits

View file

@ -84,13 +84,14 @@ 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
} }