@@ -27,16 +27,16 @@ import { generateAllGearImage, generateGearImage } from '@/lib/canvas/generateGe
2727import type { IconPackID } from '@/lib/canvas/iconPacks.js' ;
2828import { ClueTiers } from '@/lib/clues/clueTiers.js' ;
2929import { type CATier , CombatAchievements } from '@/lib/combat_achievements/combatAchievements.js' ;
30- import { BitField , MAX_LEVEL , projectiles } from '@/lib/constants.js' ;
30+ import { BitField , MAX_LEVEL } from '@/lib/constants.js' ;
3131import { bossCLItems } from '@/lib/data/Collections.js' ;
3232import { allPetIDs , avasDevices } from '@/lib/data/CollectionsExport.js' ;
3333import { degradeableItems } from '@/lib/degradeableItems.js' ;
3434import { diaries , userhasDiaryTierSync } from '@/lib/diaries.js' ;
3535import type { CommandResponseValue } from '@/lib/discord/index.js' ;
3636import { mentionCommand } from '@/lib/discord/utils.js' ;
37+ import { projectiles } from '@/lib/gear/projectiles.js' ;
3738import type { GearSetup , UserFullGearSetup } from '@/lib/gear/types.js' ;
3839import { handleNewCLItems } from '@/lib/handleNewCLItems.js' ;
39- import { marketPriceOfBank } from '@/lib/marketPrices.js' ;
4040import backgroundImages from '@/lib/minions/data/bankBackgrounds.js' ;
4141import type { CombatOptionsEnum } from '@/lib/minions/data/combatConstants.js' ;
4242import { type AddMonsterXpParams , addMonsterXPRaw } from '@/lib/minions/functions/addMonsterXPRaw.js' ;
@@ -1094,52 +1094,6 @@ Charge your items using ${mentionCommand('minion', 'charge')}.`
10941094 } ;
10951095 }
10961096
1097- async calculateNetWorth ( ) {
1098- const bank = this . allItemsOwned . clone ( ) ;
1099- const activeListings = await prisma . gEListing . findMany ( {
1100- where : {
1101- user_id : this . id ,
1102- quantity_remaining : {
1103- gt : 0
1104- } ,
1105- fulfilled_at : null ,
1106- cancelled_at : null
1107- } ,
1108- include : {
1109- buyTransactions : true ,
1110- sellTransactions : true
1111- }
1112- } ) ;
1113- for ( const listing of activeListings ) {
1114- if ( listing . type === 'Sell' ) {
1115- bank . add ( listing . item_id , listing . quantity_remaining ) ;
1116- } else {
1117- bank . add ( 'Coins' , Number ( listing . asking_price_per_item ) * listing . quantity_remaining ) ;
1118- }
1119- }
1120- const activeGiveaways = await prisma . giveaway . findMany ( {
1121- where : {
1122- completed : false ,
1123- user_id : this . id
1124- }
1125- } ) ;
1126- for ( const giveaway of activeGiveaways ) {
1127- bank . add ( giveaway . loot as ItemBank ) ;
1128- }
1129- const gifts = await prisma . giftBox . findMany ( {
1130- where : {
1131- owner_id : this . id
1132- }
1133- } ) ;
1134- for ( const gift of gifts ) {
1135- bank . add ( gift . items as ItemBank ) ;
1136- }
1137- return {
1138- bank,
1139- value : marketPriceOfBank ( bank )
1140- } ;
1141- }
1142-
11431097 public hasDiary ( key : HasDiaryDiaryKey ) : boolean {
11441098 return this . user . completed_achievement_diaries . includes ( key ) ;
11451099 }
@@ -1295,23 +1249,29 @@ declare global {
12951249 var GlobalMUserClass : typeof MUserClass ;
12961250}
12971251
1298- async function srcMUserFetch ( userID : string , updates ?: Prisma . UserUpdateInput ) {
1299- const user =
1300- updates !== undefined
1301- ? await prisma . user . upsert ( {
1302- create : {
1303- id : userID
1304- } ,
1305- update : updates ,
1306- where : {
1307- id : userID
1308- }
1309- } )
1310- : await prisma . user . findUnique ( { where : { id : userID } } ) ;
1311-
1312- if ( ! user ) {
1313- return srcMUserFetch ( userID , { } ) ;
1252+ async function srcMUserFetch ( userID : string ) {
1253+ const [ user ] = await prisma . $queryRaw < User [ ] > `INSERT INTO users (id)
1254+ VALUES (${ userID } )
1255+ ON CONFLICT (id) DO UPDATE SET id = EXCLUDED.id
1256+ RETURNING *;
1257+ ` ;
1258+ for ( const [ key , val ] of Object . entries ( user ) ) {
1259+ if ( key . includes ( '.' ) || key . includes ( ' ' ) ) {
1260+ ( user as any ) [ key . replace ( / [ . \s ] / g, '_' ) ] = val ;
1261+ // @ts -expect-error
1262+ delete user [ key ] ;
1263+ }
13141264 }
1265+
1266+ // const user2 = await prisma.user.upsert({
1267+ // where: { id: userID },
1268+ // update: {},
1269+ // create: { id: userID }
1270+ // });
1271+
1272+ // console.log(deepEqual(user, user2));
1273+ // console.log(omit(user, ['bank', 'collectionLogBank', 'gear.range', 'gear.melee', 'gear.mage', 'gear.wildy']));
1274+
13151275 return new MUserClass ( user ) ;
13161276}
13171277
0 commit comments