From 74bd98737acf89d9d56ee66a68694d82f591d591 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 11:03:32 +0200 Subject: :art: clean up imports + classes --- util/src/entities/User.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'util/src/entities/User.ts') diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts index 97564af3..662ab031 100644 --- a/util/src/entities/User.ts +++ b/util/src/entities/User.ts @@ -198,7 +198,7 @@ export class User extends BaseClass { // randomly generates a discriminator between 1 and 9999 and checks max five times if it already exists // if it all five times already exists, abort with USERNAME_TOO_MANY_USERS error // else just continue - // TODO: is there any better way to generate a random discriminator only once, without checking if it already exists in the mongodb database? + // TODO: is there any better way to generate a random discriminator only once, without checking if it already exists in the database? for (let tries = 0; tries < 5; tries++) { discriminator = Math.randomIntBetween(1, 9999).toString().padStart(4, "0"); exists = await User.findOne({ where: { discriminator, username: username }, select: ["id"] }); @@ -219,7 +219,7 @@ export class User extends BaseClass { // if nsfw_allowed is null/undefined it'll require date_of_birth to set it to true/false const language = req.language === "en" ? "en-US" : req.language || "en-US"; - const user = await new User({ + const user = new User({ created_at: new Date(), username: username, discriminator, @@ -246,7 +246,10 @@ export class User extends BaseClass { }, settings: { ...defaultSettings, locale: language }, fingerprints: [], - }).save(); + }); + + console.log(user); + await user.save(); if (Config.get().guild.autoJoin.enabled) { for (const guild of Config.get().guild.autoJoin.guilds || []) { -- cgit 1.5.1 From 82205520ed302aa5a91fc6a770e7ecf2b6ccc043 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 14:31:13 +0200 Subject: :bug: fix Emoji missing in identify --- bundle/package.json | 2 +- gateway/src/opcodes/Identify.ts | 1 + util/src/entities/User.ts | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) (limited to 'util/src/entities/User.ts') diff --git a/bundle/package.json b/bundle/package.json index 3d41f7c2..eedbdd8c 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -9,7 +9,7 @@ "start": "node scripts/build.js && node dist/bundle/src/start.js", "start:bundle": "node dist/bundle/src/start.js", "test": "echo \"Error: no test specified\" && exit 1", - "migrate": "node node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run" + "migrate": "node --require ts-node/register node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run" }, "repository": { "type": "git", diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index 16ea1904..5950105a 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -65,6 +65,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { "guild", "guild.channels", "guild.emojis", + "guild.emojis.user", "guild.roles", "guild.stickers", "user", diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts index 662ab031..04f1e9cb 100644 --- a/util/src/entities/User.ts +++ b/util/src/entities/User.ts @@ -248,7 +248,6 @@ export class User extends BaseClass { fingerprints: [], }); - console.log(user); await user.save(); if (Config.get().guild.autoJoin.enabled) { -- cgit 1.5.1 From 5249e923a0614e83ac5a7ffb1885308b3f4a936e Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 17 Oct 2021 00:41:24 +0200 Subject: :art: reformatted --- api/tests/routes.test.ts | 2 -- util/src/entities/User.ts | 17 +++++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'util/src/entities/User.ts') diff --git a/api/tests/routes.test.ts b/api/tests/routes.test.ts index 2c265ee3..35d74a94 100644 --- a/api/tests/routes.test.ts +++ b/api/tests/routes.test.ts @@ -56,9 +56,7 @@ beforeAll(async (done) => { const response = await request("/auth/register", { body: { fingerprint: "805826570869932034.wR8vi8lGlFBJerErO9LG5NViJFw", - email: "test@example.com", username: "tester", - password: "wtp9gep9gw", invite: null, consent: true, date_of_birth: "2000-01-01", diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts index 04f1e9cb..bc852616 100644 --- a/util/src/entities/User.ts +++ b/util/src/entities/User.ts @@ -4,7 +4,7 @@ import { BitField } from "../util/BitField"; import { Relationship } from "./Relationship"; import { ConnectedAccount } from "./ConnectedAccount"; import { Config, FieldErrors, Snowflake, trimSpecial } from ".."; -import { Member } from "."; +import { Member, Session } from "."; export enum PublicUserEnum { username, @@ -131,6 +131,9 @@ export class User extends BaseClass { @Column() rights: string; // Rights + @OneToMany(() => Session, (session: Session) => session.user) + sessions: Session[]; + @JoinColumn({ name: "relationship_ids" }) @OneToMany(() => Relationship, (relationship: Relationship) => relationship.from, { cascade: true, @@ -250,11 +253,13 @@ export class User extends BaseClass { await user.save(); - if (Config.get().guild.autoJoin.enabled) { - for (const guild of Config.get().guild.autoJoin.guilds || []) { - await Member.addToGuild(user.id, guild); + setImmediate(async () => { + if (Config.get().guild.autoJoin.enabled) { + for (const guild of Config.get().guild.autoJoin.guilds || []) { + await Member.addToGuild(user.id, guild).catch((e) => {}); + } } - } + }); return user; } @@ -293,7 +298,7 @@ export const defaultSettings: UserSettings = { render_reactions: true, restricted_guilds: [], show_current_game: true, - status: "offline", + status: "online", stream_notifications_enabled: true, theme: "dark", timezone_offset: 0, -- cgit 1.5.1