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
 | 
						 * @param {import("discord-api-types/v10").GatewayMessageCreateDispatchData} message
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	onMessageCreate(client, 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) {
 | 
							if (message.webhook_id) {
 | 
				
			||||||
			const row = db.prepare("SELECT webhook_id FROM webhook WHERE webhook_id = ?").pluck().get(message.webhook_id)
 | 
								const row = db.prepare("SELECT webhook_id FROM webhook WHERE webhook_id = ?").pluck().get(message.webhook_id)
 | 
				
			||||||
			if (row) {
 | 
								if (row) {
 | 
				
			||||||
| 
						 | 
					@ -25,6 +21,11 @@ module.exports = {
 | 
				
			||||||
				return
 | 
									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)
 | 
							sendMessage.sendMessage(message, guild)
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +34,7 @@ module.exports = {
 | 
				
			||||||
	 * @param {import("discord-api-types/v10").GatewayMessageReactionAddDispatchData} data
 | 
						 * @param {import("discord-api-types/v10").GatewayMessageReactionAddDispatchData} data
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	onReactionAdd(client, 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
 | 
							if (data.emoji.id !== null) return // TODO: image emoji reactions
 | 
				
			||||||
		console.log(data)
 | 
							console.log(data)
 | 
				
			||||||
		addReaction.addReaction(data)
 | 
							addReaction.addReaction(data)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										4
									
								
								index.js
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								index.js
									
										
									
									
									
								
							| 
						 | 
					@ -21,6 +21,10 @@ passthrough.as = as
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sync.require("./m2d/event-dispatcher")
 | 
					sync.require("./m2d/event-dispatcher")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					discord.snow.requestHandler.on("requestError", data => {
 | 
				
			||||||
 | 
						console.error("request error", data)
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
;(async () => {
 | 
					;(async () => {
 | 
				
			||||||
	await discord.cloud.connect()
 | 
						await discord.cloud.connect()
 | 
				
			||||||
	console.log("Discord gateway started")
 | 
						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
 | 
						// 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)
 | 
						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
 | 
					## Reaction removed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1. Remove reaction on matrix.
 | 
					1. Remove reaction on matrix. Just redact the event.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Member data changed
 | 
					## Member data changed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										20
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										20
									
								
								package-lock.json
									
										
									
										generated
									
									
									
								
							| 
						 | 
					@ -685,11 +685,11 @@
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/cloudstorm": {
 | 
					    "node_modules/cloudstorm": {
 | 
				
			||||||
      "version": "0.8.0",
 | 
					      "version": "0.8.2",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/cloudstorm/-/cloudstorm-0.8.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/cloudstorm/-/cloudstorm-0.8.2.tgz",
 | 
				
			||||||
      "integrity": "sha512-CT5/RKvSz1I0wmsf0SmZ2Jg9fPvqY67t9e2Y8n92vU0uEK5WmfPUyPOLZoYPMJwmktmsVCj4N6Pvka9gBIsY4g==",
 | 
					      "integrity": "sha512-G/P6/+LwXjiS6AmheRG+07DmmsrpHpt21JFMhe+rW8VagFOOKemC2Bcru+Qncl/5jdjZC2gzjKpjfdTjfUm+iw==",
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "snowtransfer": "0.8.0"
 | 
					        "snowtransfer": "^0.8.2"
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "engines": {
 | 
					      "engines": {
 | 
				
			||||||
        "node": ">=12.0.0"
 | 
					        "node": ">=12.0.0"
 | 
				
			||||||
| 
						 | 
					@ -1938,9 +1938,9 @@
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/node-fetch": {
 | 
					    "node_modules/node-fetch": {
 | 
				
			||||||
      "version": "2.6.9",
 | 
					      "version": "2.6.12",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
 | 
				
			||||||
      "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==",
 | 
					      "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "whatwg-url": "^5.0.0"
 | 
					        "whatwg-url": "^5.0.0"
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
| 
						 | 
					@ -2464,9 +2464,9 @@
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "node_modules/snowtransfer": {
 | 
					    "node_modules/snowtransfer": {
 | 
				
			||||||
      "version": "0.8.0",
 | 
					      "version": "0.8.2",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/snowtransfer/-/snowtransfer-0.8.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/snowtransfer/-/snowtransfer-0.8.2.tgz",
 | 
				
			||||||
      "integrity": "sha512-ang6qQsET4VX4u9mdZq6ynJvcm8HQfV6iZOHBh8Y3T0QkJLr6GAjzcv1et7BOXl1HDR/6NhD+j+ZGr8+imTclg==",
 | 
					      "integrity": "sha512-fAmaJSpFZqGwAvbrhT3XOWwhbiuHOgxN8pGeKnDDW0f8zdkPmSQT9aekXhFr1WukB94NIALYGcyIXe902p8S4A==",
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "discord-api-types": "^0.37.47",
 | 
					        "discord-api-types": "^0.37.47",
 | 
				
			||||||
        "form-data": "^4.0.0",
 | 
					        "form-data": "^4.0.0",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue