Skip to content

Commit

Permalink
Remove config file (#6242)
Browse files Browse the repository at this point in the history
  • Loading branch information
gc authored Nov 28, 2024
1 parent 1c7fa43 commit 1e3182e
Show file tree
Hide file tree
Showing 28 changed files with 126 additions and 172 deletions.
3 changes: 0 additions & 3 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ This assumes you are using VSCode as your IDE. If you have errors or issues, you
- Using **pgAdmin 4** select `Servers > PostgreSQL > Databases > Create > Database...`.
- Enter the database name into `Database` and hit `Save`.
4. Change `DATABASE_URL` and `ROBOCHIMP_DATABASE_URL` in your .env file with the format `postgresql://USER:PASSWORD@HOST:PORT/DATABASE_NAME`.
5. Edit `config.ts`:
- Copy your Discord ID into both `OWNER_IDS` and `ADMIN_IDS`.
- Enter the Server ID where you want to Administer your bot from in `SupportServer`.

### Finalizing Setup

Expand Down
3 changes: 0 additions & 3 deletions packages/toolkit/src/lib/MahojiClient/Mahoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ export type ICommand = Readonly<{
}>;

interface MahojiOptions {
developmentServerID: string;
applicationID: string;
handlers?: Handlers;
djsClient: Client;
Expand All @@ -226,13 +225,11 @@ export interface Handlers {

export class MahojiClient {
commands: Map<string, ICommand> = new Map();
developmentServerID: string;
applicationID: string;
handlers: Handlers;
djsClient: Client;

constructor(options: MahojiOptions) {
this.developmentServerID = options.developmentServerID;
this.applicationID = options.applicationID;
this.handlers = options.handlers ?? {};
this.djsClient = options.djsClient;
Expand Down
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ model ClientStorage {
grand_exchange_total_tax BigInt @default(0)
grand_exchange_tax_bank BigInt @default(0)
maxing_message String @default("Congratulations on maxing!")
@@map("clientStorage")
}

Expand Down
9 changes: 0 additions & 9 deletions src/config.ts

This file was deleted.

8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { TextChannel } from 'discord.js';
import { GatewayIntentBits, Options, Partials } from 'discord.js';
import { isObject } from 'e';

import { SENTRY_DSN, SupportServer } from './config';
import { BLACKLISTED_GUILDS, BLACKLISTED_USERS } from './lib/blacklists';
import { Channel, Events, gitHash, globalConfig } from './lib/constants';
import { economyLog } from './lib/economyLogs';
Expand All @@ -29,9 +28,9 @@ import { postCommand } from './mahoji/lib/postCommand';
import { preCommand } from './mahoji/lib/preCommand';
import { convertMahojiCommandToAbstractCommand } from './mahoji/lib/util';

if (SENTRY_DSN) {
if (globalConfig.sentryDSN) {
init({
dsn: SENTRY_DSN,
dsn: globalConfig.sentryDSN,
enableTracing: false,
defaultIntegrations: false,
integrations: [],
Expand Down Expand Up @@ -67,7 +66,7 @@ const client = new OldSchoolBotClient({
},
GuildEmojiManager: {
maxSize: 1,
keepOverLimit: i => [globalConfig.testingServerID, SupportServer].includes(i.guild.id)
keepOverLimit: i => globalConfig.supportServerID === i.guild.id
},
GuildStickerManager: { maxSize: 0 },
PresenceManager: { maxSize: 0 },
Expand Down Expand Up @@ -100,7 +99,6 @@ const client = new OldSchoolBotClient({
});

export const mahojiClient = new MahojiClient({
developmentServerID: globalConfig.testingServerID,
applicationID: globalConfig.clientID,
commands: allCommands,
handlers: {
Expand Down
9 changes: 5 additions & 4 deletions src/lib/addXP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { bold } from 'discord.js';
import { Time, noOp } from 'e';
import { convertXPtoLVL, toKMB } from './util';

import { MAXING_MESSAGE, SupportServer } from '../config';
import { Events, LEVEL_99_XP, MAX_TOTAL_LEVEL, MAX_XP } from './constants';
import { Events, LEVEL_99_XP, MAX_TOTAL_LEVEL, MAX_XP, globalConfig } from './constants';
import { skillEmoji } from './data/emojis';
import type { AddXpParams } from './minions/types';
import { sql } from './postgres';
import Skills from './skilling/skills';
import { mahojiClientSettingsFetch } from './util/clientSettings';
import { insertUserEvent } from './util/userEvents';
import { sendToChannelID } from './util/webhook';

Expand Down Expand Up @@ -43,9 +43,10 @@ async function onMax(user: MUser) {
} 🎉`;

globalClient.emit(Events.ServerNotification, str);
sendToChannelID(SupportServer, { content: str }).catch(noOp);
sendToChannelID(globalConfig.supportServerID, { content: str }).catch(noOp);
const kUser = await globalClient.fetchUser(user.id);
kUser.send(MAXING_MESSAGE).catch(noOp);
const clientSettings = await mahojiClientSettingsFetch({ maxing_message: true });
kUser.send(clientSettings.maxing_message).catch(noOp);
}

export async function addXP(user: MUser, params: AddXpParams): Promise<string> {
Expand Down
95 changes: 42 additions & 53 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,50 @@ import * as dotenv from 'dotenv';
import { getItemOrThrow, resolveItems } from 'oldschooljs';
import { z } from 'zod';

import { DISCORD_SETTINGS, production } from '../config';
import type { AbstractCommand } from '../mahoji/lib/inhibitors';
import { SkillsEnum } from './skilling/types';
import type { ActivityTaskData } from './types/minions';
import type { CanvasImage } from './util/canvasUtil';

export { PerkTier };

const TestingMainChannelID = DISCORD_SETTINGS.Channels?.TestingMain ?? '940760643525570591';

export const BOT_TYPE: 'BSO' | 'OSB' = 'OSB' as 'BSO' | 'OSB';
export const BOT_TYPE_LOWERCASE: 'bso' | 'osb' = BOT_TYPE.toLowerCase() as 'bso' | 'osb';
const isProduction = process.env.NODE_ENV === 'production';
const TEST_SERVER_LOG_CHANNEL = '1042760447830536212';
const GENERAL_CHANNEL_ID =
BOT_TYPE === 'OSB'
? isProduction
? '346304390858145792'
: '1154056119019393035'
: isProduction
? '792691343284764693'
: '1154056119019393035';
const OLDSCHOOLGG_TESTING_SERVER_ID = '940758552425955348';

export const Channel = {
General: DISCORD_SETTINGS.Channels?.General ?? '342983479501389826',
Notifications:
DISCORD_SETTINGS.Channels?.Notifications ?? (production ? '469523207691436042' : '1042760447830536212'),
GrandExchange: DISCORD_SETTINGS.Channels?.GrandExchange ?? '682996313209831435',
Developers: DISCORD_SETTINGS.Channels?.Developers ?? '648196527294251020',
BlacklistLogs: DISCORD_SETTINGS.Channels?.BlacklistLogs ?? '782459317218967602',
EconomyLogs: DISCORD_SETTINGS.Channels?.EconomyLogs ?? '802029843712573510',
PatronLogs: '806744016309714966',
General: isProduction ? '342983479501389826' : GENERAL_CHANNEL_ID,
Notifications: isProduction ? '469523207691436042' : GENERAL_CHANNEL_ID,
GrandExchange: isProduction ? '682996313209831435' : GENERAL_CHANNEL_ID,
EconomyLogs: isProduction ? '802029843712573510' : TEST_SERVER_LOG_CHANNEL,
HelpAndSupport: '668073484731154462',
TestingMain: TestingMainChannelID,
BarbarianAssault: DISCORD_SETTINGS.Channels?.BarbarianAssault ?? '789717054902763520',
ChambersOfXeric: DISCORD_SETTINGS.Channels?.ChambersOfXeric ?? '835876917252587581',
BotLogs: production ? '1051725977320964197' : TestingMainChannelID,
GeneralChannel:
BOT_TYPE === 'OSB'
? production
? '346304390858145792'
: '1154056119019393035'
: production
? '792691343284764693'
: '1154056119019393035'
BotLogs: isProduction ? '1051725977320964197' : GENERAL_CHANNEL_ID,
GeneralChannel: GENERAL_CHANNEL_ID
};

export const Roles = {
Booster: DISCORD_SETTINGS.Roles?.Booster ?? '665908237152813057',
Contributor: DISCORD_SETTINGS.Roles?.Contributor ?? '456181501437018112',
Moderator: DISCORD_SETTINGS.Roles?.Moderator ?? '622806157563527178',
PatronTier1: DISCORD_SETTINGS.Roles?.PatronTier1 ?? '678970545789730826',
PatronTier2: DISCORD_SETTINGS.Roles?.PatronTier2 ?? '678967943979204608',
PatronTier3: DISCORD_SETTINGS.Roles?.PatronTier3 ?? '687408140832342043',
Patron: DISCORD_SETTINGS.Roles?.Patron ?? '679620175838183424',
Testers: DISCORD_SETTINGS.Roles?.Tester ?? '682052620809928718',
MassHoster: DISCORD_SETTINGS.Roles?.MassHoster ?? '734055552933429280',
Mass: DISCORD_SETTINGS.Roles?.Mass ?? '711215501543473182',
BarbarianAssaultMass: DISCORD_SETTINGS.Roles?.BarbarianAssaultMass ?? '789724904885846016',
ChambersOfXericMass: DISCORD_SETTINGS.Roles?.ChambersOfXericMass ?? '836539487815204865',
Booster: '665908237152813057',
Contributor: '456181501437018112',
Moderator: '622806157563527178',
Patron: '679620175838183424',
// Top Roles
TopSkiller: DISCORD_SETTINGS.Roles?.TopSkiller ?? '795266465329709076',
TopCollector: DISCORD_SETTINGS.Roles?.TopCollector ?? '795271210141351947',
TopSacrificer: DISCORD_SETTINGS.Roles?.TopSacrificer ?? '795933981715464192',
TopMinigamer: DISCORD_SETTINGS.Roles?.TopMinigamer ?? '832798997033779220',
TopClueHunter: DISCORD_SETTINGS.Roles?.TopClueHunter ?? '839135887467610123',
TopSlayer: DISCORD_SETTINGS.Roles?.TopSlayer ?? '856080958247010324',
TopFarmer: DISCORD_SETTINGS.Roles?.TopFarmer ?? '894194027363205150',
TopSkiller: '795266465329709076',
TopCollector: '795271210141351947',
TopSacrificer: '795933981715464192',
TopMinigamer: '832798997033779220',
TopClueHunter: '839135887467610123',
TopSlayer: '856080958247010324',
TopFarmer: '894194027363205150',
TopGlobalCL: '1072426869028294747'
};

Expand Down Expand Up @@ -495,14 +481,18 @@ export const ParsedCustomEmojiWithGroups = /(?<animated>a?):(?<name>[^:]+):(?<id

const globalConfigSchema = z.object({
clientID: z.string().min(10).max(25),
geAdminChannelID: z.string().default(''),
redisPort: z.coerce.number().int().optional(),
botToken: z.string().min(1),
isCI: z.coerce.boolean().default(false),
isProduction: z.coerce.boolean().default(production),
testingServerID: z.string(),
timeZone: z.literal('UTC')
isProduction: z.boolean(),
timeZone: z.literal('UTC'),
sentryDSN: z.string().url().optional(),
adminUserIDs: z.array(z.string()).default(['157797566833098752', '425134194436341760']),
maxingMessage: z.string().default('Congratulations on maxing!'),
geAdminChannelID: z.string().default(''),
supportServerID: z.string()
});

dotenv.config({ path: path.resolve(process.cwd(), process.env.TEST ? '.env.test' : '.env') });

if (!process.env.BOT_TOKEN && !process.env.CI) {
Expand All @@ -511,21 +501,20 @@ if (!process.env.BOT_TOKEN && !process.env.CI) {
);
}

const OLDSCHOOLGG_TESTING_SERVER_ID = '940758552425955348';
const isProduction = process.env.NODE_ENV === 'production';

export const globalConfig = globalConfigSchema.parse({
clientID: process.env.CLIENT_ID,
geAdminChannelID: isProduction ? '830145040495411210' : '1042760447830536212',
redisPort: process.env.REDIS_PORT,
botToken: process.env.BOT_TOKEN,
isCI: process.env.CI,
isProduction,
testingServerID: process.env.TESTING_SERVER_ID ?? OLDSCHOOLGG_TESTING_SERVER_ID,
timeZone: process.env.TZ
timeZone: process.env.TZ,
sentryDSN: process.env.SENTRY_DSN,

geAdminChannelID: isProduction ? '830145040495411210' : GENERAL_CHANNEL_ID,
supportServerID: isProduction ? '342983479501389826' : OLDSCHOOLGG_TESTING_SERVER_ID
});

if ((process.env.NODE_ENV === 'production') !== globalConfig.isProduction || production !== globalConfig.isProduction) {
if ((process.env.NODE_ENV === 'production') !== globalConfig.isProduction) {
throw new Error('The NODE_ENV and isProduction variables must match');
}

Expand Down
5 changes: 2 additions & 3 deletions src/lib/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Items } from 'oldschooljs';

import { UserError } from '@oldschoolgg/toolkit/structures';
import { command_name_enum } from '@prisma/client';
import { SupportServer, production } from '../config';
import { untrustedGuildSettingsCache } from '../mahoji/guildSettings';
import { minionStatusCommand } from '../mahoji/lib/abstracted_commands/minionStatusCommand';
import { BitField, Channel, Emoji, globalConfig } from './constants';
Expand Down Expand Up @@ -45,7 +44,7 @@ const userCache = new LRUCache<string, number>({ max: 1000 });
function rareRoles(msg: Message) {
if (!globalConfig.isProduction) return;

if (!msg.guild || msg.guild.id !== SupportServer) {
if (!msg.guild || msg.guild.id !== globalConfig.supportServerID) {
return;
}

Expand All @@ -58,7 +57,7 @@ function rareRoles(msg: Message) {
for (const [roleID, chance, name] of rareRolesSrc) {
if (roll(chance / 10)) {
if (msg.member?.roles.cache.has(roleID)) continue;
if (!production && msg.channel.isSendable()) {
if (!globalConfig.isProduction && msg.channel.isSendable()) {
return msg.channel.send(`${msg.author}, you would've gotten the **${name}** role.`);
}
msg.member?.roles.add(roleID);
Expand Down
7 changes: 3 additions & 4 deletions src/lib/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { TSRedis } from '@oldschoolgg/toolkit/structures';
import { PrismaClient } from '@prisma/client';
import { PrismaClient as RobochimpPrismaClient } from '@prisma/robochimp';

import { production } from '../config';
import { globalConfig } from './constants';
import { handleDeletedPatron, handleEditPatron } from './patreonUtils';

Expand All @@ -14,7 +13,7 @@ declare global {
}

function makePrismaClient(): PrismaClient {
if (!production && !process.env.TEST) console.log('Making prisma client...');
if (!globalConfig.isProduction && !process.env.TEST) console.log('Making prisma client...');
if (!isMainThread && !process.env.TEST) {
throw new Error('Prisma client should only be created on the main thread.');
}
Expand All @@ -26,7 +25,7 @@ function makePrismaClient(): PrismaClient {
global.prisma = global.prisma || makePrismaClient();

function makeRobochimpPrismaClient(): RobochimpPrismaClient {
if (!production && !process.env.TEST) console.log('Making robochimp client...');
if (!globalConfig.isProduction && !process.env.TEST) console.log('Making robochimp client...');
if (!isMainThread && !process.env.TEST) {
throw new Error('Robochimp client should only be created on the main thread.');
}
Expand All @@ -38,7 +37,7 @@ function makeRobochimpPrismaClient(): RobochimpPrismaClient {
global.roboChimpClient = global.roboChimpClient || makeRobochimpPrismaClient();

function makeRedisClient(): TSRedis {
if (!production && !process.env.TEST) console.log('Making Redis client...');
if (!globalConfig.isProduction && !process.env.TEST) console.log('Making Redis client...');
if (!isMainThread && !process.env.TEST) {
throw new Error('Redis client should only be created on the main thread.');
}
Expand Down
7 changes: 3 additions & 4 deletions src/lib/grandExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { LRUCache } from 'lru-cache';
import { Bank, type Item, type ItemBank } from 'oldschooljs';
import PQueue from 'p-queue';

import { ADMIN_IDS, OWNER_IDS, production } from '../config';
import { BLACKLISTED_USERS } from './blacklists';
import { BitField, ONE_TRILLION, PerkTier, globalConfig } from './constants';
import { marketPricemap } from './marketPrices';
Expand Down Expand Up @@ -233,12 +232,12 @@ class GrandExchangeSingleton {

async lockGE(reason: string) {
if (this.locked) return;
const idsToNotify = [...ADMIN_IDS, ...OWNER_IDS];
const idsToNotify = globalConfig.adminUserIDs;
await sendToChannelID(globalConfig.geAdminChannelID, {
content: `The Grand Exchange has encountered an error and has been locked. Reason: ${reason}. ${idsToNotify
.map(i => userMention(i))
.join(', ')}`,
allowedMentions: production ? { users: idsToNotify } : undefined
allowedMentions: globalConfig.isProduction ? { users: idsToNotify } : undefined
}).catch(noOp);
await mahojiClientSettingsUpdate({
grand_exchange_is_locked: true
Expand Down Expand Up @@ -976,7 +975,7 @@ Difference: ${shouldHave.difference(currentBank)}`);
}

async totalReset() {
if (production) throw new Error("You can't reset the GE in production.");
if (globalConfig.isProduction) throw new Error("You can't reset the GE in production.");
await mahojiClientSettingsUpdate({
grand_exchange_is_locked: false,
grand_exchange_tax_bank: 0,
Expand Down
5 changes: 2 additions & 3 deletions src/lib/perkTiers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SupportServer } from '../config';
import { perkTierCache } from './cache';
import { BitField, PerkTier, Roles } from './constants';
import { BitField, PerkTier, Roles, globalConfig } from './constants';
import { roboChimpCache } from './perkTier';

export const allPerkBitfields: BitField[] = [
Expand All @@ -27,7 +26,7 @@ function getUsersPerkTierRaw(user: { bitfield: BitField[]; id: string }): PerkTi
) {
elligibleTiers.push(PerkTier.Two);
} else {
const guild = globalClient.guilds.cache.get(SupportServer);
const guild = globalClient.guilds.cache.get(globalConfig.supportServerID);
const member = guild?.members.cache.get(user.id);
if (member && [Roles.Booster].some(roleID => member.roles.cache.has(roleID))) {
elligibleTiers.push(PerkTier.One);
Expand Down
5 changes: 2 additions & 3 deletions src/lib/rolesTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import PQueue from 'p-queue';
import { partition } from 'remeda';
import z from 'zod';

import { SupportServer } from '../config';
import { BadgesEnum, Roles } from '../lib/constants';
import { BadgesEnum, Roles, globalConfig } from '../lib/constants';
import { getCollectionItems } from '../lib/data/Collections';
import { Minigames } from '../lib/settings/minigames';
import { ClueTiers } from './clues/clueTiers';
Expand Down Expand Up @@ -399,7 +398,7 @@ export async function runRolesTask(dryRun: boolean): Promise<CommandResponse> {

if (!dryRun) {
const roleNames = new Map<string, string>();
const supportServerGuild = globalClient.guilds.cache.get(SupportServer)!;
const supportServerGuild = globalClient.guilds.cache.get(globalConfig.supportServerID)!;
if (!supportServerGuild) throw new Error('No support guild');

// Remove all top badges from all users (and add back later)
Expand Down
Loading

0 comments on commit 1e3182e

Please sign in to comment.