Skip to content

Commit

Permalink
Merge branch 'master' into crystal-saw
Browse files Browse the repository at this point in the history
  • Loading branch information
TastyPumPum authored Aug 20, 2024
2 parents 7f61775 + 84d04b0 commit d753842
Show file tree
Hide file tree
Showing 106 changed files with 1,269 additions and 1,114 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
2 changes: 1 addition & 1 deletion SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This assumes you are using VSCode as your IDE. If you have errors or issues, you
2. Install [Postgres 16](https://www.postgresql.org/download/) and PGAdmin4 for interacting with postgres (optional, but helpful)
3. Install Yarn using: `npm i -g yarn`
4. Clone the repo: `git clone https://github.com/oldschoolgg/oldschoolbot.git`
5. Run `corepack enable` and `yarn` in the root of the repo.
5. Run the following commands in the root of the repo: `corepack enable`, `yarn`, `npx prisma db push` and `npx prisma db push --schema ./prisma/robochimp.prisma`

### Configuration

Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"watch": "nodemon -e ts -w src --exec 'yarn buildandrun'",
"watch": "nodemon --delay 1ms -e ts -w src --exec 'yarn buildandrun'",
"build": "tsx ./src/scripts/build.ts",
"fix": "tsx ./src/scripts/troubleshooter.ts",
"start": "yarn build && node --enable-source-maps dist/",
Expand All @@ -14,7 +14,7 @@
"test": "concurrently --raw --kill-others-on-fail \"tsc -p src && yarn test:circular\" \"yarn test:lint\" \"yarn test:unit\" \"tsc -p tests/integration --noEmit\" \"tsc -p tests/unit --noEmit\"",
"test:lint": "biome check --diagnostic-level=error",
"test:unit": "vitest run --coverage --config vitest.unit.config.mts",
"test:docker": "docker-compose up --build --abort-on-container-exit --remove-orphans && docker-compose down --volumes --remove-orphans",
"test:docker": "docker compose up --build --abort-on-container-exit --remove-orphans && docker compose down --volumes --remove-orphans",
"test:watch": "vitest --config vitest.unit.config.mts --coverage",
"buildandrun": "yarn build:esbuild && node --enable-source-maps dist",
"build:esbuild": "concurrently --raw \"yarn build:main\" \"yarn build:workers\"",
Expand All @@ -25,17 +25,19 @@
},
"dependencies": {
"@napi-rs/canvas": "^0.1.53",
"@oldschoolgg/toolkit": "git+https://github.com/oldschoolgg/toolkit.git#3550582efbdf04929f0a2c5114ed069a61551807",
"@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",
"@sapphire/time-utilities": "^1.6.0",
"@sapphire/timer-manager": "^1.0.2",
"@sentry/node": "^8.15.0",
"ascii-table3": "^0.9.0",
"bufferutil": "^4.0.8",
"discord.js": "^14.15.3",
"dotenv": "^16.4.5",
"e": "0.2.33",
"exit-hook": "^4.0.0",
"fast-deep-equal": "^3.1.3",
"lodash": "^4.17.21",
"lru-cache": "^10.3.0",
Expand All @@ -46,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
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { onMessage } from './lib/events';
import { modalInteractionHook } from './lib/modals';
import { preStartup } from './lib/preStartup';
import { OldSchoolBotClient } from './lib/structures/OldSchoolBotClient';
import { runTimedLoggedFn } from './lib/util';
import { CACHED_ACTIVE_USER_IDS } from './lib/util/cachedUserIDs';
import { interactionHook } from './lib/util/globalInteractions';
import { handleInteractionError, interactionReply } from './lib/util/interactionReply';
import { logError } from './lib/util/logError';
import { allCommands } from './mahoji/commands/allCommands';
import { onStartup } from './mahoji/lib/events';
import { exitCleanup } from './mahoji/lib/exitHandler';
import { postCommand } from './mahoji/lib/postCommand';
import { preCommand } from './mahoji/lib/preCommand';
import { convertMahojiCommandToAbstractCommand } from './mahoji/lib/util';
Expand Down Expand Up @@ -194,9 +194,16 @@ client.on('shardError', err => debugLog('Shard Error', { error: err.message }));
client.once('ready', () => onStartup());

async function main() {
await Promise.all([
preStartup(),
import('exit-hook').then(({ asyncExitHook }) =>
asyncExitHook(exitCleanup, {
wait: 2000
})
)
]);
if (process.env.TEST) return;
await preStartup();
await runTimedLoggedFn('Log In', () => client.login(globalConfig.botToken));
await client.login(globalConfig.botToken);
console.log(`Logged in as ${globalClient.user.username}`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/MUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class MUserClass {
this.bitfield = this.user.bitfield as readonly BitField[];
}

countSkillsAtleast99() {
countSkillsAtLeast99() {
return Object.values(this.skillsAsLevels).filter(lvl => lvl >= 99).length;
}

Expand Down
5 changes: 2 additions & 3 deletions src/lib/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ import { modifyBusyCounter } from './busyCounterCache';
import { minionActivityCache } from './constants';
import { convertStoredActivityToFlatActivity } from './settings/prisma';
import { activitySync, minionActivityCacheDelete } from './settings/settings';
import { logWrapFn } from './util';
import { logError } from './util/logError';

const tasks: MinionTask[] = [
Expand Down Expand Up @@ -219,13 +218,13 @@ export async function processPendingActivities() {
}
}

export const syncActivityCache = logWrapFn('syncActivityCache', async () => {
export const syncActivityCache = async () => {
const tasks = await prisma.activity.findMany({ where: { completed: false } });
minionActivityCache.clear();
for (const task of tasks) {
activitySync(task);
}
});
};

const ActivityTaskOptionsSchema = z.object({
userID: z.string(),
Expand Down
9 changes: 6 additions & 3 deletions src/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function analyticsTick() {
).map((result: any) => Number.parseInt(result[0].count)) as number[];

const taskCounts = await calculateMinionTaskCounts();
const currentClientSettings = await await prisma.clientStorage.findFirst({
const currentClientSettings = await prisma.clientStorage.upsert({
where: {
id: globalConfig.clientID
},
Expand All @@ -64,9 +64,12 @@ export async function analyticsTick() {
gp_slots: true,
gp_tax_balance: true,
economyStats_dailiesAmount: true
}
},
create: {
id: globalConfig.clientID
},
update: {}
});
if (!currentClientSettings) throw new Error('No client settings found');
await prisma.analytic.create({
data: {
guildsCount: globalClient.guilds.cache.size,
Expand Down
6 changes: 2 additions & 4 deletions src/lib/blacklists.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Time } from 'e';

import { production } from '../config';
import { TimerManager } from '@sapphire/timer-manager';

export const BLACKLISTED_USERS = new Set<string>();
export const BLACKLISTED_GUILDS = new Set<string>();
Expand All @@ -15,6 +15,4 @@ export async function syncBlacklists() {
}
}

if (production) {
setInterval(syncBlacklists, Time.Minute * 10);
}
TimerManager.setInterval(syncBlacklists, Time.Minute * 10);
39 changes: 32 additions & 7 deletions src/lib/colosseum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ interface ColosseumResult {
realDuration: number;
totalDeathChance: number;
deathChances: number[];
scytheCharges: number;
venatorBowCharges: number;
bloodFuryCharges: number;
}

export const startColosseumRun = (options: {
Expand All @@ -377,6 +380,9 @@ export const startColosseumRun = (options: {
hasClaws: boolean;
hasSGS: boolean;
hasTorture: boolean;
scytheCharges: number;
venatorBowCharges: number;
bloodFuryCharges: number;
}): ColosseumResult => {
const waveTwelveKC = options.kcBank.amount(12);

Expand Down Expand Up @@ -406,6 +412,10 @@ export const startColosseumRun = (options: {
let realDuration = 0;
let maxGlory = 0;

// Calculate charges used
const scytheCharges = 300;
const calculateVenCharges = () => 50;

for (const wave of colosseumWaves) {
realDuration += waveDuration;
const kcForThisWave = options.kcBank.amount(wave.waveNumber);
Expand All @@ -422,7 +432,10 @@ export const startColosseumRun = (options: {
fakeDuration,
realDuration,
totalDeathChance: combinedChance(deathChances),
deathChances
deathChances,
scytheCharges: options.hasScythe ? scytheCharges : 0,
venatorBowCharges: options.hasVenBow ? calculateVenCharges() : 0,
bloodFuryCharges: options.hasBF ? scytheCharges * 3 : 0
};
}
addedWaveKCBank.add(wave.waveNumber);
Expand All @@ -436,7 +449,11 @@ export const startColosseumRun = (options: {
fakeDuration,
realDuration,
totalDeathChance: combinedChance(deathChances),
deathChances
deathChances,

scytheCharges: options.hasScythe ? scytheCharges : 0,
venatorBowCharges: options.hasVenBow ? calculateVenCharges() : 0,
bloodFuryCharges: options.hasBF ? scytheCharges * 3 : 0
};
}
}
Expand Down Expand Up @@ -532,6 +549,9 @@ export async function colosseumCommand(user: MUser, channelID: string) {
const hasClaws = user.hasEquippedOrInBank('Dragon claws');
const hasSGS = user.hasEquippedOrInBank('Saradomin godsword');
const hasTorture = !hasBF && user.gear.melee.hasEquipped('Amulet of torture');
const scytheCharges = 300;
const bloodFuryCharges = scytheCharges * 3;
const venatorBowCharges = calculateVenCharges();

const res = startColosseumRun({
kcBank: new ColosseumWaveBank((await user.fetchStats({ colo_kc_bank: true })).colo_kc_bank as ItemBank),
Expand All @@ -541,7 +561,10 @@ export async function colosseumCommand(user: MUser, channelID: string) {
hasBF,
hasClaws,
hasSGS,
hasTorture
hasTorture,
scytheCharges,
venatorBowCharges,
bloodFuryCharges
});
const minutes = res.realDuration / Time.Minute;

Expand All @@ -556,7 +579,6 @@ export async function colosseumCommand(user: MUser, channelID: string) {
return 'You need to have a Ranging potion(4) or Bastion potion(4) in your bank.';
}

const scytheCharges = 300;
if (hasScythe) {
messages.push('10% boost for Scythe');
chargeBank.add('scythe_of_vitur_charges', scytheCharges);
Expand All @@ -578,7 +600,7 @@ export async function colosseumCommand(user: MUser, channelID: string) {
cost.add('Dragon arrow', 50);
} else {
messages.push(
'Missed 7% Venator bow boost. If you have one, charge it and keep it in your bank. You also need atleast 50 dragon arrows equipped.'
'Missed 7% Venator bow boost. If you have one, charge it and keep it in your bank. You also need at least 50 dragon arrows equipped.'
);
}

Expand All @@ -595,7 +617,7 @@ export async function colosseumCommand(user: MUser, channelID: string) {
}

if (user.gear.melee.hasEquipped('Amulet of blood fury')) {
chargeBank.add('blood_fury_charges', scytheCharges * 3);
chargeBank.add('blood_fury_charges', bloodFuryCharges);
messages.push('-5% death chance for blood fury');
} else {
messages.push('Missed -5% death chance for blood fury. If you have one, add charges and equip it to melee.');
Expand Down Expand Up @@ -652,7 +674,10 @@ export async function colosseumCommand(user: MUser, channelID: string) {
fakeDuration: res.fakeDuration,
maxGlory: res.maxGlory,
diedAt: res.diedAt ?? undefined,
loot: res.loot?.bank
loot: res.loot?.bank,
scytheCharges: res.scytheCharges,
venatorBowCharges: res.venatorBowCharges,
bloodFuryCharges: res.bloodFuryCharges
});

return `${user.minionName} is now attempting the Colosseum. They will finish in around ${formatDuration(
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
Loading

0 comments on commit d753842

Please sign in to comment.