mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-29 11:59:14 +00:00
Merge pull request #1052 from spacebarchat/feat/auto-create-bot-users
Feat: Auto add bot users to new apps
This commit is contained in:
@@ -28,4 +28,5 @@ export class GeneralConfiguration {
|
||||
correspondenceUserID: string | null = null;
|
||||
image: string | null = null;
|
||||
instanceId: string = Snowflake.generate();
|
||||
autoCreateBotUsers: boolean = false;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -42,3 +42,4 @@ export * from "./Token";
|
||||
export * from "./TraverseDirectory";
|
||||
export * from "./WebAuthn";
|
||||
export * from "./Gifs";
|
||||
export * from "./Application";
|
||||
|
||||
Reference in New Issue
Block a user