diff options
author | Puyodead1 <puyodead@proton.me> | 2023-05-06 23:45:09 -0400 |
---|---|---|
committer | Puyodead1 <puyodead@proton.me> | 2023-05-06 23:53:43 -0400 |
commit | 942cce913dcf00acc94f4a2cefc0902427a6c7b7 (patch) | |
tree | 04762306165888187d68a8d51e9b498f3c201bd7 | |
parent | add flags property to voice state update (diff) | |
download | server-942cce913dcf00acc94f4a2cefc0902427a6c7b7.tar.xz |
add option to auto add bot users to new apps
-rw-r--r-- | assets/openapi.json | 8 | ||||
-rw-r--r-- | assets/schemas.json | 8 | ||||
-rw-r--r-- | src/api/routes/applications/index.ts | 21 | ||||
-rw-r--r-- | src/util/config/types/GeneralConfiguration.ts | 1 |
4 files changed, 38 insertions, 0 deletions
diff --git a/assets/openapi.json b/assets/openapi.json index 2dc78741..14bfb70a 100644 --- a/assets/openapi.json +++ b/assets/openapi.json @@ -5994,6 +5994,9 @@ }, "suppress": { "type": "boolean" + }, + "flags": { + "type": "integer" } }, "required": [ @@ -7190,9 +7193,14 @@ }, "instanceId": { "type": "string" + }, + "autoCreateBotUsers": { + "type": "boolean", + "default": false } }, "required": [ + "autoCreateBotUsers", "correspondenceEmail", "correspondenceUserID", "frontPage", diff --git a/assets/schemas.json b/assets/schemas.json index dc25cacd..68ef8187 100644 --- a/assets/schemas.json +++ b/assets/schemas.json @@ -197032,6 +197032,9 @@ }, "suppress": { "type": "boolean" + }, + "flags": { + "type": "integer" } }, "additionalProperties": false, @@ -422581,10 +422584,15 @@ }, "instanceId": { "type": "string" + }, + "autoCreateBotUsers": { + "type": "boolean", + "default": false } }, "additionalProperties": false, "required": [ + "autoCreateBotUsers", "correspondenceEmail", "correspondenceUserID", "frontPage", 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); diff --git a/src/util/config/types/GeneralConfiguration.ts b/src/util/config/types/GeneralConfiguration.ts index c20fe9a7..cff8c527 100644 --- a/src/util/config/types/GeneralConfiguration.ts +++ b/src/util/config/types/GeneralConfiguration.ts @@ -28,4 +28,5 @@ export class GeneralConfiguration { correspondenceUserID: string | null = null; image: string | null = null; instanceId: string = Snowflake.generate(); + autoCreateBotUsers: boolean = false; } |