add name tracking so we can show names in the leaderboard
This commit is contained in:
parent
21971afabc
commit
3756ebc128
|
@ -41,6 +41,25 @@ const command = {
|
|||
},
|
||||
});
|
||||
|
||||
if (user && msg.senderUsername !== user.name) {
|
||||
const changeName = await prisma.user.update({
|
||||
where: {
|
||||
userId: msg.senderUserID,
|
||||
},
|
||||
data: {
|
||||
name: msg.senderUsername,
|
||||
},
|
||||
});
|
||||
|
||||
if (!changeName) {
|
||||
await client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, detected name change but something went wrong changing it`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch (splitted[2]) {
|
||||
case "start": {
|
||||
if (user) {
|
||||
|
@ -54,6 +73,7 @@ const command = {
|
|||
const createUser = await prisma.user.create({
|
||||
data: {
|
||||
userId: msg.senderUserID,
|
||||
name: msg.senderUsername,
|
||||
megis: {
|
||||
create: {
|
||||
megis: 0,
|
||||
|
@ -149,6 +169,30 @@ const command = {
|
|||
break;
|
||||
}
|
||||
|
||||
case "lb": {
|
||||
const allMegisers = await prisma.user.findMany({
|
||||
take: 3,
|
||||
orderBy: {
|
||||
megis: {
|
||||
megis: "desc",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
megis: true,
|
||||
},
|
||||
});
|
||||
|
||||
await client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, top megisers! ${allMegisers.map(
|
||||
(item, index) =>
|
||||
` ${index + 1}. ${item.name}: ${item.megis.megis} megis! `
|
||||
)}`
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
if (!user) {
|
||||
await client.say(
|
||||
|
@ -212,28 +256,6 @@ const command = {
|
|||
|
||||
break;
|
||||
}
|
||||
|
||||
case "lb": {
|
||||
const allMegisers = await prisma.user.findMany({
|
||||
take: 3,
|
||||
orderBy: {
|
||||
megis: {
|
||||
megis: "desc",
|
||||
},
|
||||
},
|
||||
include: {
|
||||
megis: true,
|
||||
},
|
||||
});
|
||||
|
||||
await client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, top megisers! ${allMegisers.map(
|
||||
(item, index) =>
|
||||
`${index + 1}. ${item.userId}: ${item.megis.megis} megis! `
|
||||
)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `name` to the `User` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_User" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"userId" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
INSERT INTO "new_User" ("createdAt", "id", "updatedAt", "userId") SELECT "createdAt", "id", "updatedAt", "userId" FROM "User";
|
||||
DROP TABLE "User";
|
||||
ALTER TABLE "new_User" RENAME TO "User";
|
||||
CREATE UNIQUE INDEX "User_userId_key" ON "User"("userId");
|
||||
CREATE UNIQUE INDEX "User_name_key" ON "User"("name");
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
|
@ -13,6 +13,7 @@ datasource db {
|
|||
model User {
|
||||
id String @id @default(uuid())
|
||||
userId String @unique
|
||||
name String @unique
|
||||
megis Megis?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
|
|
Loading…
Reference in New Issue