summary refs log tree commit diff
path: root/src/api/routes/applications/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/routes/applications/index.ts')
-rw-r--r--src/api/routes/applications/index.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/api/routes/applications/index.ts b/src/api/routes/applications/index.ts
index 1e536a06..27300c4a 100644
--- a/src/api/routes/applications/index.ts
+++ b/src/api/routes/applications/index.ts
@@ -20,6 +20,7 @@ import { route } from "@spacebar/api";
 import {
 	Application,
 	ApplicationCreateSchema,
+	Config,
 	User,
 	trimSpecial,
 } from "@spacebar/util";
@@ -68,6 +69,26 @@ router.post(
 			flags: 0,
 		});
 
+		// april 14, 2023: discord made bot users be automatically added to all new apps
+		const { autoCreateBotUsers } = Config.get().general;
+		if (autoCreateBotUsers) {
+			const user = await User.register({
+				username: app.name,
+				password: undefined,
+				id: app.id,
+				req,
+			});
+
+			user.id = app.id;
+			user.premium_since = new Date();
+			user.bot = true;
+
+			await user.save();
+
+			// flags is NaN here?
+			app.assign({ bot: user, flags: app.flags || 0 });
+		}
+
 		await app.save();
 
 		res.json(app);