reactions working
This commit is contained in:
parent
4cd9da49fd
commit
bd32fe6c6d
5 changed files with 24 additions and 16 deletions
|
@ -14,10 +14,6 @@ module.exports = {
|
|||
* @param {import("discord-api-types/v10").GatewayMessageCreateDispatchData} message
|
||||
*/
|
||||
onMessageCreate(client, message) {
|
||||
/** @ts-ignore @type {import("discord-api-types/v10").APIGuildChannel} */
|
||||
const channel = client.channels.get(message.channel_id)
|
||||
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)
|
||||
if (message.webhook_id) {
|
||||
const row = db.prepare("SELECT webhook_id FROM webhook WHERE webhook_id = ?").pluck().get(message.webhook_id)
|
||||
if (row) {
|
||||
|
@ -25,6 +21,11 @@ module.exports = {
|
|||
return
|
||||
}
|
||||
}
|
||||
/** @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)
|
||||
sendMessage.sendMessage(message, guild)
|
||||
},
|
||||
|
||||
|
@ -33,6 +34,7 @@ module.exports = {
|
|||
* @param {import("discord-api-types/v10").GatewayMessageReactionAddDispatchData} data
|
||||
*/
|
||||
onReactionAdd(client, data) {
|
||||
if (data.user_id === client.user.id) return // m2d reactions are added by the discord bot user - do not reflect them back to matrix.
|
||||
if (data.emoji.id !== null) return // TODO: image emoji reactions
|
||||
console.log(data)
|
||||
addReaction.addReaction(data)
|
||||
|
|
4
index.js
4
index.js
|
@ -21,6 +21,10 @@ passthrough.as = as
|
|||
|
||||
sync.require("./m2d/event-dispatcher")
|
||||
|
||||
discord.snow.requestHandler.on("requestError", data => {
|
||||
console.error("request error", data)
|
||||
})
|
||||
|
||||
;(async () => {
|
||||
await discord.cloud.connect()
|
||||
console.log("Discord gateway started")
|
||||
|
|
|
@ -17,7 +17,9 @@ async function addReaction(event) {
|
|||
|
||||
// no need to sync the matrix member to the other side. but if I did need to, this is where I'd do it
|
||||
|
||||
const emoji = event.content["m.relates_to"].key // TODO: handle custom text or emoji reactions
|
||||
let emoji = event.content["m.relates_to"].key // TODO: handle custom text or emoji reactions
|
||||
emoji = encodeURIComponent(emoji)
|
||||
emoji = emoji.replace(/%EF%B8%8F/g, "")
|
||||
|
||||
return discord.snow.channel.createReaction(channelID, messageID, emoji)
|
||||
}
|
||||
|
|
2
notes.md
2
notes.md
|
@ -104,7 +104,7 @@ Can use custom transaction ID (?) to send the original timestamps to Matrix. See
|
|||
|
||||
## Reaction removed
|
||||
|
||||
1. Remove reaction on matrix.
|
||||
1. Remove reaction on matrix. Just redact the event.
|
||||
|
||||
## Member data changed
|
||||
|
||||
|
|
20
package-lock.json
generated
20
package-lock.json
generated
|
@ -685,11 +685,11 @@
|
|||
}
|
||||
},
|
||||
"node_modules/cloudstorm": {
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/cloudstorm/-/cloudstorm-0.8.0.tgz",
|
||||
"integrity": "sha512-CT5/RKvSz1I0wmsf0SmZ2Jg9fPvqY67t9e2Y8n92vU0uEK5WmfPUyPOLZoYPMJwmktmsVCj4N6Pvka9gBIsY4g==",
|
||||
"version": "0.8.2",
|
||||
"resolved": "https://registry.npmjs.org/cloudstorm/-/cloudstorm-0.8.2.tgz",
|
||||
"integrity": "sha512-G/P6/+LwXjiS6AmheRG+07DmmsrpHpt21JFMhe+rW8VagFOOKemC2Bcru+Qncl/5jdjZC2gzjKpjfdTjfUm+iw==",
|
||||
"dependencies": {
|
||||
"snowtransfer": "0.8.0"
|
||||
"snowtransfer": "^0.8.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
|
@ -1938,9 +1938,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz",
|
||||
"integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==",
|
||||
"version": "2.6.12",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
|
||||
"integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
|
||||
"dependencies": {
|
||||
"whatwg-url": "^5.0.0"
|
||||
},
|
||||
|
@ -2464,9 +2464,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/snowtransfer": {
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/snowtransfer/-/snowtransfer-0.8.0.tgz",
|
||||
"integrity": "sha512-ang6qQsET4VX4u9mdZq6ynJvcm8HQfV6iZOHBh8Y3T0QkJLr6GAjzcv1et7BOXl1HDR/6NhD+j+ZGr8+imTclg==",
|
||||
"version": "0.8.2",
|
||||
"resolved": "https://registry.npmjs.org/snowtransfer/-/snowtransfer-0.8.2.tgz",
|
||||
"integrity": "sha512-fAmaJSpFZqGwAvbrhT3XOWwhbiuHOgxN8pGeKnDDW0f8zdkPmSQT9aekXhFr1WukB94NIALYGcyIXe902p8S4A==",
|
||||
"dependencies": {
|
||||
"discord-api-types": "^0.37.47",
|
||||
"form-data": "^4.0.0",
|
||||
|
|
Loading…
Reference in a new issue