mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 17:04:15 +02:00
refactor(arabot): change naming for xp to next level
This commit is contained in:
parent
304f5996fb
commit
f76cc38df0
@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `xpToNextLevel` on the `Xp` table. All the data in the column will be lost.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Xp" DROP COLUMN "xpToNextLevel",
|
||||||
|
ADD COLUMN "xpForNextLevel" INTEGER NOT NULL DEFAULT 0;
|
@ -98,13 +98,13 @@ model Verify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Xp {
|
model Xp {
|
||||||
user User @relation(fields: [userId], references: [id])
|
user User @relation(fields: [userId], references: [id])
|
||||||
userId String @id
|
userId String @id
|
||||||
level Int @default(0)
|
level Int @default(0)
|
||||||
xp Int @default(0)
|
xp Int @default(0)
|
||||||
xpToNextLevel Int @default(0)
|
xpForNextLevel Int @default(0)
|
||||||
messageCount Int @default(0)
|
messageCount Int @default(0)
|
||||||
lastMessage DateTime @default(now())
|
lastMessage DateTime @default(now())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Economy
|
// Economy
|
||||||
|
@ -13,7 +13,7 @@ export async function getUser(userId: Snowflake) {
|
|||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
xp: true,
|
xp: true,
|
||||||
xpToNextLevel: true,
|
xpForNextLevel: true,
|
||||||
level: true,
|
level: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -22,16 +22,16 @@ export async function getUser(userId: Snowflake) {
|
|||||||
|
|
||||||
export async function addXp(userId: Snowflake, xp: number) {
|
export async function addXp(userId: Snowflake, xp: number) {
|
||||||
const user = await getUser(userId);
|
const user = await getUser(userId);
|
||||||
let xpNextLevel = xp;
|
let xpForNextLevel = xp;
|
||||||
|
|
||||||
let level = 0;
|
let level = 0;
|
||||||
if (user !== null) {
|
if (user !== null) {
|
||||||
xpNextLevel = xpToNextLevel(user.level, user.xpToNextLevel + xp);
|
xpForNextLevel = xpToNextLevel(user.level, user.xpForNextLevel + xp);
|
||||||
if (xpNextLevel < 0) {
|
if (xpForNextLevel < 0) {
|
||||||
xpNextLevel = -xpNextLevel;
|
xpForNextLevel = -xpForNextLevel;
|
||||||
level = 1;
|
level = 1;
|
||||||
} else {
|
} else {
|
||||||
xpNextLevel = user.xpToNextLevel + xp;
|
xpForNextLevel = user.xpForNextLevel + xp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ export async function addXp(userId: Snowflake, xp: number) {
|
|||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
xp: { increment: xp },
|
xp: { increment: xp },
|
||||||
xpToNextLevel: xpNextLevel,
|
xpForNextLevel,
|
||||||
level: { increment: level },
|
level: { increment: level },
|
||||||
messageCount: { increment: 1 },
|
messageCount: { increment: 1 },
|
||||||
lastMessage: new Date(),
|
lastMessage: new Date(),
|
||||||
@ -59,7 +59,7 @@ export async function addXp(userId: Snowflake, xp: number) {
|
|||||||
},
|
},
|
||||||
messageCount: 1,
|
messageCount: 1,
|
||||||
xp,
|
xp,
|
||||||
xpToNextLevel: xp,
|
xpForNextLevel: xp,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user