mirror of
				https://github.com/veganhacktivists/arabot.git
				synced 2025-11-04 15:59:48 +01: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;
 | 
			
		||||
@ -102,7 +102,7 @@ model Xp {
 | 
			
		||||
  userId         String   @id
 | 
			
		||||
  level          Int      @default(0)
 | 
			
		||||
  xp             Int      @default(0)
 | 
			
		||||
  xpToNextLevel Int      @default(0)
 | 
			
		||||
  xpForNextLevel Int      @default(0)
 | 
			
		||||
  messageCount   Int      @default(0)
 | 
			
		||||
  lastMessage    DateTime @default(now())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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