Skip to content

Commit

Permalink
introduce ts-reset, change BOT_OWNERS to separate primary and seconda…
Browse files Browse the repository at this point in the history
…ry owners
  • Loading branch information
TiltedToast committed Mar 23, 2024
1 parent 8800ebb commit 65788c7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"zod-validation-error": "^3.0.3"
},
"devDependencies": {
"@total-typescript/ts-reset": "^0.5.1",
"@types/dedent": "^0.7.2",
"@types/gifsicle": "^5.2.2",
"@types/qrcode": "^1.5.5",
Expand Down
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "@total-typescript/ts-reset";
import dedent from "dedent";
import { Client, GatewayIntentBits, Partials, TextChannel } from "discord.js";
import { existsSync, rmSync } from "node:fs";
Expand Down
14 changes: 10 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { z } from "zod";
import { fromZodError } from "zod-validation-error";

// First one is the one that gets pinged in the event of an error
export const BOT_OWNERS = ["258993932262834188", "207505077013839883"];
export const BOT_OWNERS = {
primary: "258993932262834188",
secondary: ["207505077013839883"],
} as const;
export const OWNER_NAME = "@toast.dll";
export const BOT_NAME = "Hifumi";
export const DEFAULT_PREFIX = "h!";
export const DEV_PREFIX = "h?";
export const RELOAD_PREFIX = "hr"; // this should always be lowercase
export const EMBED_COLOUR = "#CE3A9B";
export const DEV_CHANNELS = ["655484859405303809", "551588329003548683", "922679249058553857"];
export const DEV_CHANNELS = [
"655484859405303809",
"551588329003548683",
"922679249058553857",
] as const;
export const LOG_CHANNEL = "655484804405657642";
export const CAT_FACT_CHANNEL = "655484859405303809";
export const DEV_COMMAND_POSTFIX = "-dev";
Expand All @@ -19,7 +25,7 @@ export const IMAGE_THREAD_CHANNELS = [
"1059120608593584258",
"1164282153396351097",
"1164282173403185262",
];
] as const;

// prettier-ignore
const envVariables = z.object({
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
userMention,
type Interaction,
} from "discord.js";
import { updatePrefix } from "../commands/database.ts";
import { beautiful, qrCode } from "../commands/imgProcess.ts";
import {
avatar,
convert,
Expand All @@ -15,7 +17,6 @@ import {
urbanEmbeds,
} from "../commands/miscellaneous.ts";
import { sub } from "../commands/reddit.ts";
import { beautiful, qrCode } from "../commands/imgProcess.ts";
import {
BOT_OWNERS,
DEV_CHANNELS,
Expand All @@ -24,7 +25,6 @@ import {
OWNER_NAME,
} from "../config.ts";
import { isDev, updateEmbed } from "../helpers/utils.ts";
import { updatePrefix } from "../commands/database.ts";

export default async function handleInteraction(interaction: Interaction) {
try {
Expand Down Expand Up @@ -53,7 +53,7 @@ export default async function handleInteraction(interaction: Interaction) {

if (!interaction.isChatInputCommand()) return;
await channel.send(
codeBlock("js", `${error as string}`) + `\n${userMention(BOT_OWNERS[0])}`
codeBlock("js", `${error as string}`) + `\n${userMention(BOT_OWNERS.primary)}`
);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PermissionsBitField,
TextChannel,
User,
userMention,
type BaseMessageOptions,
type Channel,
type PermissionResolvable,
Expand Down Expand Up @@ -131,7 +132,7 @@ export function insideDocker(): boolean {
}

export function isBotOwner(user: User): boolean {
return BOT_OWNERS.includes(user.id);
return user.id === BOT_OWNERS.primary || BOT_OWNERS.secondary.includes(user.id);
}

export function isAiTrigger(message: Message, reactCmd: string): boolean {
Expand Down Expand Up @@ -326,14 +327,14 @@ export function errorLog({ message, errorObject }: ErrorLogOptions) {
**${errorObject.stack ?? "Stack missing"}**
<@${BOT_OWNERS[0]}>`;
${userMention(BOT_OWNERS.primary)}`;

const preCutErrorMessage = fullErrorMsg.substring(0, 1900 - errorMessageWithoutStack.length);

const postCutErrorMessage = dedent`
${preCutErrorMessage.split("\n").slice(0, -2).join("\n")}**
<@${BOT_OWNERS[0]}>`;
${userMention(BOT_OWNERS.primary)}`;

db.insert(errorLogs)
.values({
Expand All @@ -355,7 +356,7 @@ export function errorLog({ message, errorObject }: ErrorLogOptions) {
errorMessage = dedent`
An Error occurred on ${currentTime}
Check console for full error (2000 character limit)
<@${BOT_OWNERS[0]}>`;
${userMention(BOT_OWNERS.primary)}`;
} else {
errorMessage = postCutErrorMessage;
}
Expand Down

0 comments on commit 65788c7

Please sign in to comment.