summary refs log tree commit diff
path: root/src/api/routes/guilds
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/routes/guilds')
-rw-r--r--src/api/routes/guilds/#guild_id/audit-logs.ts2
-rw-r--r--src/api/routes/guilds/#guild_id/bans.ts48
-rw-r--r--src/api/routes/guilds/#guild_id/channels.ts5
-rw-r--r--src/api/routes/guilds/#guild_id/delete.ts5
-rw-r--r--src/api/routes/guilds/#guild_id/discovery-requirements.ts50
-rw-r--r--src/api/routes/guilds/#guild_id/emojis.ts18
-rw-r--r--src/api/routes/guilds/#guild_id/index.ts29
-rw-r--r--src/api/routes/guilds/#guild_id/integrations.ts4
-rw-r--r--src/api/routes/guilds/#guild_id/invites.ts2
-rw-r--r--src/api/routes/guilds/#guild_id/members/#member_id/index.ts21
-rw-r--r--src/api/routes/guilds/#guild_id/members/#member_id/nick.ts2
-rw-r--r--src/api/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts2
-rw-r--r--src/api/routes/guilds/#guild_id/members/index.ts5
-rw-r--r--src/api/routes/guilds/#guild_id/premium.ts2
-rw-r--r--src/api/routes/guilds/#guild_id/prune.ts6
-rw-r--r--src/api/routes/guilds/#guild_id/regions.ts5
-rw-r--r--src/api/routes/guilds/#guild_id/roles/#role_id/index.ts16
-rw-r--r--src/api/routes/guilds/#guild_id/roles/index.ts21
-rw-r--r--src/api/routes/guilds/#guild_id/stickers.ts9
-rw-r--r--src/api/routes/guilds/#guild_id/templates.ts14
-rw-r--r--src/api/routes/guilds/#guild_id/vanity-url.ts6
-rw-r--r--src/api/routes/guilds/#guild_id/voice-states/#user_id/index.ts13
-rw-r--r--src/api/routes/guilds/#guild_id/webhooks.ts4
-rw-r--r--src/api/routes/guilds/#guild_id/welcome_screen.ts5
-rw-r--r--src/api/routes/guilds/#guild_id/widget.json.ts6
-rw-r--r--src/api/routes/guilds/#guild_id/widget.png.ts21
-rw-r--r--src/api/routes/guilds/#guild_id/widget.ts4
-rw-r--r--src/api/routes/guilds/index.ts6
-rw-r--r--src/api/routes/guilds/templates/index.ts37
29 files changed, 208 insertions, 160 deletions
diff --git a/src/api/routes/guilds/#guild_id/audit-logs.ts b/src/api/routes/guilds/#guild_id/audit-logs.ts
index b54835fc..05b9982e 100644
--- a/src/api/routes/guilds/#guild_id/audit-logs.ts
+++ b/src/api/routes/guilds/#guild_id/audit-logs.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 const router = Router();
 
 //TODO: implement audit logs
diff --git a/src/api/routes/guilds/#guild_id/bans.ts b/src/api/routes/guilds/#guild_id/bans.ts
index 3d405344..4600b4cb 100644
--- a/src/api/routes/guilds/#guild_id/bans.ts
+++ b/src/api/routes/guilds/#guild_id/bans.ts
@@ -1,8 +1,18 @@
-import { Request, Response, Router } from "express";
-import { DiscordApiErrors, emitEvent, getPermission, GuildBanAddEvent, GuildBanRemoveEvent, Guild, Ban, User, Member, BanRegistrySchema, BanModeratorSchema } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { getIpAdress, route } from "@fosscord/api";
-import { OrmUtils } from "@fosscord/util";
+import {
+	Ban,
+	BanModeratorSchema,
+	BanRegistrySchema,
+	DiscordApiErrors,
+	emitEvent,
+	GuildBanAddEvent,
+	GuildBanRemoveEvent,
+	HTTPError,
+	Member,
+	OrmUtils,
+	User
+} from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
@@ -44,16 +54,16 @@ router.get("/:user", route({ permission: "BAN_MEMBERS" }), async (req: Request,
 	const { guild_id } = req.params;
 	const user_id = req.params.ban;
 
-	let ban = await Ban.findOneOrFail({ where: { guild_id, user_id } }) as BanRegistrySchema;
-	
+	let ban = (await Ban.findOneOrFail({ where: { guild_id, user_id } })) as BanRegistrySchema;
+
 	if (ban.user_id === ban.executor_id) throw DiscordApiErrors.UNKNOWN_BAN;
 	// pretend self-bans don't exist to prevent victim chasing
-	
+
 	/* Filter secret from registry. */
-	
+
 	ban = ban as BanModeratorSchema;
 
-	delete ban.ip
+	delete ban.ip;
 
 	return res.json(ban);
 });
@@ -62,14 +72,14 @@ router.put("/:user_id", route({ body: "BanCreateSchema", permission: "BAN_MEMBER
 	const { guild_id } = req.params;
 	const banned_user_id = req.params.user_id;
 
-	if ( (req.user_id === banned_user_id) && (banned_user_id === req.permission!.cache.guild?.owner_id))
+	if (req.user_id === banned_user_id && banned_user_id === req.permission!.cache.guild?.owner_id)
 		throw new HTTPError("You are the guild owner, hence can't ban yourself", 403);
-	
+
 	if (req.permission!.cache.guild?.owner_id === banned_user_id) throw new HTTPError("You can't ban the owner", 400);
-	
+
 	const banned_user = await User.getPublicUser(banned_user_id);
 
-	const ban = OrmUtils.mergeDeep(new Ban(),{
+	const ban = OrmUtils.mergeDeep(new Ban(), {
 		user_id: banned_user_id,
 		guild_id: guild_id,
 		ip: getIpAdress(req),
@@ -93,14 +103,14 @@ router.put("/:user_id", route({ body: "BanCreateSchema", permission: "BAN_MEMBER
 	return res.json(ban);
 });
 
-router.put("/@me", route({ body: "BanCreateSchema"}), async (req: Request, res: Response) => {
+router.put("/@me", route({ body: "BanCreateSchema" }), async (req: Request, res: Response) => {
 	const { guild_id } = req.params;
 
 	const banned_user = await User.getPublicUser(req.params.user_id);
 
-	if (req.permission!.cache.guild?.owner_id === req.params.user_id) 
+	if (req.permission!.cache.guild?.owner_id === req.params.user_id)
 		throw new HTTPError("You are the guild owner, hence can't ban yourself", 403);
-	
+
 	const ban = OrmUtils.mergeDeep(new Ban(), {
 		user_id: req.params.user_id,
 		guild_id: guild_id,
@@ -129,12 +139,12 @@ router.delete("/:user_id", route({ permission: "BAN_MEMBERS" }), async (req: Req
 	const { guild_id, user_id } = req.params;
 
 	let ban = await Ban.findOneOrFail({ where: { guild_id, user_id } });
-	
+
 	if (ban.user_id === ban.executor_id) throw DiscordApiErrors.UNKNOWN_BAN;
 	// make self-bans irreversible and hide them from view to avoid victim chasing
-	
+
 	const banned_user = await User.getPublicUser(user_id);
-	
+
 	await Promise.all([
 		Ban.delete({
 			user_id: user_id,
diff --git a/src/api/routes/guilds/#guild_id/channels.ts b/src/api/routes/guilds/#guild_id/channels.ts
index 8f2d3643..3563eb4c 100644
--- a/src/api/routes/guilds/#guild_id/channels.ts
+++ b/src/api/routes/guilds/#guild_id/channels.ts
@@ -1,7 +1,6 @@
-import { Router, Response, Request } from "express";
-import { Channel, ChannelUpdateEvent, getPermission, emitEvent, ChannelModifySchema, ChannelReorderSchema } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Channel, ChannelModifySchema, ChannelReorderSchema, ChannelUpdateEvent, emitEvent, HTTPError } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 const router = Router();
 
 router.get("/", route({}), async (req: Request, res: Response) => {
diff --git a/src/api/routes/guilds/#guild_id/delete.ts b/src/api/routes/guilds/#guild_id/delete.ts
index e2624651..e6a1a6b2 100644
--- a/src/api/routes/guilds/#guild_id/delete.ts
+++ b/src/api/routes/guilds/#guild_id/delete.ts
@@ -1,7 +1,6 @@
-import { Channel, emitEvent, GuildDeleteEvent, Guild, Member, Message, Role, Invite, Emoji } from "@fosscord/util";
-import { Router, Request, Response } from "express";
-import { HTTPError } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { emitEvent, Guild, GuildDeleteEvent, HTTPError } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/guilds/#guild_id/discovery-requirements.ts b/src/api/routes/guilds/#guild_id/discovery-requirements.ts
index ad20633f..c0260fe7 100644
--- a/src/api/routes/guilds/#guild_id/discovery-requirements.ts
+++ b/src/api/routes/guilds/#guild_id/discovery-requirements.ts
@@ -1,38 +1,36 @@
-import { Guild, Config } from "@fosscord/util";
-
-import { Router, Request, Response } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
 router.get("/", route({}), async (req: Request, res: Response) => {
-	const { guild_id } = req.params;	
-    // TODO:
-    // Load from database
-    // Admin control, but for now it allows anyone to be discoverable
+	const { guild_id } = req.params;
+	// TODO:
+	// Load from database
+	// Admin control, but for now it allows anyone to be discoverable
 
 	res.send({
 		guild_id: guild_id,
 		safe_environment: true,
-        healthy: true,
-        health_score_pending: false,
-        size: true,
-        nsfw_properties: {},
-        protected: true,
-        sufficient: true,
-        sufficient_without_grace_period: true,
-        valid_rules_channel: true,
-        retention_healthy: true,
-        engagement_healthy: true,
-        age: true,
-        minimum_age: 0,
-        health_score: {
-            avg_nonnew_participators: 0,
-            avg_nonnew_communicators: 0,
-            num_intentful_joiners: 0,
-            perc_ret_w1_intentful: 0
-        },
-        minimum_size: 0
+		healthy: true,
+		health_score_pending: false,
+		size: true,
+		nsfw_properties: {},
+		protected: true,
+		sufficient: true,
+		sufficient_without_grace_period: true,
+		valid_rules_channel: true,
+		retention_healthy: true,
+		engagement_healthy: true,
+		age: true,
+		minimum_age: 0,
+		health_score: {
+			avg_nonnew_participators: 0,
+			avg_nonnew_communicators: 0,
+			num_intentful_joiners: 0,
+			perc_ret_w1_intentful: 0
+		},
+		minimum_size: 0
 	});
 });
 
diff --git a/src/api/routes/guilds/#guild_id/emojis.ts b/src/api/routes/guilds/#guild_id/emojis.ts
index 4bf4bdcd..db5ae325 100644
--- a/src/api/routes/guilds/#guild_id/emojis.ts
+++ b/src/api/routes/guilds/#guild_id/emojis.ts
@@ -1,7 +1,19 @@
-import { Router, Request, Response } from "express";
-import { Config, DiscordApiErrors, emitEvent, Emoji, EmojiCreateSchema, EmojiModifySchema, GuildEmojisUpdateEvent, handleFile, Member, Snowflake, User } from "@fosscord/util";
 import { route } from "@fosscord/api";
-import { OrmUtils } from "@fosscord/util";
+import {
+	Config,
+	DiscordApiErrors,
+	emitEvent,
+	Emoji,
+	EmojiCreateSchema,
+	EmojiModifySchema,
+	GuildEmojisUpdateEvent,
+	handleFile,
+	Member,
+	OrmUtils,
+	Snowflake,
+	User
+} from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/guilds/#guild_id/index.ts b/src/api/routes/guilds/#guild_id/index.ts
index a9712c71..af889982 100644
--- a/src/api/routes/guilds/#guild_id/index.ts
+++ b/src/api/routes/guilds/#guild_id/index.ts
@@ -1,8 +1,18 @@
-import { Request, Response, Router } from "express";
-import { DiscordApiErrors, emitEvent, getPermission, getRights, Guild, GuildUpdateEvent, GuildUpdateSchema, handleFile, Member } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { route } from "@fosscord/api";
-import { OrmUtils } from "@fosscord/util";
+import {
+	DiscordApiErrors,
+	emitEvent,
+	getPermission,
+	getRights,
+	Guild,
+	GuildUpdateEvent,
+	GuildUpdateSchema,
+	handleFile,
+	HTTPError,
+	Member,
+	OrmUtils
+} from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
@@ -21,17 +31,16 @@ router.get("/", route({}), async (req: Request, res: Response) => {
 	return res.send(guild);
 });
 
-router.patch("/", route({ body: "GuildUpdateSchema"}), async (req: Request, res: Response) => {
+router.patch("/", route({ body: "GuildUpdateSchema" }), async (req: Request, res: Response) => {
 	const body = req.body as GuildUpdateSchema;
 	const { guild_id } = req.params;
-	
-	
+
 	const rights = await getRights(req.user_id);
 	const permission = await getPermission(req.user_id, guild_id);
-	
-	if (!rights.has("MANAGE_GUILDS")||!permission.has("MANAGE_GUILD"))
+
+	if (!rights.has("MANAGE_GUILDS") || !permission.has("MANAGE_GUILD"))
 		throw DiscordApiErrors.MISSING_PERMISSIONS.withParams("MANAGE_GUILD");
-	
+
 	// TODO: guild update check image
 
 	if (body.icon) body.icon = await handleFile(`/icons/${guild_id}`, body.icon);
diff --git a/src/api/routes/guilds/#guild_id/integrations.ts b/src/api/routes/guilds/#guild_id/integrations.ts
index 90650111..6a5abec3 100644
--- a/src/api/routes/guilds/#guild_id/integrations.ts
+++ b/src/api/routes/guilds/#guild_id/integrations.ts
@@ -1,7 +1,5 @@
-import { Router, Response, Request } from "express";
-import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 const router = Router();
 
 //TODO: implement integrations list
diff --git a/src/api/routes/guilds/#guild_id/invites.ts b/src/api/routes/guilds/#guild_id/invites.ts
index b7534e31..c663df72 100644
--- a/src/api/routes/guilds/#guild_id/invites.ts
+++ b/src/api/routes/guilds/#guild_id/invites.ts
@@ -1,5 +1,5 @@
-import { getPermission, Invite, PublicInviteRelation } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Invite, PublicInviteRelation } from "@fosscord/util";
 import { Request, Response, Router } from "express";
 
 const router = Router();
diff --git a/src/api/routes/guilds/#guild_id/members/#member_id/index.ts b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts
index 794369d8..57152f9a 100644
--- a/src/api/routes/guilds/#guild_id/members/#member_id/index.ts
+++ b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts
@@ -1,8 +1,18 @@
-import { Request, Response, Router } from "express";
-import { Member, getPermission, getRights, Role, GuildMemberUpdateEvent, emitEvent, Sticker, Emoji, Rights, Guild, MemberChangeSchema } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { route } from "@fosscord/api";
-import { OrmUtils } from "@fosscord/util";
+import {
+	emitEvent,
+	Emoji,
+	getPermission,
+	getRights,
+	Guild,
+	GuildMemberUpdateEvent,
+	Member,
+	MemberChangeSchema,
+	OrmUtils,
+	Role,
+	Sticker
+} from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
@@ -46,7 +56,6 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re
 });
 
 router.put("/", route({}), async (req: Request, res: Response) => {
-
 	// TODO: Lurker mode
 
 	const rights = await getRights(req.user_id);
@@ -56,7 +65,7 @@ router.put("/", route({}), async (req: Request, res: Response) => {
 		member_id = req.user_id;
 		rights.hasThrow("JOIN_GUILDS");
 	} else {
-		// TODO: join others by controller	
+		// TODO: join others by controller
 	}
 
 	let guild = await Guild.findOneOrFail({
diff --git a/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts b/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts
index a6c71333..26411f97 100644
--- a/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts
+++ b/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts
@@ -1,5 +1,5 @@
-import { getPermission, Member, PermissionResolvable } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { getPermission, Member, PermissionResolvable } from "@fosscord/util";
 import { Request, Response, Router } from "express";
 
 const router = Router();
diff --git a/src/api/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts b/src/api/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts
index 8f5ca7ba..0aa7a4dc 100644
--- a/src/api/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts
+++ b/src/api/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts
@@ -1,5 +1,5 @@
-import { getPermission, Member } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Member } from "@fosscord/util";
 import { Request, Response, Router } from "express";
 
 const router = Router();
diff --git a/src/api/routes/guilds/#guild_id/members/index.ts b/src/api/routes/guilds/#guild_id/members/index.ts
index 2ed28bda..08164626 100644
--- a/src/api/routes/guilds/#guild_id/members/index.ts
+++ b/src/api/routes/guilds/#guild_id/members/index.ts
@@ -1,8 +1,7 @@
-import { Request, Response, Router } from "express";
-import { Guild, Member, PublicMemberProjection } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { HTTPError, Member, PublicMemberProjection } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 import { MoreThan } from "typeorm";
-import { HTTPError } from "@fosscord/util";
 
 const router = Router();
 
diff --git a/src/api/routes/guilds/#guild_id/premium.ts b/src/api/routes/guilds/#guild_id/premium.ts
index 75361ac6..b7716378 100644
--- a/src/api/routes/guilds/#guild_id/premium.ts
+++ b/src/api/routes/guilds/#guild_id/premium.ts
@@ -1,5 +1,5 @@
-import { Router, Request, Response } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 const router = Router();
 
 router.get("/subscriptions", route({}), async (req: Request, res: Response) => {
diff --git a/src/api/routes/guilds/#guild_id/prune.ts b/src/api/routes/guilds/#guild_id/prune.ts
index 673f022f..3645721c 100644
--- a/src/api/routes/guilds/#guild_id/prune.ts
+++ b/src/api/routes/guilds/#guild_id/prune.ts
@@ -1,7 +1,7 @@
-import { Router, Request, Response } from "express";
-import { Guild, Member, Snowflake } from "@fosscord/util";
-import { LessThan, IsNull } from "typeorm";
 import { route } from "@fosscord/api";
+import { Guild, Member, Snowflake } from "@fosscord/util";
+import { Request, Response, Router } from "express";
+import { IsNull, LessThan } from "typeorm";
 const router = Router();
 
 //Returns all inactive members, respecting role hierarchy
diff --git a/src/api/routes/guilds/#guild_id/regions.ts b/src/api/routes/guilds/#guild_id/regions.ts
index 308d5ee5..aa57ec65 100644
--- a/src/api/routes/guilds/#guild_id/regions.ts
+++ b/src/api/routes/guilds/#guild_id/regions.ts
@@ -1,7 +1,6 @@
-import { Config, Guild, Member } from "@fosscord/util";
+import { getIpAdress, getVoiceRegions, route } from "@fosscord/api";
+import { Guild } from "@fosscord/util";
 import { Request, Response, Router } from "express";
-import { getVoiceRegions, route } from "@fosscord/api";
-import { getIpAdress } from "@fosscord/api";
 
 const router = Router();
 
diff --git a/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts b/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts
index d4422a9c..7f9dbc6f 100644
--- a/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts
+++ b/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts
@@ -1,8 +1,16 @@
-import { Router, Request, Response } from "express";
-import { Role, Member, GuildRoleUpdateEvent, GuildRoleDeleteEvent, emitEvent, handleFile, RoleModifySchema } from "@fosscord/util";
 import { route } from "@fosscord/api";
-import { HTTPError } from "@fosscord/util";
-import { OrmUtils } from "@fosscord/util";
+import {
+	emitEvent,
+	GuildRoleDeleteEvent,
+	GuildRoleUpdateEvent,
+	handleFile,
+	HTTPError,
+	Member,
+	OrmUtils,
+	Role,
+	RoleModifySchema
+} from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/guilds/#guild_id/roles/index.ts b/src/api/routes/guilds/#guild_id/roles/index.ts
index 17f0b5e9..9791f7a9 100644
--- a/src/api/routes/guilds/#guild_id/roles/index.ts
+++ b/src/api/routes/guilds/#guild_id/roles/index.ts
@@ -1,21 +1,18 @@
-import { Request, Response, Router } from "express";
+import { route } from "@fosscord/api";
 import {
-	Role,
+	Config,
+	DiscordApiErrors,
+	emitEvent,
 	getPermission,
-	Member,
 	GuildRoleCreateEvent,
 	GuildRoleUpdateEvent,
-	GuildRoleDeleteEvent,
-	emitEvent,
-	Config,
-	DiscordApiErrors,
-	handleFile,
+	Member,
+	OrmUtils,
+	Role,
 	RoleModifySchema,
 	RolePositionUpdateSchema
 } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
-import { route } from "@fosscord/api";
-import { OrmUtils } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
@@ -38,7 +35,7 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" })
 
 	if (role_count > maxRoles) throw DiscordApiErrors.MAXIMUM_ROLES.withParams(maxRoles);
 
-	let role: Role = OrmUtils.mergeDeep(new Role(),{
+	let role: Role = OrmUtils.mergeDeep(new Role(), {
 		// values before ...body are default and can be overriden
 		position: 0,
 		hoist: false,
diff --git a/src/api/routes/guilds/#guild_id/stickers.ts b/src/api/routes/guilds/#guild_id/stickers.ts
index 71c9dfcd..15741780 100644
--- a/src/api/routes/guilds/#guild_id/stickers.ts
+++ b/src/api/routes/guilds/#guild_id/stickers.ts
@@ -1,20 +1,19 @@
+import { route } from "@fosscord/api";
 import {
 	emitEvent,
 	GuildStickersUpdateEvent,
-	handleFile,
+	HTTPError,
 	Member,
 	ModifyGuildStickerSchema,
+	OrmUtils,
 	Snowflake,
 	Sticker,
 	StickerFormatType,
 	StickerType,
 	uploadFile
 } from "@fosscord/util";
-import { Router, Request, Response } from "express";
-import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 import multer from "multer";
-import { HTTPError } from "@fosscord/util";
-import { OrmUtils } from "@fosscord/util";
 const router = Router();
 
 router.get("/", route({}), async (req: Request, res: Response) => {
diff --git a/src/api/routes/guilds/#guild_id/templates.ts b/src/api/routes/guilds/#guild_id/templates.ts
index 9c79692d..448ee033 100644
--- a/src/api/routes/guilds/#guild_id/templates.ts
+++ b/src/api/routes/guilds/#guild_id/templates.ts
@@ -1,9 +1,6 @@
+import { generateCode, route } from "@fosscord/api";
+import { Guild, HTTPError, OrmUtils, Template } from "@fosscord/util";
 import { Request, Response, Router } from "express";
-import { Guild, Template } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
-import { route } from "@fosscord/api";
-import { generateCode } from "@fosscord/api";
-import { OrmUtils } from "@fosscord/util";
 
 const router: Router = Router();
 
@@ -75,7 +72,12 @@ router.patch("/:code", route({ body: "TemplateModifySchema", permission: "MANAGE
 	const { code, guild_id } = req.params;
 	const { name, description } = req.body;
 
-	const template = await OrmUtils.mergeDeep(new Template(), { code, name: name, description: description, source_guild_id: guild_id }).save();
+	const template = await OrmUtils.mergeDeep(new Template(), {
+		code,
+		name: name,
+		description: description,
+		source_guild_id: guild_id
+	}).save();
 
 	res.json(template);
 });
diff --git a/src/api/routes/guilds/#guild_id/vanity-url.ts b/src/api/routes/guilds/#guild_id/vanity-url.ts
index ff92ce8d..bf2db134 100644
--- a/src/api/routes/guilds/#guild_id/vanity-url.ts
+++ b/src/api/routes/guilds/#guild_id/vanity-url.ts
@@ -1,8 +1,6 @@
-import { Channel, ChannelType, getPermission, Guild, Invite, trimSpecial, VanityUrlSchema } from "@fosscord/util";
-import { Router, Request, Response } from "express";
 import { route } from "@fosscord/api";
-import { HTTPError } from "@fosscord/util";
-import { OrmUtils } from "@fosscord/util";
+import { Channel, ChannelType, Guild, HTTPError, Invite, OrmUtils, VanityUrlSchema } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/guilds/#guild_id/voice-states/#user_id/index.ts b/src/api/routes/guilds/#guild_id/voice-states/#user_id/index.ts
index 28a9e8c1..797d348e 100644
--- a/src/api/routes/guilds/#guild_id/voice-states/#user_id/index.ts
+++ b/src/api/routes/guilds/#guild_id/voice-states/#user_id/index.ts
@@ -1,7 +1,16 @@
-import { Channel, ChannelType, DiscordApiErrors, emitEvent, getPermission, VoiceState, VoiceStateUpdateEvent, VoiceStateUpdateSchema } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import {
+	Channel,
+	ChannelType,
+	DiscordApiErrors,
+	emitEvent,
+	getPermission,
+	OrmUtils,
+	VoiceState,
+	VoiceStateUpdateEvent,
+	VoiceStateUpdateSchema
+} from "@fosscord/util";
 import { Request, Response, Router } from "express";
-import { OrmUtils } from "@fosscord/util";
 
 const router = Router();
 router.patch("/", route({ body: "VoiceStateUpdateSchema" }), async (req: Request, res: Response) => {
diff --git a/src/api/routes/guilds/#guild_id/webhooks.ts b/src/api/routes/guilds/#guild_id/webhooks.ts
index c8c1eb5c..80e6a59a 100644
--- a/src/api/routes/guilds/#guild_id/webhooks.ts
+++ b/src/api/routes/guilds/#guild_id/webhooks.ts
@@ -1,7 +1,5 @@
-import { Router, Response, Request } from "express";
-import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 const router = Router();
 
 //TODO: implement webhooks
diff --git a/src/api/routes/guilds/#guild_id/welcome_screen.ts b/src/api/routes/guilds/#guild_id/welcome_screen.ts
index d08300ba..85c22a19 100644
--- a/src/api/routes/guilds/#guild_id/welcome_screen.ts
+++ b/src/api/routes/guilds/#guild_id/welcome_screen.ts
@@ -1,7 +1,6 @@
-import { Request, Response, Router } from "express";
-import { Guild, getPermission, Snowflake, Member, GuildUpdateWelcomeScreenSchema } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Guild, GuildUpdateWelcomeScreenSchema, HTTPError, Member } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
diff --git a/src/api/routes/guilds/#guild_id/widget.json.ts b/src/api/routes/guilds/#guild_id/widget.json.ts
index 37739418..368fe46e 100644
--- a/src/api/routes/guilds/#guild_id/widget.json.ts
+++ b/src/api/routes/guilds/#guild_id/widget.json.ts
@@ -1,8 +1,6 @@
-import { Request, Response, Router } from "express";
-import { Config, Permissions, Guild, Invite, Channel, Member } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { random, route } from "@fosscord/api";
-import { OrmUtils } from "@fosscord/util";
+import { Channel, Guild, HTTPError, Invite, Member, OrmUtils, Permissions } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
diff --git a/src/api/routes/guilds/#guild_id/widget.png.ts b/src/api/routes/guilds/#guild_id/widget.png.ts
index a61d938d..1c4ef29b 100644
--- a/src/api/routes/guilds/#guild_id/widget.png.ts
+++ b/src/api/routes/guilds/#guild_id/widget.png.ts
@@ -1,10 +1,19 @@
-import { Request, Response, Router } from "express";
-import { Guild } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Guild, HTTPError } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 import fs from "fs";
 import path from "path";
 
+// Setup canvas
+let createCanvas: any, loadImage: any;
+try {
+	createCanvas = require("canvas").createCanvas;
+	loadImage = require("canvas").loadImage;
+} catch {
+	console.log("Canvas not found, disabling widgets!");
+}
+const sizeOf = require("image-size");
+
 const router: Router = Router();
 
 // TODO: use svg templates instead of node-canvas for improved performance and to change it easily
@@ -12,6 +21,7 @@ const router: Router = Router();
 // https://discord.com/developers/docs/resources/guild#get-guild-widget-image
 // TODO: Cache the response
 router.get("/", route({}), async (req: Request, res: Response) => {
+	if (!createCanvas) return res.status(404);
 	const { guild_id } = req.params;
 
 	const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
@@ -28,11 +38,6 @@ router.get("/", route({}), async (req: Request, res: Response) => {
 		throw new HTTPError("Value must be one of ('shield', 'banner1', 'banner2', 'banner3', 'banner4').", 400);
 	}
 
-	// Setup canvas
-	const { createCanvas } = require("canvas");
-	const { loadImage } = require("canvas");
-	const sizeOf = require("image-size");
-
 	// TODO: Widget style templates need Fosscord branding
 	const source = path.join(__dirname, "..", "..", "..", "..", "..", "assets", "widget", `${style}.png`);
 	if (!fs.existsSync(source)) {
diff --git a/src/api/routes/guilds/#guild_id/widget.ts b/src/api/routes/guilds/#guild_id/widget.ts
index dbb4cc0c..d2369dd1 100644
--- a/src/api/routes/guilds/#guild_id/widget.ts
+++ b/src/api/routes/guilds/#guild_id/widget.ts
@@ -1,6 +1,6 @@
-import { Request, Response, Router } from "express";
-import { Guild, WidgetModifySchema } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Guild, WidgetModifySchema } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
diff --git a/src/api/routes/guilds/index.ts b/src/api/routes/guilds/index.ts
index e4d66192..6946e2f7 100644
--- a/src/api/routes/guilds/index.ts
+++ b/src/api/routes/guilds/index.ts
@@ -1,6 +1,6 @@
-import { Router, Request, Response } from "express";
-import { Role, Guild, Snowflake, Config, getRights, Member, Channel, DiscordApiErrors, handleFile, GuildCreateSchema } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Config, DiscordApiErrors, getRights, Guild, GuildCreateSchema, Member } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
@@ -12,7 +12,7 @@ router.post("/", route({ body: "GuildCreateSchema", right: "CREATE_GUILDS" }), a
 	const { maxGuilds } = Config.get().limits.user;
 	const guild_count = await Member.count({ where: { id: req.user_id } });
 	const rights = await getRights(req.user_id);
-	if ((guild_count >= maxGuilds)&&!rights.has("MANAGE_GUILDS")) {
+	if (guild_count >= maxGuilds && !rights.has("MANAGE_GUILDS")) {
 		throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds);
 	}
 
diff --git a/src/api/routes/guilds/templates/index.ts b/src/api/routes/guilds/templates/index.ts
index 3a0de9e8..467186a3 100644
--- a/src/api/routes/guilds/templates/index.ts
+++ b/src/api/routes/guilds/templates/index.ts
@@ -1,6 +1,6 @@
-import { Request, Response, Router } from "express";
-import { Template, Guild, Role, Snowflake, Config, User, Member, DiscordApiErrors, OrmUtils, GuildTemplateCreateSchema } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Config, DiscordApiErrors, Guild, GuildTemplateCreateSchema, Member, OrmUtils, Role, Snowflake, Template } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 import fetch from "node-fetch";
 const router: Router = Router();
 
@@ -9,9 +9,10 @@ router.get("/:code", route({}), async (req: Request, res: Response) => {
 	if (!enabled) res.json({ code: 403, message: "Template creation & usage is disabled on this instance." }).sendStatus(403);
 
 	const { code } = req.params;
-	
+
 	if (code.startsWith("discord:")) {
-		if (!allowDiscordTemplates)	return res.json({ code: 403, message: "Discord templates cannot be used on this instance." }).sendStatus(403);
+		if (!allowDiscordTemplates)
+			return res.json({ code: 403, message: "Discord templates cannot be used on this instance." }).sendStatus(403);
 		const discordTemplateID = code.split("discord:", 2)[1];
 
 		const discordTemplateData = await fetch(`https://discord.com/api/v9/guilds/templates/${discordTemplateID}`, {
@@ -22,7 +23,7 @@ router.get("/:code", route({}), async (req: Request, res: Response) => {
 	}
 
 	if (code.startsWith("external:")) {
-		if (!allowRaws)	return res.json({ code: 403, message: "Importing raws is disabled on this instance." }).sendStatus(403);
+		if (!allowRaws) return res.json({ code: 403, message: "Importing raws is disabled on this instance." }).sendStatus(403);
 
 		return res.json(code.split("external:", 2)[1]);
 	}
@@ -57,18 +58,20 @@ router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req:
 			id: guild_id,
 			owner_id: req.user_id
 		}).save(),
-		(OrmUtils.mergeDeep(new Role(), {
-			id: guild_id,
-			guild_id: guild_id,
-			color: 0,
-			hoist: false,
-			managed: true,
-			mentionable: true,
-			name: "@everyone",
-			permissions: BigInt("2251804225"),
-			position: 0,
-			tags: null
-		}) as Role).save()
+		(
+			OrmUtils.mergeDeep(new Role(), {
+				id: guild_id,
+				guild_id: guild_id,
+				color: 0,
+				hoist: false,
+				managed: true,
+				mentionable: true,
+				name: "@everyone",
+				permissions: BigInt("2251804225"),
+				position: 0,
+				tags: null
+			}) as Role
+		).save()
 	]);
 
 	await Member.addToGuild(req.user_id, guild_id);