🐛 fix guild create with client template
This commit is contained in:
		
							parent
							
								
									2c3fe9bd9e
								
							
						
					
					
						commit
						9d2f0ddf5c
					
				| @ -31,7 +31,7 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res: | |||||||
| 
 | 
 | ||||||
| 	const guild_id = Snowflake.generate(); | 	const guild_id = Snowflake.generate(); | ||||||
| 
 | 
 | ||||||
| 	await Guild.insert({ | 	await new Guild({ | ||||||
| 		name: body.name, | 		name: body.name, | ||||||
| 		icon: await handleFile(`/icons/${guild_id}`, body.icon as string), | 		icon: await handleFile(`/icons/${guild_id}`, body.icon as string), | ||||||
| 		region: Config.get().regions.default, | 		region: Config.get().regions.default, | ||||||
| @ -61,10 +61,10 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res: | |||||||
| 			welcome_channels: [] | 			welcome_channels: [] | ||||||
| 		}, | 		}, | ||||||
| 		widget_enabled: false | 		widget_enabled: false | ||||||
| 	}); | 	}).save(); | ||||||
| 
 | 
 | ||||||
| 	// we have to create the role _after_ the guild because else we would get a "SQLITE_CONSTRAINT: FOREIGN KEY constraint failed" error
 | 	// we have to create the role _after_ the guild because else we would get a "SQLITE_CONSTRAINT: FOREIGN KEY constraint failed" error
 | ||||||
| 	await Role.insert({ | 	await new Role({ | ||||||
| 		id: guild_id, | 		id: guild_id, | ||||||
| 		guild_id: guild_id, | 		guild_id: guild_id, | ||||||
| 		color: 0, | 		color: 0, | ||||||
| @ -74,7 +74,7 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res: | |||||||
| 		name: "@everyone", | 		name: "@everyone", | ||||||
| 		permissions: String("2251804225"), | 		permissions: String("2251804225"), | ||||||
| 		position: 0 | 		position: 0 | ||||||
| 	}); | 	}).save(); | ||||||
| 
 | 
 | ||||||
| 	if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }]; | 	if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }]; | ||||||
| 
 | 
 | ||||||
| @ -86,23 +86,19 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res: | |||||||
| 		} | 		} | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| 	await Promise.all( | 	for (const channel of body.channels?.sort((a, b) => (a.parent_id ? 1 : -1))) { | ||||||
| 		body.channels | 		var id = ids.get(channel.id) || Snowflake.generate(); | ||||||
| 			?.sort((a, b) => (a.parent_id ? -1 : 1)) |  | ||||||
| 			.map((x) => { |  | ||||||
| 				var id = ids.get(x.id) || Snowflake.generate(); |  | ||||||
| 
 | 
 | ||||||
| 		// TODO: should we abort if parent_id is a category? (to disallow sub category channels)
 | 		// TODO: should we abort if parent_id is a category? (to disallow sub category channels)
 | ||||||
| 				var parent_id = ids.get(x.parent_id); | 		var parent_id = ids.get(channel.parent_id); | ||||||
| 
 | 
 | ||||||
| 				return Channel.createChannel({ ...x, guild_id, id, parent_id }, req.user_id, { | 		await Channel.createChannel({ ...channel, guild_id, id, parent_id }, req.user_id, { | ||||||
| 			keepId: true, | 			keepId: true, | ||||||
| 			skipExistsCheck: true, | 			skipExistsCheck: true, | ||||||
| 			skipPermissionCheck: true, | 			skipPermissionCheck: true, | ||||||
| 			skipEventEmit: true | 			skipEventEmit: true | ||||||
| 		}); | 		}); | ||||||
| 			}) | 	} | ||||||
| 	); |  | ||||||
| 
 | 
 | ||||||
| 	await Member.addToGuild(req.user_id, guild_id); | 	await Member.addToGuild(req.user_id, guild_id); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Flam3rboy
						Flam3rboy