diff options
Diffstat (limited to 'util/src/entities/Member.ts')
-rw-r--r-- | util/src/entities/Member.ts | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts index e7e97b7c..7ca50992 100644 --- a/util/src/entities/Member.ts +++ b/util/src/entities/Member.ts @@ -122,17 +122,19 @@ export class Member extends BaseClassWithoutId { } static async removeFromGuild(user_id: string, guild_id: string) { - const guild = await Guild.findOneOrFail({ select: ["owner_id"], where: { id: guild_id } }); + const guild = await Guild.findOneOrFail({ select: ["owner_id", "member_count"], where: { id: guild_id } }); if (guild.owner_id === user_id) throw new Error("The owner cannot be removed of the guild"); const member = await Member.findOneOrFail({ where: { id: user_id, guild_id }, relations: ["user"] }); // use promise all to execute all promises at the same time -> save time + //TODO: check for bugs + if(guild.member_count) guild.member_count--; return Promise.all([ Member.delete({ id: user_id, guild_id, }), - Guild.decrement({ id: guild_id }, "member_count", -1), + //Guild.decrement({ id: guild_id }, "member_count", -1), emitEvent({ event: "GUILD_DELETE", @@ -259,7 +261,8 @@ export class Member extends BaseClassWithoutId { mute: false, pending: false, }; - + //TODO: check for bugs + if(guild.member_count) guild.member_count++; await Promise.all([ new Member({ ...member, @@ -276,7 +279,7 @@ export class Member extends BaseClassWithoutId { }, // Member.save is needed because else the roles relations wouldn't be updated }).save(), - Guild.increment({ id: guild_id }, "member_count", 1), + //Guild.increment({ id: guild_id }, "member_count", 1), emitEvent({ event: "GUILD_MEMBER_ADD", data: { |