Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 71e3dc9083 | |||
| a4c70f5b09 | |||
| bd66e7aa70 | |||
| aed1ee515a | |||
| 1a3bc54bcb | |||
| 24f121f1ad | |||
| 610611e1d9 | |||
| 857ae3e01a | |||
| 8de32af061 | |||
| 86dea5b14c | |||
| 706123ff44 |
@@ -1,2 +1,4 @@
|
|||||||
node_modules/*
|
node_modules/*
|
||||||
dist/*
|
dist/*
|
||||||
|
|
||||||
|
.env
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"jsxSingleQuote": true,
|
||||||
|
"arrowParens": "always",
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"useTabs": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import js from "@eslint/js";
|
||||||
|
import globals from "globals";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
import { defineConfig } from "eslint/config";
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
{ files: ["src/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.browser } },
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
]);
|
||||||
Generated
+1750
-4
File diff suppressed because it is too large
Load Diff
+19
-4
@@ -4,8 +4,15 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npx tsc",
|
"build": "tsc",
|
||||||
"start": "node dist/index.js"
|
"start": "node dist/index.js",
|
||||||
|
"dev": "tsx watch src/index.ts",
|
||||||
|
"watch": "tsc --watch",
|
||||||
|
"clean": "rm -rf dist",
|
||||||
|
"build:clean": "npm run clean && npm run build",
|
||||||
|
"lint": "eslint",
|
||||||
|
"format": "prettier --check './src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
|
||||||
|
"format:apply": "prettier --write './src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -16,11 +23,19 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.39.2",
|
||||||
"@types/node": "^25.0.5",
|
"@types/node": "^25.0.5",
|
||||||
|
"eslint": "^9.39.2",
|
||||||
|
"globals": "^17.0.0",
|
||||||
|
"jiti": "^2.6.1",
|
||||||
"tsx": "^4.21.0",
|
"tsx": "^4.21.0",
|
||||||
"typescript": "^5.9.3"
|
"typescript": "^5.9.3",
|
||||||
|
"typescript-eslint": "^8.52.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"colorts": "^0.1.63"
|
"colorts": "^0.1.63",
|
||||||
|
"discord.js": "^14.25.1",
|
||||||
|
"dotenv": "^17.2.3",
|
||||||
|
"prettier": "^3.7.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
export interface Config {
|
||||||
|
token: string;
|
||||||
|
client_id: string;
|
||||||
|
owner_id: string | undefined;
|
||||||
|
|
||||||
|
tts_default_mode: string | undefined;
|
||||||
|
tts_default_voice: string | undefined;
|
||||||
|
|
||||||
|
tts_azure_key: string | undefined;
|
||||||
|
tts_elevenlabs_key: string | undefined;
|
||||||
|
|
||||||
|
steam_webapi_key: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadConfig(): Config {
|
||||||
|
const token = process.env.DISCORD_TOKEN;
|
||||||
|
const client_id = process.env.DISCORD_ID;
|
||||||
|
|
||||||
|
if (!token) throw new Error('DISCORD_TOKEN environment variable is not set.');
|
||||||
|
if (!client_id)
|
||||||
|
throw new Error('DISCORD_ID environment variable is not set.');
|
||||||
|
|
||||||
|
return {
|
||||||
|
token,
|
||||||
|
client_id,
|
||||||
|
owner_id: process.env.DISCORD_OWNER_ID,
|
||||||
|
tts_default_mode: process.env.DEFAULT_TTS_MODE,
|
||||||
|
tts_default_voice: process.env.DEFAULT_TTS_VOICE,
|
||||||
|
tts_azure_key: process.env.TTS_AZURE_KEY,
|
||||||
|
tts_elevenlabs_key: process.env.TTS_ELEVENLABS_KEY,
|
||||||
|
steam_webapi_key: process.env.STEAM_WEBAPI_KEY
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = loadConfig();
|
||||||
+62
-63
@@ -7,93 +7,92 @@ import 'colorts/lib/string';
|
|||||||
helper fns
|
helper fns
|
||||||
*/
|
*/
|
||||||
function getCallerFrame(shift: number = 0): NodeJS.CallSite | undefined {
|
function getCallerFrame(shift: number = 0): NodeJS.CallSite | undefined {
|
||||||
const prepareStackTrace = Error.prepareStackTrace;
|
const prepareStackTrace = Error.prepareStackTrace;
|
||||||
let loggedStack: NodeJS.CallSite[] | undefined;
|
let loggedStack: NodeJS.CallSite[] | undefined;
|
||||||
|
|
||||||
Error.prepareStackTrace = (_, stackTraces: NodeJS.CallSite[]) => {
|
Error.prepareStackTrace = (_, stackTraces: NodeJS.CallSite[]) => {
|
||||||
loggedStack = stackTraces;
|
loggedStack = stackTraces;
|
||||||
stackTraces.shift(); // discard curr frame
|
stackTraces.shift(); // discard curr frame
|
||||||
return stackTraces;
|
return stackTraces;
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||||
new Error().stack;
|
new Error().stack;
|
||||||
|
|
||||||
Error.prepareStackTrace = prepareStackTrace;
|
Error.prepareStackTrace = prepareStackTrace;
|
||||||
|
|
||||||
if (!loggedStack) return undefined;
|
if (!loggedStack) return undefined;
|
||||||
|
|
||||||
if (shift > 0)
|
if (shift > 0) for (let i = 0; i < shift; i++) loggedStack.shift();
|
||||||
for (let i = 0; i < shift; i++)
|
|
||||||
loggedStack.shift();
|
|
||||||
|
|
||||||
return loggedStack[1];
|
return loggedStack[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
logger
|
logger
|
||||||
*/
|
*/
|
||||||
const LOG_TYPES = {
|
const LOG_TYPES = {
|
||||||
Info: "[Info]".green,
|
Info: '[Info]'.green,
|
||||||
Verbose: "[Verbose]".blue,
|
Verbose: '[Verbose]'.blue,
|
||||||
Warning: "[Warning]".yellow,
|
Warning: '[Warning]'.yellow,
|
||||||
Error: "[Error]".red,
|
Error: '[Error]'.red
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export class Logger {
|
export class Logger {
|
||||||
private readonly name: string;
|
private readonly name: string;
|
||||||
|
|
||||||
constructor(name: string) {
|
constructor(name: string) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public info(fmt: string, ...args: unknown[]): void {
|
public info(fmt: string, ...args: unknown[]): void {
|
||||||
this.log(LOG_TYPES.Info, fmt, args);
|
this.log(LOG_TYPES.Info, fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public verbose(fmt: string, ...args: unknown[]): void {
|
public verbose(fmt: string, ...args: unknown[]): void {
|
||||||
this.log(LOG_TYPES.Verbose, fmt, args);
|
this.log(LOG_TYPES.Verbose, fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public warning(fmt: string, ...args: unknown[]): void {
|
public warning(fmt: string, ...args: unknown[]): void {
|
||||||
this.log(LOG_TYPES.Warning, fmt, args);
|
this.log(LOG_TYPES.Warning, fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public error(fmt: string, ...args: unknown[]): void {
|
public error(fmt: string, ...args: unknown[]): void {
|
||||||
this.log(LOG_TYPES.Error, fmt, args);
|
this.log(LOG_TYPES.Error, fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private log(type: string, message: string, args: unknown[]): void {
|
private log(type: string, message: string, args: unknown[]): void {
|
||||||
const caller = getCallerFrame(1);
|
const caller = getCallerFrame(1);
|
||||||
if (!caller) {
|
if (!caller) {
|
||||||
console.error('Failed to determine caller information');
|
console.error('Failed to determine caller information');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const timestamp = this.getFormattedTime();
|
const timestamp = this.getFormattedTime();
|
||||||
const callerInfo = this.getCallerInfo(caller);
|
const callerInfo = this.getCallerInfo(caller);
|
||||||
const formattedMessage = util.format(message, ...args);
|
const formattedMessage = util.format(message, ...args);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`${timestamp} - ${callerInfo} [${this.name.magenta}] ${type} ${formattedMessage}`
|
`${timestamp} - ${callerInfo} [${this.name.magenta}] ${type} ${formattedMessage}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFormattedTime(): string {
|
private getFormattedTime(): string {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
return now.toLocaleTimeString('en-US', {
|
return now.toLocaleTimeString('en-US', {
|
||||||
hour: '2-digit',
|
hour: '2-digit',
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
second: '2-digit',
|
second: '2-digit',
|
||||||
hour12: false
|
hour12: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCallerInfo(caller: NodeJS.CallSite): string {
|
private getCallerInfo(caller: NodeJS.CallSite): string {
|
||||||
const functionName = caller.getFunctionName()?.replace(/\[.*\]/, '') || '<anonymous>';
|
const functionName =
|
||||||
const fileName = caller.getFileName() || 'unknown';
|
caller.getFunctionName()?.replace(/\[.*\]/, '') || '<anonymous>';
|
||||||
const relativePath = path.relative(process.cwd(), fileName);
|
const fileName = caller.getFileName() || 'unknown';
|
||||||
|
const relativePath = path.relative(process.cwd(), fileName);
|
||||||
|
|
||||||
return `${functionName.cyan} @ ${relativePath.dim}`;
|
return `${functionName.cyan} @ ${relativePath.dim}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user