Ensure the appservice bot user is registered
Synapse does it automatically, but Conduit requires this HTTP call.
This commit is contained in:
		
							parent
							
								
									a542bbdca7
								
							
						
					
					
						commit
						762e48230c
					
				
					 2 changed files with 13 additions and 6 deletions
				
			
		| 
						 | 
					@ -36,7 +36,7 @@ async function createSim(user) {
 | 
				
			||||||
		await api.register(localpart)
 | 
							await api.register(localpart)
 | 
				
			||||||
	} catch (e) {
 | 
						} catch (e) {
 | 
				
			||||||
		// If user creation fails, manually undo the database change. Still isn't perfect, but should help.
 | 
							// If user creation fails, manually undo the database change. Still isn't perfect, but should help.
 | 
				
			||||||
		// (A transaction would be preferable, but I don't think it's safe to leave transaction open across event loop ticks.)
 | 
							// (I would prefer a transaction, but it's not safe to leave transactions open across event loop ticks.)
 | 
				
			||||||
		db.prepare("DELETE FROM sim WHERE user_id = ?").run(user.id)
 | 
							db.prepare("DELETE FROM sim WHERE user_id = ?").run(user.id)
 | 
				
			||||||
		throw e
 | 
							throw e
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,6 +67,18 @@ async function uploadAutoEmoji(guild, name, filename) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	console.log("✅ Database is ready...")
 | 
						console.log("✅ Database is ready...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// ensure appservice bot user is registered...
 | 
				
			||||||
 | 
						try {
 | 
				
			||||||
 | 
							await api.register(reg.sender_localpart)
 | 
				
			||||||
 | 
						} catch (e) {
 | 
				
			||||||
 | 
							if (e.data?.error !== "Internal server error") throw e // "Internal server error" is the only OK error because Synapse says this if you try to register the same username twice.
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// upload initial images...
 | 
				
			||||||
 | 
						const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element.png")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						console.log("✅ Matrix appservice login works...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// upload the L1 L2 emojis to some guild
 | 
						// upload the L1 L2 emojis to some guild
 | 
				
			||||||
	const emojis = db.prepare("SELECT name FROM auto_emoji WHERE name = 'L1' OR name = 'L2'").pluck().all()
 | 
						const emojis = db.prepare("SELECT name FROM auto_emoji WHERE name = 'L1' OR name = 'L2'").pluck().all()
 | 
				
			||||||
	if (emojis.length !== 2) {
 | 
						if (emojis.length !== 2) {
 | 
				
			||||||
| 
						 | 
					@ -104,11 +116,6 @@ async function uploadAutoEmoji(guild, name, filename) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	console.log("✅ Emojis are ready...")
 | 
						console.log("✅ Emojis are ready...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// ensure homeserver well-known is valid and returns reg.ooye.server_name...
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// upload initial images...
 | 
					 | 
				
			||||||
	const avatarUrl = await file.uploadDiscordFileToMxc("https://cadence.moe/friends/out_of_your_element.png")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// set profile data on discord...
 | 
						// set profile data on discord...
 | 
				
			||||||
	const avatarImageBuffer = await fetch("https://cadence.moe/friends/out_of_your_element.png").then(res => res.arrayBuffer())
 | 
						const avatarImageBuffer = await fetch("https://cadence.moe/friends/out_of_your_element.png").then(res => res.arrayBuffer())
 | 
				
			||||||
	await discord.snow.user.updateSelf({avatar: "data:image/png;base64," + Buffer.from(avatarImageBuffer).toString("base64")})
 | 
						await discord.snow.user.updateSelf({avatar: "data:image/png;base64," + Buffer.from(avatarImageBuffer).toString("base64")})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue