mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 13:44:13 +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 {
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId String @id
|
||||
level Int @default(0)
|
||||
xp Int @default(0)
|
||||
xpToNextLevel Int @default(0)
|
||||
messageCount Int @default(0)
|
||||
lastMessage DateTime @default(now())
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
userId String @id
|
||||
level Int @default(0)
|
||||
xp Int @default(0)
|
||||
xpForNextLevel Int @default(0)
|
||||
messageCount Int @default(0)
|
||||
lastMessage DateTime @default(now())
|
||||
}
|
||||
|
||||
// Economy
|
||||
|
@ -13,7 +13,7 @@ export async function getUser(userId: Snowflake) {
|
||||
},
|
||||
select: {
|
||||
xp: true,
|
||||
xpToNextLevel: true,
|
||||
xpForNextLevel: true,
|
||||
level: true,
|
||||
},
|
||||
});
|
||||
@ -22,16 +22,16 @@ export async function getUser(userId: Snowflake) {
|
||||
|
||||
export async function addXp(userId: Snowflake, xp: number) {
|
||||
const user = await getUser(userId);
|
||||
let xpNextLevel = xp;
|
||||
let xpForNextLevel = xp;
|
||||
|
||||
let level = 0;
|
||||
if (user !== null) {
|
||||
xpNextLevel = xpToNextLevel(user.level, user.xpToNextLevel + xp);
|
||||
if (xpNextLevel < 0) {
|
||||
xpNextLevel = -xpNextLevel;
|
||||
xpForNextLevel = xpToNextLevel(user.level, user.xpForNextLevel + xp);
|
||||
if (xpForNextLevel < 0) {
|
||||
xpForNextLevel = -xpForNextLevel;
|
||||
level = 1;
|
||||
} else {
|
||||
xpNextLevel = user.xpToNextLevel + xp;
|
||||
xpForNextLevel = user.xpForNextLevel + xp;
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ export async function addXp(userId: Snowflake, xp: number) {
|
||||
},
|
||||
update: {
|
||||
xp: { increment: xp },
|
||||
xpToNextLevel: xpNextLevel,
|
||||
xpForNextLevel,
|
||||
level: { increment: level },
|
||||
messageCount: { increment: 1 },
|
||||
lastMessage: new Date(),
|
||||
@ -59,7 +59,7 @@ export async function addXp(userId: Snowflake, xp: number) {
|
||||
},
|
||||
messageCount: 1,
|
||||
xp,
|
||||
xpToNextLevel: xp,
|
||||
xpForNextLevel: xp,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user