Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
fix: properly update user
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Feb 18, 2024
1 parent 648e434 commit f86fbfd
Showing 1 changed file with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { users } from "@nezuchan/kanao-schema";
import { RoutingKey } from "@nezuchan/utilities";
import type { GatewayUserUpdateDispatch } from "discord-api-types/v10";
import { GatewayDispatchEvents } from "discord-api-types/v10";
import { eq } from "drizzle-orm";
import type { ListenerContext } from "../../../Stores/Listener.js";
import { Listener } from "../../../Stores/Listener.js";
import { clientId } from "../../../config.js";
Expand All @@ -17,22 +16,39 @@ export class UserUpdateListener extends Listener {
}

public async run(payload: { data: GatewayUserUpdateDispatch; shardId: number; }): Promise<void> {
await this.store.drizzle.update(users).set({
await this.store.drizzle.insert(users).values({
id: payload.data.d.id,
username: payload.data.d.username,
discriminator: payload.data.d.discriminator,
globalName: payload.data.d.global_name,
discriminator: payload.data.d.discriminator ?? null,
globalName: payload.data.d.global_name ?? null,
avatar: payload.data.d.avatar ?? null,
bot: payload.data.d.bot ?? false,
flags: payload.data.d.flags,
accentColor: payload.data.d.accent_color,
avatar: payload.data.d.avatar,
avatarDecoration: payload.data.d.avatar_decoration,
banner: payload.data.d.banner,
bot: payload.data.d.bot,
flags: payload.data.d.flags,
id: payload.data.d.id,
locale: payload.data.d.locale,
mfaEnabled: payload.data.d.mfa_enabled,
premiumType: payload.data.d.premium_type,
publicFlags: payload.data.d.public_flags
}).where(eq(users.id, payload.data.d.id));
}).onConflictDoUpdate({
target: users.id,
set: {
username: payload.data.d.username,
discriminator: payload.data.d.discriminator ?? null,
globalName: payload.data.d.global_name ?? null,
avatar: payload.data.d.avatar ?? null,
bot: payload.data.d.bot ?? false,
flags: payload.data.d.flags,
accentColor: payload.data.d.accent_color,
avatarDecoration: payload.data.d.avatar_decoration,
banner: payload.data.d.banner,
locale: payload.data.d.locale,
mfaEnabled: payload.data.d.mfa_enabled,
premiumType: payload.data.d.premium_type,
publicFlags: payload.data.d.public_flags
}
});

await this.store.amqp.publish(RabbitMQ.GATEWAY_QUEUE_SEND, RoutingKey(clientId, payload.shardId), Buffer.from(JSON.stringify(payload.data)));
}
Expand Down

0 comments on commit f86fbfd

Please sign in to comment.