d->m: Support permissioned @everyone -> @room
This only works if #9 is fixed in the future.
This commit is contained in:
parent
e2d0ea41d5
commit
2fb68900c7
3 changed files with 220 additions and 1 deletions
|
@ -249,6 +249,8 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
let repliedToEventRow = null
|
let repliedToEventRow = null
|
||||||
let repliedToEventSenderMxid = null
|
let repliedToEventSenderMxid = null
|
||||||
|
|
||||||
|
if (message.mention_everyone) mentions.room = true
|
||||||
|
|
||||||
function addMention(mxid) {
|
function addMention(mxid) {
|
||||||
if (!mentions.user_ids) mentions.user_ids = []
|
if (!mentions.user_ids) mentions.user_ids = []
|
||||||
if (!mentions.user_ids.includes(mxid)) mentions.user_ids.push(mxid)
|
if (!mentions.user_ids.includes(mxid)) mentions.user_ids.push(mxid)
|
||||||
|
@ -480,7 +482,7 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
|
|
||||||
// Mentions scenario 3: scan the message content for written @mentions of matrix users. Allows for up to one space between @ and mention.
|
// Mentions scenario 3: scan the message content for written @mentions of matrix users. Allows for up to one space between @ and mention.
|
||||||
const matches = [...message.content.matchAll(/@ ?([a-z0-9._]+)\b/gi)]
|
const matches = [...message.content.matchAll(/@ ?([a-z0-9._]+)\b/gi)]
|
||||||
if (matches.length && matches.some(m => m[1].match(/[a-z]/i))) {
|
if (matches.length && matches.some(m => m[1].match(/[a-z]/i) && m[1] !== "everyone" && m[1] !== "here")) {
|
||||||
const writtenMentionsText = matches.map(m => m[1].toLowerCase())
|
const writtenMentionsText = matches.map(m => m[1].toLowerCase())
|
||||||
const roomID = select("channel_room", "room_id", {channel_id: message.channel_id}).pluck().get()
|
const roomID = select("channel_room", "room_id", {channel_id: message.channel_id}).pluck().get()
|
||||||
assert(roomID)
|
assert(roomID)
|
||||||
|
|
|
@ -789,3 +789,63 @@ test("message2event: crossposted announcements say where they are crossposted fr
|
||||||
formatted_body: "🔀 <strong>Chewey Bot Official Server #announcements</strong><br>All text based commands are now inactive on Chewey Bot<br>To continue using commands you'll need to use them as slash commands"
|
formatted_body: "🔀 <strong>Chewey Bot Official Server #announcements</strong><br>All text based commands are now inactive on Chewey Bot<br>To continue using commands you'll need to use them as slash commands"
|
||||||
}])
|
}])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("message2event: @everyone", async t => {
|
||||||
|
const events = await messageToEvent(data.message_mention_everyone.at_everyone)
|
||||||
|
t.deepEqual(events, [{
|
||||||
|
$type: "m.room.message",
|
||||||
|
msgtype: "m.text",
|
||||||
|
body: "@room",
|
||||||
|
"m.mentions": {
|
||||||
|
room: true
|
||||||
|
}
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
||||||
|
test("message2event: @here", async t => {
|
||||||
|
const events = await messageToEvent(data.message_mention_everyone.at_here)
|
||||||
|
t.deepEqual(events, [{
|
||||||
|
$type: "m.room.message",
|
||||||
|
msgtype: "m.text",
|
||||||
|
body: "@room",
|
||||||
|
"m.mentions": {
|
||||||
|
room: true
|
||||||
|
}
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
||||||
|
test("message2event: @everyone without permission", async t => {
|
||||||
|
const events = await messageToEvent(data.message_mention_everyone.at_everyone_without_permission)
|
||||||
|
t.deepEqual(events, [{
|
||||||
|
$type: "m.room.message",
|
||||||
|
msgtype: "m.text",
|
||||||
|
body: "@everyone <-- this is testing that it DOESN'T mention. if this mentions everyone then my apologies.",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: "@everyone <-- this is testing that it DOESN'T mention. if this mentions everyone then my apologies.",
|
||||||
|
"m.mentions": {}
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
||||||
|
test("message2event: @here without permission", async t => {
|
||||||
|
const events = await messageToEvent(data.message_mention_everyone.at_here_without_permission)
|
||||||
|
t.deepEqual(events, [{
|
||||||
|
$type: "m.room.message",
|
||||||
|
msgtype: "m.text",
|
||||||
|
body: "@here <-- this is testing that it DOESN'T mention. if this mentions people then my apologies.",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: "@here <-- this is testing that it DOESN'T mention. if this mentions people then my apologies.",
|
||||||
|
"m.mentions": {}
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
||||||
|
test("message2event: @everyone within a link", async t => {
|
||||||
|
const events = await messageToEvent(data.message_mention_everyone.at_everyone_within_link)
|
||||||
|
t.deepEqual(events, [{
|
||||||
|
$type: "m.room.message",
|
||||||
|
msgtype: "m.text",
|
||||||
|
body: "https://github.com/@everyone",
|
||||||
|
format: "org.matrix.custom.html",
|
||||||
|
formatted_body: `<a href="https://github.com/@everyone">https://github.com/@everyone</a>`,
|
||||||
|
"m.mentions": {}
|
||||||
|
}])
|
||||||
|
})
|
||||||
|
|
157
test/data.js
157
test/data.js
|
@ -1925,6 +1925,163 @@ module.exports = {
|
||||||
webhook_id: "1195662438662680720"
|
webhook_id: "1195662438662680720"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
message_mention_everyone: {
|
||||||
|
at_everyone: {
|
||||||
|
id: "1214510099058655252",
|
||||||
|
type: 0,
|
||||||
|
content: "@everyone",
|
||||||
|
channel_id: "1100319550446252084",
|
||||||
|
author: {
|
||||||
|
id: "772659086046658620",
|
||||||
|
username: "cadence.worm",
|
||||||
|
avatar: "4b5c4b28051144e4c111f0113a0f1cf1",
|
||||||
|
discriminator: "0",
|
||||||
|
public_flags: 0,
|
||||||
|
premium_type: 0,
|
||||||
|
flags: 0,
|
||||||
|
banner: null,
|
||||||
|
accent_color: null,
|
||||||
|
global_name: "cadence",
|
||||||
|
avatar_decoration_data: null,
|
||||||
|
banner_color: null
|
||||||
|
},
|
||||||
|
attachments: [],
|
||||||
|
embeds: [],
|
||||||
|
mentions: [],
|
||||||
|
mention_roles: [],
|
||||||
|
pinned: false,
|
||||||
|
mention_everyone: true,
|
||||||
|
tts: false,
|
||||||
|
timestamp: "2024-03-05T09:49:32.122000+00:00",
|
||||||
|
edited_timestamp: null,
|
||||||
|
flags: 0,
|
||||||
|
components: []
|
||||||
|
},
|
||||||
|
at_here: {
|
||||||
|
id: "1214510192230797332",
|
||||||
|
type: 0,
|
||||||
|
content: "@here",
|
||||||
|
channel_id: "1100319550446252084",
|
||||||
|
author: {
|
||||||
|
id: "772659086046658620",
|
||||||
|
username: "cadence.worm",
|
||||||
|
avatar: "4b5c4b28051144e4c111f0113a0f1cf1",
|
||||||
|
discriminator: "0",
|
||||||
|
public_flags: 0,
|
||||||
|
premium_type: 0,
|
||||||
|
flags: 0,
|
||||||
|
banner: null,
|
||||||
|
accent_color: null,
|
||||||
|
global_name: "cadence",
|
||||||
|
avatar_decoration_data: null,
|
||||||
|
banner_color: null
|
||||||
|
},
|
||||||
|
attachments: [],
|
||||||
|
embeds: [],
|
||||||
|
mentions: [],
|
||||||
|
mention_roles: [],
|
||||||
|
pinned: false,
|
||||||
|
mention_everyone: true,
|
||||||
|
tts: false,
|
||||||
|
timestamp: "2024-03-05T09:49:54.336000+00:00",
|
||||||
|
edited_timestamp: null,
|
||||||
|
flags: 0,
|
||||||
|
components: []
|
||||||
|
},
|
||||||
|
at_everyone_without_permission: {
|
||||||
|
id: "1214510346623258654",
|
||||||
|
type: 0,
|
||||||
|
content: "@everyone <-- this is testing that it DOESN'T mention. if this mentions everyone then my apologies.",
|
||||||
|
channel_id: "112760669178241024",
|
||||||
|
author: {
|
||||||
|
id: "772659086046658620",
|
||||||
|
username: "cadence.worm",
|
||||||
|
avatar: "4b5c4b28051144e4c111f0113a0f1cf1",
|
||||||
|
discriminator: "0",
|
||||||
|
public_flags: 0,
|
||||||
|
premium_type: 0,
|
||||||
|
flags: 0,
|
||||||
|
banner: null,
|
||||||
|
accent_color: null,
|
||||||
|
global_name: "cadence",
|
||||||
|
avatar_decoration_data: null,
|
||||||
|
banner_color: null
|
||||||
|
},
|
||||||
|
attachments: [],
|
||||||
|
embeds: [],
|
||||||
|
mentions: [],
|
||||||
|
mention_roles: [],
|
||||||
|
pinned: false,
|
||||||
|
mention_everyone: false,
|
||||||
|
tts: false,
|
||||||
|
timestamp: "2024-03-05T09:50:31.146000+00:00",
|
||||||
|
edited_timestamp: null,
|
||||||
|
flags: 0,
|
||||||
|
components: []
|
||||||
|
},
|
||||||
|
at_here_without_permission: {
|
||||||
|
id: "1214510346623258654",
|
||||||
|
type: 0,
|
||||||
|
content: "@here <-- this is testing that it DOESN'T mention. if this mentions people then my apologies.",
|
||||||
|
channel_id: "112760669178241024",
|
||||||
|
author: {
|
||||||
|
id: "772659086046658620",
|
||||||
|
username: "cadence.worm",
|
||||||
|
avatar: "4b5c4b28051144e4c111f0113a0f1cf1",
|
||||||
|
discriminator: "0",
|
||||||
|
public_flags: 0,
|
||||||
|
premium_type: 0,
|
||||||
|
flags: 0,
|
||||||
|
banner: null,
|
||||||
|
accent_color: null,
|
||||||
|
global_name: "cadence",
|
||||||
|
avatar_decoration_data: null,
|
||||||
|
banner_color: null
|
||||||
|
},
|
||||||
|
attachments: [],
|
||||||
|
embeds: [],
|
||||||
|
mentions: [],
|
||||||
|
mention_roles: [],
|
||||||
|
pinned: false,
|
||||||
|
mention_everyone: false,
|
||||||
|
tts: false,
|
||||||
|
timestamp: "2024-03-05T09:50:31.146000+00:00",
|
||||||
|
edited_timestamp: null,
|
||||||
|
flags: 0,
|
||||||
|
components: []
|
||||||
|
},
|
||||||
|
at_everyone_within_link: {
|
||||||
|
id: "1214510225885888563",
|
||||||
|
type: 0,
|
||||||
|
content: "https://github.com/@everyone",
|
||||||
|
channel_id: "1100319550446252084",
|
||||||
|
author: {
|
||||||
|
id: "772659086046658620",
|
||||||
|
username: "cadence.worm",
|
||||||
|
avatar: "4b5c4b28051144e4c111f0113a0f1cf1",
|
||||||
|
discriminator: "0",
|
||||||
|
public_flags: 0,
|
||||||
|
premium_type: 0,
|
||||||
|
flags: 0,
|
||||||
|
banner: null,
|
||||||
|
accent_color: null,
|
||||||
|
global_name: "cadence",
|
||||||
|
avatar_decoration_data: null,
|
||||||
|
banner_color: null
|
||||||
|
},
|
||||||
|
attachments: [],
|
||||||
|
embeds: [],
|
||||||
|
mentions: [],
|
||||||
|
mention_roles: [],
|
||||||
|
pinned: false,
|
||||||
|
mention_everyone: false,
|
||||||
|
tts: false,
|
||||||
|
timestamp: "2024-03-05T09:50:02.360000+00:00",
|
||||||
|
edited_timestamp: null,
|
||||||
|
flags: 0,
|
||||||
|
components: []
|
||||||
|
}
|
||||||
|
},
|
||||||
message_with_embeds: {
|
message_with_embeds: {
|
||||||
nothing_but_a_field: {
|
nothing_but_a_field: {
|
||||||
guild_id: "497159726455455754",
|
guild_id: "497159726455455754",
|
||||||
|
|
Loading…
Reference in a new issue