Cleanup and rename
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
ALTER TABLE channel_room ADD COLUMN room_mention_role TEXT;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
BEGIN TRANSACTION;
|
|
||||||
|
|
||||||
ALTER TABLE channel_room ADD COLUMN ping_role_id TEXT;
|
|
||||||
|
|
||||||
COMMIT;
|
|
||||||
Vendored
+1
-1
@@ -21,7 +21,7 @@ export type Models = {
|
|||||||
speedbump_checked: number | null
|
speedbump_checked: number | null
|
||||||
guild_id: string | null
|
guild_id: string | null
|
||||||
custom_topic: number
|
custom_topic: number
|
||||||
ping_role_id: string | null
|
room_mention_role: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
channel_speedbump: {
|
channel_speedbump: {
|
||||||
|
|||||||
@@ -463,7 +463,7 @@ async function checkWrittenMentions(content, senderMxid, roomID, guild, di) {
|
|||||||
if (writtenMentionMatch[1] === "room") { // convert @room to discord
|
if (writtenMentionMatch[1] === "room") { // convert @room to discord
|
||||||
const {powers: {[senderMxid]: userPower}, powerLevels} = await mxUtils.getEffectivePower(roomID, [senderMxid], di.api)
|
const {powers: {[senderMxid]: userPower}, powerLevels} = await mxUtils.getEffectivePower(roomID, [senderMxid], di.api)
|
||||||
if (userPower >= (powerLevels.notifications?.room ?? 50)) {
|
if (userPower >= (powerLevels.notifications?.room ?? 50)) {
|
||||||
const roleID = select("channel_room", "ping_role_id", {room_id: roomID}).pluck().get()
|
const roleID = select("channel_room", "room_mention_role", {room_id: roomID}).pluck().get()
|
||||||
return {
|
return {
|
||||||
// @ts-ignore - typescript doesn't know about indices yet
|
// @ts-ignore - typescript doesn't know about indices yet
|
||||||
content: content.slice(0, writtenMentionMatch.indices[1][0]-1) + (roleID ? `<@&${roleID}>` : "@everyone") + content.slice(writtenMentionMatch.indices[1][1]),
|
content: content.slice(0, writtenMentionMatch.indices[1][0]-1) + (roleID ? `<@&${roleID}>` : "@everyone") + content.slice(writtenMentionMatch.indices[1][1]),
|
||||||
|
|||||||
+11
-11
@@ -189,8 +189,8 @@ block body
|
|||||||
.s-empty-state No channels linked between Discord and Matrix yet...
|
.s-empty-state No channels linked between Discord and Matrix yet...
|
||||||
|
|
||||||
if space_id && linkedChannelsWithDetails.length
|
if space_id && linkedChannelsWithDetails.length
|
||||||
- const customPingRooms = linkedChannelsWithDetails.filter(row => row.ping_role_id)
|
- const customPingRooms = linkedChannelsWithDetails.filter(row => row.room_mention_role)
|
||||||
- const defaultPingRooms = linkedChannelsWithDetails.filter(row => !row.ping_role_id)
|
- const defaultPingRooms = linkedChannelsWithDetails.filter(row => !row.room_mention_role)
|
||||||
- const pingRoles = [...guild.roles].filter(role => role.id !== guild_id).sort((a, b) => b.position - a.position)
|
- const pingRoles = [...guild.roles].filter(role => role.id !== guild_id).sort((a, b) => b.position - a.position)
|
||||||
h3.mt32.fs-category#room-notifications Room notifications
|
h3.mt32.fs-category#room-notifications Room notifications
|
||||||
.s-card.p0
|
.s-card.p0
|
||||||
@@ -209,20 +209,20 @@ block body
|
|||||||
+discord(row.channel)
|
+discord(row.channel)
|
||||||
td.pr12
|
td.pr12
|
||||||
.d-flex.ai-start.g8
|
.d-flex.ai-start.g8
|
||||||
form.fl-grow1.wmn0.d-flex.ai-stretch.g8(method="post" action=rel("/api/room-ping-role"))
|
form.fl-grow1.wmn0.d-flex.ai-stretch.g8(method="post" action=rel("/api/room-mention-role"))
|
||||||
input(type="hidden" name="guild_id" value=guild_id)
|
input(type="hidden" name="guild_id" value=guild_id)
|
||||||
input(type="hidden" name="channel_id" value=row.channel.id)
|
input(type="hidden" name="channel_id" value=row.channel.id)
|
||||||
.s-select.fl-grow1.wmn0
|
.s-select.fl-grow1.wmn0
|
||||||
select.w100(name="ping_role_id" id="ping-role-" + row.channel.id aria-label="Notify role for #" + row.channel.name onchange="this.form.requestSubmit()" style="height: 32px")
|
select.w100(name="room_mention_role" id="ping-role-" + row.channel.id aria-label="Notify role for #" + row.channel.name onchange="this.form.requestSubmit()" style="height: 32px")
|
||||||
if !pingRoles.some(role => role.id === row.ping_role_id)
|
if !pingRoles.some(role => role.id === row.room_mention_role)
|
||||||
option(value=row.ping_role_id selected disabled) Deleted role (choose a replacement)
|
option(value=row.room_mention_role selected disabled) Deleted role (choose a replacement)
|
||||||
each role in pingRoles
|
each role in pingRoles
|
||||||
option(value=role.id selected=row.ping_role_id === role.id)= "@" + role.name
|
option(value=role.id selected=row.room_mention_role === role.id)= "@" + role.name
|
||||||
button.s-btn.s-btn__outlined.py0.box-border(type="submit" data-room-ping-save style="height: 32px; min-height: 0") Save
|
button.s-btn.s-btn__outlined.py0.box-border(type="submit" data-room-ping-save style="height: 32px; min-height: 0") Save
|
||||||
form.d-flex.ai-stretch(method="post" action=rel("/api/room-ping-role"))
|
form.d-flex.ai-stretch(method="post" action=rel("/api/room-mention-role"))
|
||||||
input(type="hidden" name="guild_id" value=guild_id)
|
input(type="hidden" name="guild_id" value=guild_id)
|
||||||
input(type="hidden" name="channel_id" value=row.channel.id)
|
input(type="hidden" name="channel_id" value=row.channel.id)
|
||||||
input(type="hidden" name="ping_role_id" value="")
|
input(type="hidden" name="room_mention_role" value="")
|
||||||
button.s-btn.s-btn__danger.s-btn__outlined.py0(type="submit" aria-label="Remove custom role for #" + row.channel.name style="height: 32px") Remove
|
button.s-btn.s-btn__danger.s-btn__outlined.py0(type="submit" aria-label="Remove custom role for #" + row.channel.name style="height: 32px") Remove
|
||||||
|
|
||||||
script.
|
script.
|
||||||
@@ -231,7 +231,7 @@ block body
|
|||||||
if defaultPingRooms.length && pingRoles.length
|
if defaultPingRooms.length && pingRoles.length
|
||||||
details.mt16.mx12.mb12
|
details.mt16.mx12.mb12
|
||||||
summary.s-label.cursor-pointer Add custom role
|
summary.s-label.cursor-pointer Add custom role
|
||||||
form.mt16(method="post" action=rel("/api/room-ping-role"))
|
form.mt16(method="post" action=rel("/api/room-mention-role"))
|
||||||
input(type="hidden" name="guild_id" value=guild_id)
|
input(type="hidden" name="guild_id" value=guild_id)
|
||||||
.d-flex.fw-wrap.ai-end.g16
|
.d-flex.fw-wrap.ai-end.g16
|
||||||
.fl-grow1.wmn0(style="flex-basis: 0; min-width: 180px")
|
.fl-grow1.wmn0(style="flex-basis: 0; min-width: 180px")
|
||||||
@@ -245,7 +245,7 @@ block body
|
|||||||
.fl-grow1.wmn0(style="flex-basis: 0; min-width: 180px")
|
.fl-grow1.wmn0(style="flex-basis: 0; min-width: 180px")
|
||||||
label.s-label(for="ping-role-new") Notify role
|
label.s-label(for="ping-role-new") Notify role
|
||||||
.s-select
|
.s-select
|
||||||
select.w100.box-border#ping-role-new(name="ping_role_id" required style="height: 32px")
|
select.w100.box-border#ping-role-new(name="room_mention_role" required style="height: 32px")
|
||||||
option(value="" selected disabled) Choose a role
|
option(value="" selected disabled) Choose a role
|
||||||
each role in pingRoles
|
each role in pingRoles
|
||||||
option(value=role.id)= "@" + role.name
|
option(value=role.id)= "@" + role.name
|
||||||
|
|||||||
@@ -142,20 +142,20 @@ as.router.post("/api/default-roles", defineEventHandler(async event => {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
// An empty role restores @everyone
|
// An empty role restores @everyone
|
||||||
as.router.post("/api/room-ping-role", defineEventHandler(async event => {
|
as.router.post("/api/room-mention-role", defineEventHandler(async event => {
|
||||||
const body = await readValidatedBody(event, z.object({
|
const body = await readValidatedBody(event, z.object({
|
||||||
guild_id: z.string(),
|
guild_id: z.string(),
|
||||||
channel_id: z.string(),
|
channel_id: z.string(),
|
||||||
ping_role_id: z.string().regex(/^(?:[0-9]+)?$/)
|
room_mention_role: z.string().regex(/^(?:[0-9]+)?$/)
|
||||||
}).parse)
|
}).parse)
|
||||||
const managed = await auth.getManagedGuilds(event)
|
const managed = await auth.getManagedGuilds(event)
|
||||||
if (!managed.has(body.guild_id)) throw createError({status: 403, message: "Forbidden", data: "Can't change settings for a guild you don't have Manage Server permissions in"})
|
if (!managed.has(body.guild_id)) throw createError({status: 403, message: "Forbidden", data: "Can't change settings for a guild you don't have Manage Server permissions in"})
|
||||||
const room = select("channel_room", "room_id", {channel_id: body.channel_id, guild_id: body.guild_id}).get()
|
const room = select("channel_room", "room_id", {channel_id: body.channel_id, guild_id: body.guild_id}).get()
|
||||||
if (!room) throw createError({status: 404, message: "Linked channel not found"})
|
if (!room) throw createError({status: 404, message: "Linked channel not found"})
|
||||||
const guild = discord.guilds.get(body.guild_id)
|
const guild = discord.guilds.get(body.guild_id)
|
||||||
if (body.ping_role_id && (!guild?.roles.some(role => role.id === body.ping_role_id) || body.ping_role_id === body.guild_id)) {
|
if (body.room_mention_role && (!guild?.roles.some(role => role.id === body.room_mention_role) || body.room_mention_role === body.guild_id)) {
|
||||||
throw createError({status: 400, message: "Choose a role from this server"})
|
throw createError({status: 400, message: "Choose a role from this server"})
|
||||||
}
|
}
|
||||||
db.prepare("UPDATE channel_room SET ping_role_id = ? WHERE channel_id = ? AND guild_id = ?").run(body.ping_role_id || null, body.channel_id, body.guild_id)
|
db.prepare("UPDATE channel_room SET room_mention_role = ? WHERE channel_id = ? AND guild_id = ?").run(body.room_mention_role || null, body.channel_id, body.guild_id)
|
||||||
return sendRedirect(event, `/guild?guild_id=${body.guild_id}#room-notifications`, 302)
|
return sendRedirect(event, `/guild?guild_id=${body.guild_id}#room-notifications`, 302)
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ function getChannelRoomsLinks(guild, rooms, roles) {
|
|||||||
let channelIDs = discord.guildChannelMap.get(guild.id)
|
let channelIDs = discord.guildChannelMap.get(guild.id)
|
||||||
assert(channelIDs)
|
assert(channelIDs)
|
||||||
|
|
||||||
let linkedChannels = select("channel_room", ["channel_id", "room_id", "name", "nick", "ping_role_id"], {channel_id: channelIDs}).all()
|
let linkedChannels = select("channel_room", ["channel_id", "room_id", "name", "nick", "room_mention_role"], {channel_id: channelIDs}).all()
|
||||||
let linkedChannelsWithDetails = linkedChannels.map(c => ({
|
let linkedChannelsWithDetails = linkedChannels.map(c => ({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
/** @type {DiscordTypes.APIGuildChannel} */ channel: discord.channels.get(c.channel_id),
|
/** @type {DiscordTypes.APIGuildChannel} */ channel: discord.channels.get(c.channel_id),
|
||||||
|
|||||||
Reference in New Issue
Block a user