diff options
author | Puyodead1 <puyodead@proton.me> | 2023-05-07 00:15:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-07 00:15:04 -0400 |
commit | ba0d1bb6ff678c5a451afd7dad51b27a2e770cd8 (patch) | |
tree | 734d2721cf99205da2439db34e6a399ec4b2546d /src/util | |
parent | add initial_guild_id client state property (diff) | |
parent | fix build failure (diff) | |
download | server-ba0d1bb6ff678c5a451afd7dad51b27a2e770cd8.tar.xz |
Merge pull request #1052 from spacebarchat/feat/auto-create-bot-users
Feat: Auto add bot users to new apps
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/config/types/GeneralConfiguration.ts | 1 | ||||
-rw-r--r-- | src/util/util/Application.ts | 24 | ||||
-rw-r--r-- | src/util/util/index.ts | 1 |
3 files changed, 26 insertions, 0 deletions
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; } diff --git a/src/util/util/Application.ts b/src/util/util/Application.ts new file mode 100644 index 00000000..23019a7f --- /dev/null +++ b/src/util/util/Application.ts @@ -0,0 +1,24 @@ +import { Request } from "express"; +import { Application, User } from "../entities"; + +export async function createAppBotUser(app: Application, req: Request) { + 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(); + + return user; +} diff --git a/src/util/util/index.ts b/src/util/util/index.ts index 3a98be15..10e09b5c 100644 --- a/src/util/util/index.ts +++ b/src/util/util/index.ts @@ -42,3 +42,4 @@ export * from "./Token"; export * from "./TraverseDirectory"; export * from "./WebAuthn"; export * from "./Gifs"; +export * from "./Application"; |