summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2023-05-07 00:00:42 -0400
committerPuyodead1 <puyodead@proton.me>2023-05-07 00:00:42 -0400
commitbb22e42da93f9e9a6ea5c00980cff9c865ea3c48 (patch)
tree6759f8b810cf413eb36f08f2d55da02f8198126d /src/util
parentadd option to auto add bot users to new apps (diff)
downloadserver-bb22e42da93f9e9a6ea5c00980cff9c865ea3c48.tar.xz
create util for app bot user creation
Diffstat (limited to 'src/util')
-rw-r--r--src/util/util/Application.ts24
-rw-r--r--src/util/util/index.ts1
2 files changed, 25 insertions, 0 deletions
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..6076f70a 100644 --- a/src/util/util/index.ts +++ b/src/util/util/index.ts
@@ -18,6 +18,7 @@ export * from "./ApiError"; export * from "./Array"; +export * from "./Application"; export * from "./BitField"; //export * from "./Categories"; export * from "./cdn";