Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomizer #4822

Open
wants to merge 35 commits into
base: bso
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ model User {
bank_bg_hex String?
minion_name String? @map("minion.name")
minion_hasBought Boolean @default(false) @map("minion.hasBought")
minion_ironman Boolean @default(false) @map("minion.ironman")
minion_ironman Boolean @default(true) @map("minion.ironman")
minion_icon String? @map("minion.icon")
minion_equippedPet Int? @map("minion.equippedPet")
minion_farmingContract Json? @map("minion.farmingContract") @db.Json
Expand Down Expand Up @@ -480,6 +480,8 @@ model User {

minion_defaultCompostToUse CropUpgradeType @default(compost) @map("minion.defaultCompostToUse")

last_decode_date DateTime? @db.Timestamp(6)

@@index([id, last_command_date])
@@map("users")
}
Expand Down
18 changes: 1 addition & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import './lib/util/logger';
import * as Sentry from '@sentry/node';
import { Chart } from 'chart.js';
import ChartDataLabels from 'chartjs-plugin-datalabels';
import { GatewayIntentBits, InteractionType, Options, Partials, TextChannel } from 'discord.js';
import { GatewayIntentBits, InteractionType, Options, Partials } from 'discord.js';
import { isObject, Time } from 'e';
import { MahojiClient } from 'mahoji';
import { join } from 'path';
import { debuglog } from 'util';

import { botToken, CLIENT_ID, DEV_SERVER_ID, production, SENTRY_DSN, SupportServer } from './config';
import { BLACKLISTED_GUILDS, BLACKLISTED_USERS } from './lib/blacklists';
import { Channel, Events } from './lib/constants';
import { onMessage } from './lib/events';
import { makeServer } from './lib/http';
import { modalInteractionHook } from './lib/modals';
import { runStartupScripts } from './lib/startupScripts';
import { OldSchoolBotClient } from './lib/structures/OldSchoolBotClient';
Expand Down Expand Up @@ -144,9 +142,6 @@ client.mahojiClient = mahojiClient;
global.globalClient = client;
client.on('messageCreate', onMessage);
client.on('interactionCreate', async interaction => {
if (BLACKLISTED_USERS.has(interaction.user.id)) return;
if (interaction.guildId && BLACKLISTED_GUILDS.has(interaction.guildId)) return;

if (!client.isReady()) {
if (interaction.isChatInputCommand()) {
interaction.reply({
Expand Down Expand Up @@ -185,10 +180,6 @@ client.on('interactionCreate', async interaction => {
}
});

client.on(Events.ServerNotification, (message: string) => {
const channel = globalClient.channels.cache.get(Channel.Notifications);
if (channel) (channel as TextChannel).send(message);
});
let economyLogBuffer: string[] = [];

client.on(Events.EconomyLog, async (message: string) => {
Expand All @@ -201,18 +192,11 @@ client.on(Events.EconomyLog, async (message: string) => {
economyLogBuffer = [];
}
});
client.on('guildCreate', guild => {
if (!guild.available) return;
if (BLACKLISTED_GUILDS.has(guild.id) || BLACKLISTED_USERS.has(guild.ownerId)) {
guild.leave();
}
});

client.on('shardDisconnect', ({ wasClean, code, reason }) => debugLog('Shard Disconnect', { wasClean, code, reason }));
client.on('shardError', err => debugLog('Shard Error', { error: err.message }));

async function main() {
client.fastifyServer = makeServer();
await Promise.all([
runTimedLoggedFn('Sync Active User IDs', syncActiveUserIDs),
runTimedLoggedFn('Sync Activity Cache', syncActivityCache)
Expand Down
2 changes: 0 additions & 2 deletions src/lib/DynamicButtons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { noOp, Time } from 'e';
import murmurhash from 'murmurhash';

import { BLACKLISTED_USERS } from './blacklists';
import { awaitMessageComponentInteraction, makeComponents } from './util';
import { minionIsBusy } from './util/minionIsBusy';

Expand Down Expand Up @@ -87,7 +86,6 @@ export class DynamicButtons {
const collectedInteraction = await awaitMessageComponentInteraction({
message: this.message,
filter: i => {
if (BLACKLISTED_USERS.has(i.user.id)) return false;
if (this.usersWhoCanInteract.includes(i.user.id)) {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/MUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ export function getUsersPerkTier(
userOrBitfield: MUser | User | BitField[],
noCheckOtherAccounts?: boolean
): PerkTier | 0 {
if (1 > 0) return PerkTier.Four;
if (userOrBitfield instanceof MUserClass && userOrBitfield.user.premium_balance_tier !== null) {
const date = userOrBitfield.user.premium_balance_expiry_date;
if (date && Date.now() < date) {
Expand Down
20 changes: 18 additions & 2 deletions src/lib/addXP.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { increaseNumByPercent, noOp, notEmpty, objectValues, Time } from 'e';
import { increaseNumByPercent, noOp, notEmpty, objectValues, randArrItem, Time } from 'e';
import { Item } from 'oldschooljs/dist/meta/types';
import { convertLVLtoXP, convertXPtoLVL, toKMB } from 'oldschooljs/dist/util/util';

Expand All @@ -12,7 +12,7 @@ import { prisma } from './settings/prisma';
import Skillcapes from './skilling/skillcapes';
import Skills from './skilling/skills';
import { SkillsEnum } from './skilling/types';
import { itemNameFromID } from './util';
import { assert, itemNameFromID, murMurSort } from './util';
import { formatOrdinal } from './util/formatOrdinal';
import getOSItem from './util/getOSItem';
import resolveItems from './util/resolveItems';
Expand Down Expand Up @@ -112,13 +112,29 @@ function getEquippedCapes(user: MUser) {
.map(i => i.item);
}

const allSkills = Object.values(SkillsEnum);

function getMurSkill(userID: string, inputSkill: SkillsEnum) {
const index = allSkills.indexOf(inputSkill);
const sorted = murMurSort(allSkills, `${userID}-v1`);
return sorted[index];
}

let skillsTest = new Set();
for (const skill of allSkills) {
skillsTest.add(getMurSkill('asdf', skill));
}
assert(skillsTest.size === allSkills.length);

export async function addXP(user: MUser, params: AddXpParams): Promise<string> {
params.skillName = getMurSkill(user.id, params.skillName);
const currentXP = Number(user.user[`skills_${params.skillName}`]);
const currentLevel = user.skillLevel(params.skillName);
const currentTotalLevel = user.totalLevel;
const multiplier = params.multiplier !== false;
if (multiplier) {
params.amount *= GLOBAL_BSO_XP_MULTIPLIER;
params.amount *= randArrItem([10, 5, 10, 5, 20, 1, 5, 10, 20, 20, 50]);
}

// Look for Mastery skill cape:
Expand Down
3 changes: 2 additions & 1 deletion src/lib/baxtorianBathhouses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { table } from 'table';

import { MysteryBoxes } from './bsoOpenables';
import { Emoji, GLOBAL_BSO_XP_MULTIPLIER } from './constants';
import { randomizeBank } from './randomizer';
import { incrementMinigameScore } from './settings/minigames';
import Grimy from './skilling/skills/herblore/mixables/grimy';
import { SkillsEnum } from './skilling/types';
Expand Down Expand Up @@ -413,7 +414,7 @@ function calculateResult(data: BathhouseTaskOptions) {
}

return {
loot,
loot: randomizeBank(data.userID, loot),
herbXP,
firemakingXP,
ore,
Expand Down
20 changes: 0 additions & 20 deletions src/lib/blacklists.ts

This file was deleted.

34 changes: 1 addition & 33 deletions src/lib/bsoOpenables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { randArrItem, roll } from 'e';
import { Bank, Items, LootTable } from 'oldschooljs';
import TreeHerbSeedTable from 'oldschooljs/dist/simulation/subtables/TreeHerbSeedTable';

import { Emoji } from './constants';
import {
allPetIDs,
chambersOfXericCL,
Expand Down Expand Up @@ -31,9 +30,7 @@ export const MysteryBoxes = new LootTable()
.oneIn(55, 'Pet Mystery Box')
.oneIn(165, 'Holiday Mystery Box')
.oneIn(35, 'Equippable mystery box')
.oneIn(35, 'Clothing Mystery Box')
.add('Tradeable Mystery Box')
.add('Untradeable Mystery Box');
.oneIn(35, 'Clothing Mystery Box');

export const magicCreateCrate = new LootTable()
.add('Pure essence', [500, 1000], 4)
Expand Down Expand Up @@ -166,15 +163,13 @@ export const NestBoxes = new LootTable()
.add('Nest box (empty)', 1, 3);

const baseTGBTable = new LootTable()
.add('Tradeable mystery box', [1, 3])
.add('Reward casket (master)', [3, 6])
.add('Reward casket (beginner)', [3, 9])
.add('Reward casket (hard)', [3, 7])
.add('Dwarven crate', 2)
.add(NestBoxes, 100)
.add('Holiday Mystery box')
.add('Pet Mystery box')
.add('Untradeable Mystery box')
.add('Abyssal dragon bones', [100, 500], 2)
.add('Coins', [20_000_000, 100_000_000], 2)
.add(LampTable, [1, 3])
Expand All @@ -201,7 +196,6 @@ const testerGiftTable = new LootTable()
.every('Clue scroll (grandmaster)', [1, 3])
.every(LampTable, [1, 2])
.add('Rocktail', [30, 60])
.add('Tradeable mystery box', [1, 3])
.add(baseTGBTable);

export const IronmanPMBTable = new LootTable()
Expand Down Expand Up @@ -577,32 +571,6 @@ const ChristmasBoxTable = new LootTable()
.add('Coal', 1, 2);

export const bsoOpenables: UnifiedOpenable[] = [
{
name: 'Tradeables Mystery box',
id: 6199,
openedItem: getOSItem(6199),
aliases: ['mystery', 'mystery box', 'tradeables mystery box', 'tmb'],

output: async ({ user, quantity, totalLeaguesPoints }) => ({
bank: getMysteryBoxItem(user, totalLeaguesPoints, true, quantity)
}),
emoji: Emoji.MysteryBox,
allItems: [],
isMysteryBox: true,
smokeyApplies: true
},
{
name: 'Untradeables Mystery box',
id: 19_939,
openedItem: getOSItem(19_939),
aliases: ['untradeables mystery box', 'umb'],
output: async ({ user, quantity, totalLeaguesPoints }) => ({
bank: getMysteryBoxItem(user, totalLeaguesPoints, false, quantity)
}),
allItems: [],
isMysteryBox: true,
smokeyApplies: true
},
{
name: 'Equippable mystery box',
id: itemID('Equippable mystery box'),
Expand Down
33 changes: 16 additions & 17 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ export const BotID = DISCORD_SETTINGS.BotID ?? '729244028989603850';
const TestingMainChannelID = DISCORD_SETTINGS.Channels?.TestingMain ?? '944924763405574174';

export const Channel = {
General: DISCORD_SETTINGS.Channels?.General ?? '342983479501389826',
Notifications: production ? '811589869314899980' : '1042760447830536212',
ErrorLogs: DISCORD_SETTINGS.Channels?.ErrorLogs ?? '665678499578904596',
GrandExchange: DISCORD_SETTINGS.Channels?.GrandExchange ?? '738780181946171493',
// General: DISCORD_SETTINGS.Channels?.General ?? '342983479501389826',
// Notifications: production ? '811589869314899980' : '1042760447830536212',
// GrandExchange: DISCORD_SETTINGS.Channels?.GrandExchange ?? '738780181946171493',
Developers: DISCORD_SETTINGS.Channels?.Developers ?? '648196527294251020',
BlacklistLogs: DISCORD_SETTINGS.Channels?.BlacklistLogs ?? '782459317218967602',
EconomyLogs: DISCORD_SETTINGS.Channels?.EconomyLogs ?? '802029843712573510',
Expand All @@ -38,8 +37,8 @@ export const Channel = {
// BSO Channels
BSOGeneral: DISCORD_SETTINGS.Channels?.BSOGeneral ?? '792691343284764693',
BSOChannel: DISCORD_SETTINGS.Channels?.BSOChannel ?? '732207379818479756',
BSOGambling: DISCORD_SETTINGS.Channels?.BSOChannel ?? '792692390778896424',
BSOGrandExchange: DISCORD_SETTINGS.Channels?.BSOChannel ?? '738780181946171493'
BSOGambling: DISCORD_SETTINGS.Channels?.BSOChannel ?? '792692390778896424'
// BSOGrandExchange: DISCORD_SETTINGS.Channels?.BSOChannel ?? '738780181946171493'
};

export const Roles = {
Expand All @@ -49,17 +48,17 @@ export const Roles = {
PatronTier1: DISCORD_SETTINGS.Roles?.PatronTier1 ?? '678970545789730826',
PatronTier2: DISCORD_SETTINGS.Roles?.PatronTier2 ?? '678967943979204608',
PatronTier3: DISCORD_SETTINGS.Roles?.PatronTier3 ?? '687408140832342043',
Patron: DISCORD_SETTINGS.Roles?.Patron ?? '679620175838183424',
MassHoster: DISCORD_SETTINGS.Roles?.MassHoster ?? '734055552933429280',
BSOMassHoster: DISCORD_SETTINGS.Roles?.BSOMassHoster ?? '759572886364225558',
TopSkiller: DISCORD_SETTINGS.Roles?.TopSkiller ?? '848966830617788427',
TopCollector: DISCORD_SETTINGS.Roles?.TopCollector ?? '848966773885763586',
TopSacrificer: DISCORD_SETTINGS.Roles?.TopSacrificer ?? '848966732265160775',
TopMinigamer: DISCORD_SETTINGS.Roles?.TopMinigamer ?? '867967884515770419',
TopClueHunter: DISCORD_SETTINGS.Roles?.TopClueHunter ?? '848967350120218636',
TopSlayer: DISCORD_SETTINGS.Roles?.TopSlayer ?? '867967551819358219',
TopInventor: '992799099801833582',
TopLeagues: '1005417171112972349'
Patron: DISCORD_SETTINGS.Roles?.Patron ?? '679620175838183424'
// MassHoster: DISCORD_SETTINGS.Roles?.MassHoster ?? '734055552933429280',
// BSOMassHoster: DISCORD_SETTINGS.Roles?.BSOMassHoster ?? '759572886364225558',
// TopSkiller: DISCORD_SETTINGS.Roles?.TopSkiller ?? '848966830617788427',
// TopCollector: DISCORD_SETTINGS.Roles?.TopCollector ?? '848966773885763586',
// TopSacrificer: DISCORD_SETTINGS.Roles?.TopSacrificer ?? '848966732265160775',
// TopMinigamer: DISCORD_SETTINGS.Roles?.TopMinigamer ?? '867967884515770419',
// TopClueHunter: DISCORD_SETTINGS.Roles?.TopClueHunter ?? '848967350120218636',
// TopSlayer: DISCORD_SETTINGS.Roles?.TopSlayer ?? '867967551819358219',
// TopInventor: '992799099801833582',
// TopLeagues: '1005417171112972349'
};

export const enum DefaultPingableRoles {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/customItems/customItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { EquipmentSlot } from 'oldschooljs/dist/meta/types';
import getOSItem from '../util/getOSItem';
import { setCustomItem, UN_EQUIPPABLE } from './util';

setCustomItem(19_939, 'Untradeable Mystery Box', 'Mystery box', {}, 100_000);
setCustomItem(6199, 'Tradeable Mystery Box', 'Mystery box', {}, 100_000);
// setCustomItem(19_939, 'Untradeable Mystery Box', 'Mystery box', {}, 100_000);
// setCustomItem(6199, 'Tradeable Mystery Box', 'Mystery box', {}, 100_000);
setCustomItem(3062, 'Pet Mystery Box', 'Mystery box', {}, 100_000);
setCustomItem(3713, 'Holiday Mystery Box', 'Mystery box', {}, 100_000);
setCustomItem(13_345, 'Tester Gift Box', 'Mystery box', {}, 100_000);
Expand Down
2 changes: 0 additions & 2 deletions src/lib/data/CollectionsExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2013,8 +2013,6 @@ export const dailyCL = resolveItems([
'Druidic wreath',
'Disk of returning',
'Stale baguette',
'Tradeable mystery box',
'Untradeable mystery box',
'Equippable mystery box',
'Holiday mystery box',
'Pet mystery box'
Expand Down
15 changes: 3 additions & 12 deletions src/lib/doubleLoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { mahojiClientSettingsFetch, mahojiClientSettingsUpdate } from './util/cl

export let DOUBLE_LOOT_FINISH_TIME_CACHE = 0;

export function isDoubleLootActive(duration: number = 0) {
return Date.now() - duration < DOUBLE_LOOT_FINISH_TIME_CACHE;
export function isDoubleLootActive(_duration: number = 0) {
return true;
}

export async function addToDoubleLootTimer(amount: number, reason: string) {
Expand Down Expand Up @@ -56,13 +56,4 @@ export async function syncDoubleLoot() {
DOUBLE_LOOT_FINISH_TIME_CACHE = Number(clientSettings.double_loot_finish_time);
}

export async function syncPrescence() {
await syncDoubleLoot();

let str = isDoubleLootActive()
? `${formatDuration(DOUBLE_LOOT_FINISH_TIME_CACHE - Date.now(), true)} Double Loot!`
: '/help';
if (globalClient.user!.presence.activities[0]?.name !== str) {
globalClient.user?.setActivity(str);
}
}
export async function syncPrescence() {}
Loading