Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gc authored Aug 6, 2024
2 parents 8c5d02c + cf085e4 commit 6b2a64b
Show file tree
Hide file tree
Showing 23 changed files with 616 additions and 744 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Run Integration Tests
run: docker-compose up --build --abort-on-container-exit
run: docker compose up --build --abort-on-container-exit --remove-orphans && docker compose down --volumes --remove-orphans
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@napi-rs/canvas": "^0.1.53",
"@oldschoolgg/toolkit": "git+https://github.com/oldschoolgg/toolkit.git#2813f25327093fcf2cb12bee7d4c85ce629069a0",
"@oldschoolgg/toolkit": "git+https://github.com/oldschoolgg/toolkit.git#cd7c6865229ca7dc4a66b3816586f2d3f4a4fbed",
"@prisma/client": "^5.17.0",
"@sapphire/ratelimits": "^2.4.9",
"@sapphire/snowflake": "^3.5.3",
Expand All @@ -48,6 +48,7 @@
"p-queue": "^6.6.2",
"piscina": "^4.6.1",
"random-js": "^2.1.0",
"remeda": "^2.7.0",
"simple-statistics": "^7.8.3",
"sonic-boom": "^4.0.1",
"zlib-sync": "^0.1.9",
Expand Down
5 changes: 3 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ model User {
store_bitfield Int[] @default([])
// Migrate
farmingPatches_herb Json? @map("farmingPatches.herb") @db.Json
farmingPatches_fruit_tree Json? @map("farmingPatches.fruit tree") @db.Json
farmingPatches_tree Json? @map("farmingPatches.tree") @db.Json
Expand Down Expand Up @@ -436,6 +435,8 @@ model User {
gift_boxes_owned GiftBox[] @relation("gift_boxes_owned")
gift_boxes_created GiftBox[] @relation("gift_boxes_created")
cl_array Int[] @default([])
@@index([id, last_command_date])
@@map("users")
}
Expand Down Expand Up @@ -744,7 +745,7 @@ model UserStats {
creature_scores Json @default("{}")
monster_scores Json @default("{}")
laps_scores Json @default("{}")
sacrificed_bank Json @default("{}")
sacrificed_bank Json @default("{}") @db.JsonB
openable_scores Json @default("{}")
gp_luckypick BigInt @default(0)
Expand Down
8 changes: 4 additions & 4 deletions src/lib/combat_achievements/combatAchievements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ const indexesWithRng = entries.flatMap(i => i[1].tasks.filter(t => 'rng' in t));
export const combatAchievementTripEffect = async ({ data, messages, user }: Parameters<TripFinishEffect['fn']>[0]) => {
const dataCopy = deepClone(data);
if (dataCopy.type === 'Inferno' && !dataCopy.diedPreZuk && !dataCopy.diedZuk) {
(dataCopy as any).quantity = 1;
(dataCopy as any).q = 1;
}
if (dataCopy.type === 'Colosseum') {
(dataCopy as any).quantity = 1;
(dataCopy as any).q = 1;
}
if (!('quantity' in dataCopy)) return;
let quantity = Number(dataCopy.quantity);
if (!('q' in dataCopy)) return;
let quantity = Number(dataCopy.q);
if (Number.isNaN(quantity)) return;

if (data.type === 'TombsOfAmascut') {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/combat_achievements/hard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ export const hardCombatAchievements: CombatAchievement[] = [
monster: 'Tempoross',
desc: 'Subdue Tempoross, getting rewarded with 10 reward permits from a single Tempoross fight.',
rng: {
chancePerKill: 30,
chancePerKill: 5,
hasChance: data => data.type === 'Tempoross'
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/combat_achievements/medium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export const mediumCombatAchievements: CombatAchievement[] = [
monster: 'Skotizo',
desc: 'Kill Skotizo with no altars active.',
rng: {
chancePerKill: 15,
chancePerKill: 5,
hasChance: isCertainMonsterTrip(Monsters.Skotizo.id)
}
},
Expand Down
8 changes: 6 additions & 2 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ export const BadgesEnum = {
TopSkiller: 9,
TopCollector: 10,
TopMinigame: 11,
SotWTrophy: 12
SotWTrophy: 12,
Slayer: 13,
TopGiveawayer: 14
} as const;

export const badges: { [key: number]: string } = {
Expand All @@ -360,7 +362,9 @@ export const badges: { [key: number]: string } = {
[BadgesEnum.TopSkiller]: Emoji.Skiller,
[BadgesEnum.TopCollector]: Emoji.CollectionLog,
[BadgesEnum.TopMinigame]: Emoji.MinigameIcon,
[BadgesEnum.SotWTrophy]: Emoji.SOTWTrophy
[BadgesEnum.SotWTrophy]: Emoji.SOTWTrophy,
[BadgesEnum.Slayer]: Emoji.Slayer,
[BadgesEnum.TopGiveawayer]: Emoji.SantaHat
};

export const MAX_XP = 200_000_000;
Expand Down
22 changes: 13 additions & 9 deletions src/lib/handleNewCLItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { allCLItems, allCollectionLogsFlat, calcCLDetails } from './data/Collect
import { calculateMastery } from './mastery';
import { calculateOwnCLRanking, roboChimpSyncData } from './roboChimp';

import { RawSQL } from './rawSql';
import { MUserStats } from './structures/MUserStats';
import { fetchCLLeaderboard } from './util/clLeaderboard';
import { insertUserEvent } from './util/userEvents';
Expand Down Expand Up @@ -49,6 +50,10 @@ export async function handleNewCLItems({
await prisma.historicalData.create({ data: await createHistoricalData(user) });
}

if (didGetNewCLItem) {
await prisma.$queryRawUnsafe(RawSQL.updateCLArray(user.id));
}

if (!didGetNewCLItem) return;

const previousCLDetails = calcCLDetails(previousCL);
Expand Down Expand Up @@ -101,15 +106,14 @@ export async function handleNewCLItems({
})}!`
: '';

const nthUser = (
await fetchCLLeaderboard({
ironmenOnly: false,
items: finishedCL.items,
resultLimit: 100_000,
method: 'raw_cl',
userEvents: null
})
).filter(u => u.qty === finishedCL.items.length).length;
const leaderboardUsers = await fetchCLLeaderboard({
ironmenOnly: false,
items: finishedCL.items,
resultLimit: 100_000,
clName: finishedCL.name
});

const nthUser = leaderboardUsers.users.filter(u => u.qty === finishedCL.items.length).length;

const placeStr = nthUser > 100 ? '' : ` They are the ${formatOrdinal(nthUser)} user to finish this CL.`;

Expand Down
5 changes: 4 additions & 1 deletion src/lib/preStartup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { noOp } from 'e';
import { syncCustomPrices } from '../mahoji/lib/events';
import { syncActivityCache } from './Task';
import { cacheBadges } from './badges';
import { syncBlacklists } from './blacklists';
import { GrandExchange } from './grandExchange';
import { cacheGEPrices } from './marketPrices';
import { populateRoboChimpCache } from './perkTier';
import { RawSQL } from './rawSql';
import { runStartupScripts } from './startupScripts';
import { logWrapFn } from './util';
import { syncActiveUserIDs } from './util/cachedUserIDs';
Expand All @@ -21,6 +23,7 @@ export const preStartup = logWrapFn('PreStartup', async () => {
cacheBadges(),
GrandExchange.init(),
populateRoboChimpCache(),
cacheGEPrices()
cacheGEPrices(),
prisma.$queryRawUnsafe(RawSQL.updateAllUsersCLArrays()).then(noOp)
]);
});
16 changes: 16 additions & 0 deletions src/lib/rawSql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Prisma } from '@prisma/client';

const u = Prisma.UserScalarFieldEnum;

export const RawSQL = {
updateAllUsersCLArrays: () => `UPDATE users
SET ${u.cl_array} = (
SELECT (ARRAY(SELECT jsonb_object_keys("${u.collectionLogBank}")::int))
)
WHERE last_command_date > now() - INTERVAL '1 week';`,
updateCLArray: (userID: string) => `UPDATE users
SET ${u.cl_array} = (
SELECT (ARRAY(SELECT jsonb_object_keys("${u.collectionLogBank}")::int))
)
WHERE ${u.id} = '${userID}';`
};
Loading

0 comments on commit 6b2a64b

Please sign in to comment.