2023-06-28 12:06:56 +00:00
const assert = require ( "assert" ) . strict
2023-07-03 12:39:42 +00:00
const { sync , db } = require ( "../passthrough" )
2023-05-04 20:25:00 +00:00
/** @type {import("./actions/send-message")}) */
const sendMessage = sync . require ( "./actions/send-message" )
2023-05-09 05:13:59 +00:00
/** @type {import("./actions/add-reaction")}) */
const addReaction = sync . require ( "./actions/add-reaction" )
2023-05-04 20:25:00 +00:00
// Grab Discord events we care about for the bridge, check them, and pass them on
2023-04-30 12:57:30 +00:00
2023-04-25 20:06:08 +00:00
module . exports = {
/ * *
* @ param { import ( "./discord-client" ) } client
* @ param { import ( "discord-api-types/v10" ) . GatewayMessageCreateDispatchData } message
* /
onMessageCreate ( client , message ) {
2023-07-03 12:39:42 +00:00
if ( message . webhook _id ) {
const row = db . prepare ( "SELECT webhook_id FROM webhook WHERE webhook_id = ?" ) . pluck ( ) . get ( message . webhook _id )
if ( row ) {
// The message was sent by the bridge's own webhook on discord. We don't want to reflect this back, so just drop it.
return
}
}
2023-07-04 20:41:15 +00:00
/** @type {import("discord-api-types/v10").APIGuildChannel} */
const channel = client . channels . get ( message . channel _id )
if ( ! channel . guild _id ) return // Nothing we can do in direct messages.
const guild = client . guilds . get ( channel . guild _id )
if ( message . guild _id !== "112760669178241024" && message . guild _id !== "497159726455455754" ) return // TODO: activate on other servers (requires the space creation flow to be done first)
2023-06-28 12:06:56 +00:00
sendMessage . sendMessage ( message , guild )
2023-04-25 20:06:08 +00:00
} ,
/ * *
* @ param { import ( "./discord-client" ) } client
* @ param { import ( "discord-api-types/v10" ) . GatewayMessageReactionAddDispatchData } data
* /
onReactionAdd ( client , data ) {
2023-07-04 20:41:15 +00:00
if ( data . user _id === client . user . id ) return // m2d reactions are added by the discord bot user - do not reflect them back to matrix.
2023-06-28 11:38:58 +00:00
if ( data . emoji . id !== null ) return // TODO: image emoji reactions
2023-04-25 20:06:08 +00:00
console . log ( data )
2023-05-09 05:13:59 +00:00
addReaction . addReaction ( data )
2023-04-25 20:06:08 +00:00
}
}