2023-05-12 05:35:37 +00:00
const { test } = require ( "supertape" )
const { messageToEvent } = require ( "./message-to-event" )
const data = require ( "../../test/data" )
2023-07-11 04:51:30 +00:00
const Ty = require ( "../../types" )
/ * *
* @ param { string } roomID
* @ param { string } eventID
* @ returns { ( roomID : string , eventID : string ) => Promise < Ty . Event . Outer < Ty . Event . M _Room _Message >> }
* /
function mockGetEvent ( t , roomID _in , eventID _in , outer ) {
return async function ( roomID , eventID ) {
t . equal ( roomID , roomID _in )
t . equal ( eventID , eventID _in )
return new Promise ( resolve => {
setTimeout ( ( ) => {
resolve ( {
event _id : eventID _in ,
room _id : roomID _in ,
origin _server _ts : 1680000000000 ,
unsigned : {
age : 2245 ,
transaction _id : "$local.whatever"
} ,
... outer
} )
} )
} )
}
}
2023-05-12 05:35:37 +00:00
2023-07-07 05:31:39 +00:00
test ( "message2event: simple plaintext" , async t => {
2023-08-16 08:44:38 +00:00
const events = await messageToEvent ( data . message . simple _plaintext , data . guild . general , { } )
2023-07-07 07:28:23 +00:00
t . deepEqual ( events , [ {
$type : "m.room.message" ,
2023-07-11 04:51:30 +00:00
"m.mentions" : { } ,
2023-07-07 07:28:23 +00:00
msgtype : "m.text" ,
body : "ayy lmao"
} ] )
2023-07-07 05:31:39 +00:00
} )
2023-08-17 13:22:33 +00:00
test ( "message2event: simple plaintext with quotes" , async t => {
const events = await messageToEvent ( data . message . simple _plaintext _with _quotes , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : ` then he said, "you and her aren't allowed in here!" `
} ] )
} )
2023-07-07 05:31:39 +00:00
test ( "message2event: simple user mention" , async t => {
2023-08-16 08:44:38 +00:00
const events = await messageToEvent ( data . message . simple _user _mention , data . guild . general , { } )
2023-07-07 07:28:23 +00:00
t . deepEqual ( events , [ {
$type : "m.room.message" ,
2023-07-11 04:51:30 +00:00
"m.mentions" : { } ,
2023-07-07 07:28:23 +00:00
msgtype : "m.text" ,
body : "@crunch god: Tell me about Phil, renowned martial arts master and creator of the Chin Trick" ,
format : "org.matrix.custom.html" ,
formatted _body : '<a href="https://matrix.to/#/@_ooye_crunch_god:cadence.moe">@crunch god</a> Tell me about Phil, renowned martial arts master and creator of the Chin Trick'
} ] )
2023-07-07 05:31:39 +00:00
} )
2023-07-10 20:01:11 +00:00
test ( "message2event: simple room mention" , async t => {
2024-02-12 19:27:58 +00:00
let called = 0
const events = await messageToEvent ( data . message . simple _room _mention , data . guild . general , { } , {
api : {
async getStateEvent ( roomID , type , key ) {
called ++
t . equal ( roomID , "!kLRqKKUQXcibIMtOpl:cadence.moe" )
t . equal ( type , "m.room.power_levels" )
t . equal ( key , "" )
return {
users : {
"@_ooye_bot:cadence.moe" : 100
}
}
} ,
async getJoinedMembers ( roomID ) {
called ++
t . equal ( roomID , "!kLRqKKUQXcibIMtOpl:cadence.moe" )
return {
joined : {
"@_ooye_bot:cadence.moe" : { display _name : null , avatar _url : null } ,
"@user:matrix.org" : { display _name : null , avatar _url : null }
}
}
}
}
} )
2023-07-10 20:01:11 +00:00
t . deepEqual ( events , [ {
$type : "m.room.message" ,
2023-07-11 04:51:30 +00:00
"m.mentions" : { } ,
2023-07-10 20:01:11 +00:00
msgtype : "m.text" ,
2023-07-10 22:10:47 +00:00
body : "#main" ,
2023-07-10 20:01:11 +00:00
format : "org.matrix.custom.html" ,
2024-02-12 19:27:58 +00:00
formatted _body : '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe?via=cadence.moe&via=matrix.org">#main</a>'
2023-07-10 20:01:11 +00:00
} ] )
2024-02-13 03:52:21 +00:00
t . equal ( called , 2 , "should call getStateEvent and getJoinedMembers once each" )
2023-10-13 13:15:21 +00:00
} )
2024-01-18 23:37:13 +00:00
test ( "message2event: unknown room mention" , async t => {
const events = await messageToEvent ( data . message . unknown _room _mention , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
2024-02-13 22:57:01 +00:00
body : "#unknown-channel [channel from an unbridged server]"
} ] )
} )
test ( "message2event: unbridged room mention" , async t => {
const events = await messageToEvent ( data . message . unbridged _room _mention , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "#bad-boots-prison [channel not bridged]"
2024-01-18 23:37:13 +00:00
} ] )
} )
2023-10-13 13:15:21 +00:00
test ( "message2event: simple role mentions" , async t => {
const events = await messageToEvent ( data . message . simple _role _mentions , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "I'm just @!!DLCS!!: testing a few role pings @Master Wonder Mage: don't mind me" ,
format : "org.matrix.custom.html" ,
formatted _body : ` I'm just <font color="#a901ff">@!!DLCS!!</font> testing a few role pings <span data-mx-color="#ffffff" data-mx-bg-color="#414eef">@Master Wonder Mage</span> don't mind me `
} ] )
2023-07-10 20:01:11 +00:00
} )
2023-11-23 02:52:41 +00:00
test ( "message2event: manually constructed unknown roles should use fallback" , async t => {
const events = await messageToEvent ( data . message . unknown _role , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "I'm just @&4 testing a few role pings <@&B> don't mind me" ,
format : "org.matrix.custom.html" ,
formatted _body : "I'm just @&4 testing a few role pings <@&B> don't mind me"
} ] )
} )
2023-07-10 20:01:11 +00:00
test ( "message2event: simple message link" , async t => {
2024-02-13 03:52:21 +00:00
let called = 0
const events = await messageToEvent ( data . message . simple _message _link , data . guild . general , { } , {
api : {
async getStateEvent ( roomID , type , key ) {
called ++
t . equal ( roomID , "!kLRqKKUQXcibIMtOpl:cadence.moe" )
t . equal ( type , "m.room.power_levels" )
t . equal ( key , "" )
return {
users : {
"@_ooye_bot:cadence.moe" : 100
}
}
} ,
async getJoinedMembers ( roomID ) {
called ++
t . equal ( roomID , "!kLRqKKUQXcibIMtOpl:cadence.moe" )
return {
joined : {
"@_ooye_bot:cadence.moe" : { display _name : null , avatar _url : null } ,
"@user:super.invalid" : { display _name : null , avatar _url : null }
}
}
}
}
} )
2023-07-10 20:01:11 +00:00
t . deepEqual ( events , [ {
$type : "m.room.message" ,
2023-07-11 04:51:30 +00:00
"m.mentions" : { } ,
2023-07-10 20:01:11 +00:00
msgtype : "m.text" ,
2024-02-13 03:52:21 +00:00
body : "https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg?via=cadence.moe&via=super.invalid" ,
2023-07-10 20:01:11 +00:00
format : "org.matrix.custom.html" ,
2024-02-13 03:52:21 +00:00
formatted _body : '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg?via=cadence.moe&via=super.invalid">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg?via=cadence.moe&via=super.invalid</a>'
2023-07-10 20:01:11 +00:00
} ] )
2024-02-13 03:52:21 +00:00
t . equal ( called , 2 , "should call getStateEvent and getJoinedMembers once each" )
2023-07-10 20:01:11 +00:00
} )
2023-11-23 03:11:46 +00:00
test ( "message2event: message link that OOYE doesn't know about" , async t => {
let called = 0
const events = await messageToEvent ( data . message . message _link _to _before _ooye , data . guild . general , { } , {
api : {
async getEventForTimestamp ( roomID , ts ) {
called ++
t . equal ( roomID , "!kLRqKKUQXcibIMtOpl:cadence.moe" )
return {
event _id : "$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U" ,
origin _server _ts : 1613287812754
}
2024-02-13 03:52:21 +00:00
} ,
async getStateEvent ( roomID , type , key ) { // for ?via calculation
called ++
t . equal ( roomID , "!kLRqKKUQXcibIMtOpl:cadence.moe" )
t . equal ( type , "m.room.power_levels" )
t . equal ( key , "" )
return {
users : {
"@_ooye_bot:cadence.moe" : 100
}
}
} ,
async getJoinedMembers ( roomID ) { // for ?via calculation
called ++
t . equal ( roomID , "!kLRqKKUQXcibIMtOpl:cadence.moe" )
return {
joined : {
"@_ooye_bot:cadence.moe" : { display _name : null , avatar _url : null } ,
"@user:matrix.org" : { display _name : null , avatar _url : null }
}
}
2023-11-23 03:11:46 +00:00
}
}
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "Me: I'll scroll up to find a certain message I'll send\n_scrolls up and clicks message links for god knows how long_\n_completely forgets what they were looking for and simply begins scrolling up to find some fun moments_\n_stumbles upon:_ "
2024-02-13 03:52:21 +00:00
+ "https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U?via=cadence.moe&via=matrix.org" ,
2023-11-23 03:11:46 +00:00
format : "org.matrix.custom.html" ,
formatted _body : "Me: I'll scroll up to find a certain message I'll send<br><em>scrolls up and clicks message links for god knows how long</em><br><em>completely forgets what they were looking for and simply begins scrolling up to find some fun moments</em><br><em>stumbles upon:</em> "
2024-02-13 03:52:21 +00:00
+ '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U?via=cadence.moe&via=matrix.org">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U?via=cadence.moe&via=matrix.org</a>'
2023-11-23 03:11:46 +00:00
} ] )
2024-02-13 03:52:21 +00:00
t . equal ( called , 3 , "getEventForTimestamp, getStateEvent, and getJoinedMembers should be called once each" )
2023-11-23 03:11:46 +00:00
} )
2023-11-23 03:41:32 +00:00
test ( "message2event: message link from another server" , async t => {
const events = await messageToEvent ( data . message . message _link _from _another _server , data . guild . general )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "Neither of these servers are known to OOYE: https://discord.com/channels/111/222/333 [event is from another server] https://canary.discordapp.com/channels/444/555/666 [event is from another server]" ,
format : "org.matrix.custom.html" ,
formatted _body : 'Neither of these servers are known to OOYE: <a href="https://discord.com/channels/111/222/333">https://discord.com/channels/111/222/333</a> [event is from another server]'
+ ' <a href="https://canary.discordapp.com/channels/444/555/666">https://canary.discordapp.com/channels/444/555/666</a> [event is from another server]'
} ] )
} )
2023-07-01 13:41:31 +00:00
test ( "message2event: attachment with no content" , async t => {
2023-08-16 08:44:38 +00:00
const events = await messageToEvent ( data . message . attachment _no _content , data . guild . general , { } )
2023-07-07 07:28:23 +00:00
t . deepEqual ( events , [ {
$type : "m.room.message" ,
2023-07-11 04:51:30 +00:00
"m.mentions" : { } ,
2023-07-07 07:28:23 +00:00
msgtype : "m.image" ,
url : "mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM" ,
body : "image.png" ,
external _url : "https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png" ,
2023-08-30 03:20:39 +00:00
filename : "image.png" ,
2023-07-07 07:28:23 +00:00
info : {
mimetype : "image/png" ,
w : 466 ,
h : 85 ,
size : 12919 ,
} ,
} ] )
2023-07-01 13:41:31 +00:00
} )
2023-09-02 09:44:54 +00:00
test ( "message2event: spoiler attachment" , async t => {
const events = await messageToEvent ( data . message . spoiler _attachment , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "📄 Uploaded SPOILER file: https://cdn.discordapp.com/attachments/1100319550446252084/1147465564307079258/SPOILER_69-GNDP-CADENCE.nfs.gci (74 KB)" ,
format : "org.matrix.custom.html" ,
2023-11-25 09:08:29 +00:00
formatted _body : "<blockquote>📄 Uploaded SPOILER file: <a href=\"https://cdn.discordapp.com/attachments/1100319550446252084/1147465564307079258/SPOILER_69-GNDP-CADENCE.nfs.gci\">https://cdn.discordapp.com/attachments/1100319550446252084/1147465564307079258/SPOILER_69-GNDP-CADENCE.nfs.gci</a> (74 KB)</blockquote>"
2023-09-02 09:44:54 +00:00
} ] )
} )
2023-05-12 05:35:37 +00:00
test ( "message2event: stickers" , async t => {
2023-08-16 08:44:38 +00:00
const events = await messageToEvent ( data . message . sticker , data . guild . general , { } )
2023-07-07 07:28:23 +00:00
t . deepEqual ( events , [ {
$type : "m.room.message" ,
2023-07-11 04:51:30 +00:00
"m.mentions" : { } ,
2023-07-07 07:28:23 +00:00
msgtype : "m.text" ,
body : "can have attachments too"
} , {
$type : "m.room.message" ,
2023-07-11 04:51:30 +00:00
"m.mentions" : { } ,
2023-07-07 07:28:23 +00:00
msgtype : "m.image" ,
url : "mxc://cadence.moe/ZDCNYnkPszxGKgObUIFmvjus" ,
body : "image.png" ,
external _url : "https://cdn.discordapp.com/attachments/122155380120748034/1106366167486038016/image.png" ,
2023-08-30 03:20:39 +00:00
filename : "image.png" ,
2023-07-07 07:28:23 +00:00
info : {
mimetype : "image/png" ,
w : 333 ,
h : 287 ,
size : 127373 ,
} ,
} , {
$type : "m.sticker" ,
2023-07-11 04:51:30 +00:00
"m.mentions" : { } ,
2023-07-07 07:28:23 +00:00
body : "pomu puff - damn that tiny lil bitch really chuffing. puffing that fat ass dart" ,
info : {
mimetype : "image/png"
// thumbnail_url
// thumbnail_info
} ,
url : "mxc://cadence.moe/UuUaLwXhkxFRwwWCXipDlBHn"
} ] )
2023-05-12 05:35:37 +00:00
} )
2023-07-11 04:51:30 +00:00
2024-01-18 23:38:25 +00:00
test ( "message2event: lottie sticker" , async t => {
const events = await messageToEvent ( data . message . lottie _sticker , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.sticker" ,
"m.mentions" : { } ,
body : "8" ,
info : {
mimetype : "image/png" ,
w : 160 ,
h : 160
} ,
url : "mxc://cadence.moe/ZtvvVbwMIdUZeovWVyGVFCeR"
} ] )
} )
2023-07-11 04:51:30 +00:00
test ( "message2event: skull webp attachment with content" , async t => {
2023-08-16 08:44:38 +00:00
const events = await messageToEvent ( data . message . skull _webp _attachment _with _content , data . guild . general , { } )
2023-07-11 04:51:30 +00:00
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "Image"
} , {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.image" ,
body : "skull.webp" ,
info : {
w : 1200 ,
h : 628 ,
mimetype : "image/webp" ,
size : 74290
} ,
external _url : "https://cdn.discordapp.com/attachments/112760669178241024/1128084747910918195/skull.webp" ,
2023-08-30 03:20:39 +00:00
filename : "skull.webp" ,
2023-07-11 04:51:30 +00:00
url : "mxc://cadence.moe/sDxWmDErBhYBxtDcJQgBETes"
} ] )
} )
test ( "message2event: reply to skull webp attachment with content" , async t => {
2023-08-16 08:44:38 +00:00
const events = await messageToEvent ( data . message . reply _to _skull _webp _attachment _with _content , data . guild . general , { } )
2023-07-11 04:51:30 +00:00
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$oLyUTyZ_7e_SUzGNWZKz880ll9amLZvXGbArJCKai2Q"
}
} ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "> Extremity: Image\n\nReply" ,
format : "org.matrix.custom.html" ,
formatted _body :
'<mx-reply><blockquote><a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$oLyUTyZ_7e_SUzGNWZKz880ll9amLZvXGbArJCKai2Q">In reply to</a> Extremity'
+ '<br>Image</blockquote></mx-reply>'
+ 'Reply'
} , {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.image" ,
body : "RDT_20230704_0936184915846675925224905.jpg" ,
info : {
w : 2048 ,
h : 1536 ,
mimetype : "image/jpeg" ,
size : 85906
} ,
external _url : "https://cdn.discordapp.com/attachments/112760669178241024/1128084851023675515/RDT_20230704_0936184915846675925224905.jpg" ,
2023-08-30 03:20:39 +00:00
filename : "RDT_20230704_0936184915846675925224905.jpg" ,
2023-07-11 04:51:30 +00:00
url : "mxc://cadence.moe/WlAbFSiNRIHPDEwKdyPeGywa"
} ] )
} )
test ( "message2event: simple reply to matrix user" , async t => {
2023-08-16 08:44:38 +00:00
const events = await messageToEvent ( data . message . simple _reply _to _matrix _user , data . guild . general , { } , {
api : {
getEvent : mockGetEvent ( t , "!kLRqKKUQXcibIMtOpl:cadence.moe" , "$Ij3qo7NxMA4VPexlAiIx2CB9JbsiGhJeyt-2OvkAUe4" , {
type : "m.room.message" ,
content : {
msgtype : "m.text" ,
body : "so can you reply to my webhook uwu"
} ,
sender : "@cadence:cadence.moe"
} )
}
2023-07-11 04:51:30 +00:00
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$Ij3qo7NxMA4VPexlAiIx2CB9JbsiGhJeyt-2OvkAUe4"
}
} ,
"m.mentions" : {
user _ids : [
"@cadence:cadence.moe"
]
} ,
msgtype : "m.text" ,
body : "> cadence: so can you reply to my webhook uwu\n\nReply" ,
format : "org.matrix.custom.html" ,
formatted _body :
'<mx-reply><blockquote><a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$Ij3qo7NxMA4VPexlAiIx2CB9JbsiGhJeyt-2OvkAUe4">In reply to</a> <a href="https://matrix.to/#/@cadence:cadence.moe">cadence</a>'
+ '<br>so can you reply to my webhook uwu</blockquote></mx-reply>'
+ 'Reply'
} ] )
} )
2023-08-16 08:44:38 +00:00
test ( "message2event: simple reply to matrix user, reply fallbacks disabled" , async t => {
const events = await messageToEvent ( data . message . simple _reply _to _matrix _user , data . guild . general , { includeReplyFallback : false } , {
api : {
getEvent : mockGetEvent ( t , "!kLRqKKUQXcibIMtOpl:cadence.moe" , "$Ij3qo7NxMA4VPexlAiIx2CB9JbsiGhJeyt-2OvkAUe4" , {
type : "m.room.message" ,
content : {
msgtype : "m.text" ,
body : "so can you reply to my webhook uwu"
} ,
sender : "@cadence:cadence.moe"
} )
}
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$Ij3qo7NxMA4VPexlAiIx2CB9JbsiGhJeyt-2OvkAUe4"
}
} ,
"m.mentions" : {
user _ids : [
"@cadence:cadence.moe"
]
} ,
msgtype : "m.text" ,
body : "Reply"
} ] )
} )
2024-01-18 23:39:07 +00:00
test ( "message2event: reply with a video" , async t => {
const events = await messageToEvent ( data . message . reply _with _video , data . guild . general , {
api : {
getEvent : mockGetEvent ( t , "!kLRqKKUQXcibIMtOpl:cadence.moe" , "$7tJoMw1h44n2gxgLUE1T_YinGrLbK0x-TDY1z6M7GBw" , {
type : "m.room.message" ,
content : {
msgtype : "m.text" ,
body : 'deadpicord "extremity you woke up at 4 am"'
} ,
sender : "@_ooye_extremity:cadence.moe"
} )
}
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
msgtype : "m.video" ,
body : "Ins_1960637570.mp4" ,
filename : "Ins_1960637570.mp4" ,
url : "mxc://cadence.moe/kMqLycqMURhVpwleWkmASpnU" ,
external _url : "https://cdn.discordapp.com/attachments/112760669178241024/1197621094786531358/Ins_1960637570.mp4?ex=65bbee8f&is=65a9798f&hm=ae14f7824c3d526c5e11c162e012e1ee405fd5776e1e9302ed80ccd86503cfda&" ,
info : {
h : 854 ,
mimetype : "video/mp4" ,
size : 860559 ,
w : 480 ,
} ,
"m.mentions" : { } ,
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$7tJoMw1h44n2gxgLUE1T_YinGrLbK0x-TDY1z6M7GBw"
}
}
} ] )
} )
2024-02-02 02:55:02 +00:00
test ( "message2event: voice message" , async t => {
const events = await messageToEvent ( data . message . voice _message )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
body : "voice-message.ogg" ,
external _url : "https://cdn.discordapp.com/attachments/1099031887500034088/1112476845502365786/voice-message.ogg?ex=65c92d4c&is=65b6b84c&hm=0654bab5027474cbe23875954fa117cf44d8914c144cd151879590fa1baf8b1c&" ,
filename : "voice-message.ogg" ,
info : {
duration : 3960.0000381469727 ,
mimetype : "audio/ogg" ,
size : 10584 ,
} ,
"m.mentions" : { } ,
msgtype : "m.audio" ,
url : "mxc://cadence.moe/MRRPDggXQMYkrUjTpxQbmcxB"
} ] )
} )
test ( "message2event: misc file" , async t => {
const events = await messageToEvent ( data . message . misc _file )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
msgtype : "m.text" ,
body : "final final final revised draft" ,
"m.mentions" : { }
} , {
$type : "m.room.message" ,
body : "the.yml" ,
external _url : "https://cdn.discordapp.com/attachments/122155380120748034/1174514575220158545/the.yml?ex=65cd6270&is=65baed70&hm=8c5f1b571784e3c7f99628492298815884e351ae0dc7c2ae40dd22d97caf27d9&" ,
filename : "the.yml" ,
info : {
mimetype : "text/plain; charset=utf-8" ,
size : 2274
} ,
"m.mentions" : { } ,
msgtype : "m.file" ,
url : "mxc://cadence.moe/HnQIYQmmlIKwOQsbFsIGpzPP"
} ] )
} )
2023-10-12 13:05:44 +00:00
test ( "message2event: simple reply in thread to a matrix user's reply" , async t => {
const events = await messageToEvent ( data . message . simple _reply _to _reply _in _thread , data . guild . general , { } , {
api : {
getEvent : mockGetEvent ( t , "!FuDZhlOAtqswlyxzeR:cadence.moe" , "$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo" , {
type : "m.room.message" ,
sender : "@cadence:cadence.moe" ,
content : {
msgtype : "m.text" ,
body : "> <@_ooye_cadence:cadence.moe> So what I'm wondering is about replies.\n\nWhat about them?" ,
format : "org.matrix.custom.html" ,
formatted _body : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!FuDZhlOAtqswlyxzeR:cadence.moe/$fWQT8uOrzLzAXNVXz88VkGx7Oo724iS5uD8Qn5KUy9w?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@_ooye_cadence:cadence.moe\">@_ooye_cadence:cadence.moe</a><br>So what I'm wondering is about replies.</blockquote></mx-reply>What about them?" ,
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$fWQT8uOrzLzAXNVXz88VkGx7Oo724iS5uD8Qn5KUy9w"
}
}
} ,
event _id : "$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo" ,
room _id : "!FuDZhlOAtqswlyxzeR:cadence.moe"
} )
}
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.relates_to" : {
"m.in_reply_to" : {
event _id : "$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo"
}
} ,
"m.mentions" : {
user _ids : [ "@cadence:cadence.moe" ]
} ,
msgtype : "m.text" ,
2024-02-15 21:06:15 +00:00
body : "> cadence [they]: What about them?\n\nWell, they don't seem to..." ,
2023-10-12 13:05:44 +00:00
format : "org.matrix.custom.html" ,
2024-02-15 21:06:15 +00:00
formatted _body : "<mx-reply><blockquote><a href=\"https://matrix.to/#/!FuDZhlOAtqswlyxzeR:cadence.moe/$nUM-ABBF8KdnvrhXwLlYAE9dgDl_tskOvvcNIBrtsVo\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">cadence [they]</a><br>What about them?</blockquote></mx-reply>Well, they don't seem to..." ,
2023-10-12 13:05:44 +00:00
} ] )
} )
2023-10-04 10:23:57 +00:00
test ( "message2event: simple written @mention for matrix user" , async t => {
2023-08-16 08:44:38 +00:00
const events = await messageToEvent ( data . message . simple _written _at _mention _for _matrix , data . guild . general , { } , {
2023-10-04 10:23:57 +00:00
api : {
async getJoinedMembers ( roomID ) {
t . equal ( roomID , "!rEOspnYqdOalaIFniV:cadence.moe" )
return new Promise ( resolve => {
setTimeout ( ( ) => {
resolve ( {
joined : {
"@she_who_brings_destruction:matrix.org" : {
avatar _url : "mxc://matrix.org/FKcfnfFZlEhspeMsERfYtCuO" ,
display _name : "ash (Old)"
} ,
"@tomskeleton:cadence.moe" : {
avatar _url : "mxc://cadence.moe/OvYYicuOwfAACKaXKJCUPbVz" ,
display _name : "tomskeleton"
} ,
"@she_who_brings_destruction:cadence.moe" : {
avatar _url : "mxc://cadence.moe/XDXLMbkieETPrjFupoeiwyyq" ,
display _name : "ash"
} ,
"@_ooye_bot:cadence.moe" : {
avatar _url : "mxc://cadence.moe/jlrgFjYQHzfBvORedOmYqXVz" ,
display _name : "Out Of Your Element"
} ,
"@cadence:cadence.moe" : {
avatar _url : "mxc://cadence.moe/GJDPWiryxIhyRBNJzRNYzAlh" ,
display _name : "cadence [they]"
} ,
"@_ooye_tomskeleton:cadence.moe" : {
avatar _url : "mxc://cadence.moe/SdSrjjsrNVdyPTAKEGQUhKUK" ,
display _name : "tomskeleton"
} ,
"@_ooye_queergasm:cadence.moe" : {
avatar _url : "mxc://cadence.moe/KqXYGbUqhPPJKifLmfpoLnmB" ,
display _name : "queergasm"
} ,
"@_ooye_.subtext:cadence.moe" : {
avatar _url : "mxc://cadence.moe/heoCvaUmfCdpxdzaChwwkpEp" ,
display _name : ".subtext"
}
}
} )
} )
} )
}
}
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : {
user _ids : [
"@she_who_brings_destruction:cadence.moe"
]
} ,
msgtype : "m.text" ,
body : "@ash do you need anything from the store btw as I'm heading there after gym"
} ] )
} )
test ( "message2event: advanced written @mentions for matrix users" , async t => {
let called = 0
const events = await messageToEvent ( data . message . advanced _written _at _mention _for _matrix , data . guild . general , { } , {
2023-08-16 08:44:38 +00:00
api : {
async getJoinedMembers ( roomID ) {
2023-08-17 06:17:53 +00:00
called ++
2023-08-16 08:44:38 +00:00
t . equal ( roomID , "!kLRqKKUQXcibIMtOpl:cadence.moe" )
return new Promise ( resolve => {
setTimeout ( ( ) => {
resolve ( {
joined : {
"@cadence:cadence.moe" : {
2023-10-04 10:23:57 +00:00
display _name : "cadence [they]" ,
2023-08-16 08:44:38 +00:00
avatar _url : "whatever"
} ,
"@huckleton:cadence.moe" : {
2023-10-04 10:23:57 +00:00
display _name : "huck" ,
2023-08-16 08:44:38 +00:00
avatar _url : "whatever"
} ,
"@_ooye_botrac4r:cadence.moe" : {
2023-10-04 10:23:57 +00:00
display _name : "botrac4r" ,
2023-08-16 08:44:38 +00:00
avatar _url : "whatever"
} ,
"@_ooye_bot:cadence.moe" : {
2023-10-04 10:23:57 +00:00
display _name : "Out Of Your Element" ,
2023-08-16 08:44:38 +00:00
avatar _url : "whatever"
}
2023-07-11 05:27:40 +00:00
}
2023-08-16 08:44:38 +00:00
} )
2023-07-11 05:27:40 +00:00
} )
} )
2023-08-16 08:44:38 +00:00
}
2023-07-11 05:27:40 +00:00
}
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : {
user _ids : [
"@cadence:cadence.moe" ,
"@huckleton:cadence.moe"
]
} ,
msgtype : "m.text" ,
body : "@Cadence, tell me about @Phil, the creator of the Chin Trick, who has become ever more powerful under the mentorship of @botrac4r and @huck"
} ] )
2023-08-17 06:17:53 +00:00
t . equal ( called , 1 , "should only look up the member list once" )
2023-07-11 05:27:40 +00:00
} )
2023-07-13 05:36:20 +00:00
test ( "message2event: very large attachment is linked instead of being uploaded" , async t => {
const events = await messageToEvent ( {
content : "hey" ,
attachments : [ {
filename : "hey.jpg" ,
url : "https://discord.com/404/hey.jpg" ,
content _type : "application/i-made-it-up" ,
size : 100e6
} ]
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "hey"
} , {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "📄 Uploaded file: https://discord.com/404/hey.jpg (100 MB)" ,
format : "org.matrix.custom.html" ,
formatted _body : '📄 Uploaded file: <a href="https://discord.com/404/hey.jpg">hey.jpg</a> (100 MB)'
} ] )
} )
2023-08-19 10:54:23 +00:00
test ( "message2event: type 4 channel name change" , async t => {
const events = await messageToEvent ( data . special _message . thread _name _change , data . guild . general )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.emote" ,
body : "changed the channel name to **worming**" ,
format : "org.matrix.custom.html" ,
formatted _body : "changed the channel name to <strong>worming</strong>"
} ] )
} )
2023-08-21 11:31:40 +00:00
test ( "message2event: thread start message reference" , async t => {
const events = await messageToEvent ( data . special _message . thread _start _context , data . guild . general , { } , {
api : {
2023-10-04 10:23:57 +00:00
getEvent : mockGetEvent ( t , "!BnKuBPCvyfOkhcUjEu:cadence.moe" , "$FchUVylsOfmmbj-VwEs5Z9kY49_dt2zd0vWfylzy5Yo" , {
2023-08-21 11:31:40 +00:00
"type" : "m.room.message" ,
2023-09-07 12:13:25 +00:00
"sender" : "@_ooye_kyuugryphon:cadence.moe" ,
2023-08-21 11:31:40 +00:00
"content" : {
"m.mentions" : { } ,
"msgtype" : "m.text" ,
"body" : "layer 4"
}
} )
}
} )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
2023-10-14 04:23:55 +00:00
$sender : null ,
2023-08-21 11:31:40 +00:00
msgtype : "m.text" ,
body : "layer 4" ,
"m.mentions" : { }
} ] )
} )
2023-09-19 05:43:57 +00:00
test ( "message2event: single large bridged emoji" , async t => {
const events = await messageToEvent ( data . message . single _emoji , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : ":hippo:" ,
format : "org.matrix.custom.html" ,
formatted _body : '<img data-mx-emoticon height="32" src="mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC" title=":hippo:" alt=":hippo:">'
} ] )
} )
test ( "message2event: mid-message small bridged emoji" , async t => {
const events = await messageToEvent ( data . message . surrounded _emoji , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "h is for :hippo:!" ,
format : "org.matrix.custom.html" ,
formatted _body : 'h is for <img data-mx-emoticon height="32" src="mxc://cadence.moe/qWmbXeRspZRLPcjseyLmeyXC" title=":hippo:" alt=":hippo:">!'
} ] )
} )
2023-09-27 10:24:31 +00:00
2023-10-07 07:58:46 +00:00
test ( "message2event: emoji that hasn't been registered yet" , async t => {
const events = await messageToEvent ( data . message . not _been _registered _emoji , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : ":Yeah:" ,
format : "org.matrix.custom.html" ,
formatted _body : '<img data-mx-emoticon height="32" src="mxc://cadence.moe/pgdGTxAyEltccRgZKxdqzHHP" title=":Yeah:" alt=":Yeah:">'
} ] )
} )
2023-09-27 10:24:31 +00:00
test ( "message2event: emoji triple long name" , async t => {
const events = await messageToEvent ( data . message . emoji _triple _long _name , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : ":brillillillilliant_move::brillillillilliant_move::brillillillilliant_move:" ,
format : "org.matrix.custom.html" ,
formatted _body :
'<img data-mx-emoticon height="32" src="mxc://cadence.moe/scfRIDOGKWFDEBjVXocWYQHik" title=":brillillillilliant_move:" alt=":brillillillilliant_move:">'
+ '<img data-mx-emoticon height="32" src="mxc://cadence.moe/scfRIDOGKWFDEBjVXocWYQHik" title=":brillillillilliant_move:" alt=":brillillillilliant_move:">'
+ '<img data-mx-emoticon height="32" src="mxc://cadence.moe/scfRIDOGKWFDEBjVXocWYQHik" title=":brillillillilliant_move:" alt=":brillillillilliant_move:">'
} ] )
} )
2023-10-09 22:29:27 +00:00
test ( "message2event: crossposted announcements say where they are crossposted from" , async t => {
const events = await messageToEvent ( data . special _message . crosspost _announcement , data . guild . general , { } )
t . deepEqual ( events , [ {
$type : "m.room.message" ,
"m.mentions" : { } ,
msgtype : "m.text" ,
body : "[🔀 Chewey Bot Official Server #announcements]\nAll text based commands are now inactive on Chewey Bot\nTo continue using commands you'll need to use them as slash commands" ,
format : "org.matrix.custom.html" ,
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"
} ] )
} )
2024-03-05 22:56:21 +00:00
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" : { }
} ] )
} )