Compare commits

..

11 Commits

Author SHA1 Message Date
neru 71e3dc9083 fix: only lint at /src 2026-01-10 09:10:02 -03:00
neru a4c70f5b09 feat: add config 2026-01-10 09:08:56 -03:00
neru bd66e7aa70 style: run format:apply 2026-01-10 09:08:24 -03:00
neru aed1ee515a feat: populate script list 2026-01-10 09:08:14 -03:00
neru 1a3bc54bcb feat: add .prettierrc 2026-01-10 09:07:52 -03:00
neru 24f121f1ad chore: add/configure eslint 2026-01-10 09:07:15 -03:00
neru 610611e1d9 chore: update package-lock 2026-01-10 09:05:37 -03:00
neru 857ae3e01a fix: add missing dotenv dep 2026-01-10 09:05:32 -03:00
neru 8de32af061 chore: add prettier 2026-01-10 09:05:24 -03:00
neru 86dea5b14c chore: ignore .env file 2026-01-10 08:51:30 -03:00
neru 706123ff44 chore: add discord.js 2026-01-10 08:50:03 -03:00
7 changed files with 1888 additions and 73 deletions
+3 -1
View File
@@ -1,2 +1,4 @@
node_modules/* node_modules/*
dist/* dist/*
.env
+9
View File
@@ -0,0 +1,9 @@
{
"semi": true,
"singleQuote": true,
"jsxSingleQuote": true,
"arrowParens": "always",
"trailingComma": "none",
"bracketSpacing": true,
"useTabs": true
}
+9
View File
@@ -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,
]);
+1750 -4
View File
File diff suppressed because it is too large Load Diff
+20 -5
View File
@@ -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"
} }
} }
+35
View File
@@ -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
View File
@@ -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}`;
} }
} }