Skip to content
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
NODE_ENV=dev # Your node environment (prod, dev)

# Selfbot options
TOKEN = "" # Your Discord self-bot token
PREFIX = "$" # The prefix used to trigger your self-bot commands
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ node_modules/
dist/
.env
bun.lockb
*lock.json
videos/
tmp/
*.sock
cookies.txt
cookies.txt
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"start:node": "node dist/index.js",
"server": "bun src/server/index.ts",
"server:node": "node dist/server/index.js",
"dev": "tsx watch src/index.ts",
"dev:server": "tsx watch src/server/index.ts",
"prebuild": "rimraf dist && npm run type-check",
"build": "tsc",
"build:only": "tsc",
"type-check": "tsc --noEmit",
"watch": "tsc -w",
"gen-hash": "bun src/utils/gen-hash.ts",
"gen-hash:node": "node dist/utils/gen-hash.js"
Expand All @@ -18,8 +23,6 @@
"license": "MIT",
"dependencies": {
"@dank074/discord-video-stream": "6.0.0",
"@types/bcrypt": "^6.0.0",
"@types/bun": "^1.3.10",
"argon2": "^0.44.0",
"axios": "^1.13.6",
"bcrypt": "^6.0.0",
Expand All @@ -37,9 +40,13 @@
"winston": "^3.19.0"
},
"devDependencies": {
"@types/bcrypt": "^6.0.0",
"@types/bun": "^1.3.10",
"@types/express": "^5.0.6",
"@types/express-session": "^1.18.2",
"@types/multer": "^2.1.0",
"rimraf": "^6.1.3",
"tsx": "^4.22.3",
"typescript": "^5.9.3"
}
}
9 changes: 7 additions & 2 deletions src/commands/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ export class CommandManager {
}

private async loadCommands(): Promise<void> {
// Prefer src for Bun (TypeScript native), dist for Node.js (compiled JS)
// Prefer src for Bun (TypeScript native) or dev environment, dist for Node.js (compiled JS)
const isBun = typeof Bun !== 'undefined';
const commandsPath = path.join(process.cwd(), isBun ? 'src' : 'dist', 'commands');
const isDev = !config.isProduction;
const commandsPath = path.join(process.cwd(), (isBun || isDev) ? 'src' : 'dist', 'commands');

if (!commandsPath) {
logger.error('Could not find commands directory in either dist/ or src/');
Expand Down Expand Up @@ -87,6 +88,10 @@ export class CommandManager {
return Array.from(this.commands.values());
}

public exists(name: string): boolean {
return this.commands.has(name.toLowerCase()) || this.aliases.has(name.toLowerCase());
}

public async executeCommand(commandName: string, context: CommandContext): Promise<boolean> {
const command = this.getCommand(commandName);

Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ function parseAdminIds(value: string): string[] {
}

export default {
get isProduction() {
return process.env.NODE_ENV === 'production';
},

// Selfbot options
token: process.env.TOKEN || '',
prefix: process.env.PREFIX || '',
Expand Down
8 changes: 7 additions & 1 deletion src/events/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export async function handleMessageCreate(

const commandName = args.shift()!.toLowerCase();

if (!commandManager.exists(commandName)) {
await message.react('❌');
await message.reply(`❌ **Error**: Unknown command. Use \`${config.prefix}help\` to see available commands.`);
return;
}

const context: CommandContext = {
message,
args,
Expand All @@ -39,6 +45,6 @@ export async function handleMessageCreate(

if (!executed) {
await message.react('❌');
await message.reply(`❌ **Error**: Unknown command. Use \`${config.prefix}help\` to see available commands.`);
await message.reply(`❌ **Error**: Failed to execute command. Please check the command usage and try again.`);
}
}
2 changes: 1 addition & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import dashboardRoutes from "./routes/dashboard.js";
import uploadRoutes from "./routes/upload.js";
import previewRoutes from "./routes/preview.js";

const app = express();
const app: express.Application = express();

// Configure EJS templating engine
app.set('view engine', 'ejs');
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/auth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Router } from 'express';
import express from 'express';
import bcrypt from 'bcrypt';
import argon2 from 'argon2';
import config from '../../config.js';
import logger from '../../utils/logger.js';

const router = Router();
const router: express.Router = express.Router();

// Login route - GET
router.get("/login", (req, res) => {
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Router } from 'express';
import express from 'express';
import fs from 'fs';
import path from 'path';
import config from '../../config.js';
import logger from '../../utils/logger.js';
import { prettySize } from '../utils/helpers.js';

const router = Router();
const router: express.Router = express.Router();

// Main dashboard route
router.get("/", (req, res) => {
Expand Down
5 changes: 2 additions & 3 deletions src/server/routes/preview.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Router } from 'express';
import express from 'express';
import fs from 'fs';
import path from 'path';
import ffmpeg from 'fluent-ffmpeg';
import config from '../../config.js';
import logger from '../../utils/logger.js';
import { ffmpegScreenshot } from '../../utils/ffmpeg.js';
import { stringify } from '../utils/helpers.js';

const router = Router();
const router: express.Router = express.Router();

// Preview route
router.get("/preview/:file", (req, res) => {
Expand Down
6 changes: 3 additions & 3 deletions src/server/routes/upload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Router } from 'express';
import express from 'express';
import axios from 'axios';
import https from 'https';
import fs from 'fs';
Expand All @@ -7,7 +7,7 @@ import config from '../../config.js';
import logger from '../../utils/logger.js';
import { upload } from '../middleware/multer.js';

const router = Router();
const router: express.Router = express.Router();
const agent = new https.Agent({ rejectUnauthorized: false });

// Upload route - local file with progress support
Expand All @@ -29,7 +29,7 @@ router.post("/api/remote_upload", upload.single("link"), async (req, res) => {
try {
// First, get the file info to determine size
const headResponse = await axios.head(link, { httpsAgent: agent });
const totalSize = parseInt(headResponse.headers['content-length'], 10);
const totalSize = Number(headResponse.headers['content-length'] || 0);

// Set up progress tracking
let downloaded = 0;
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"strictNullChecks": false, /* When type checking, take into account null and undefined. */
"skipLibCheck": true, /* Skip type checking all .d.ts files. */

"types": ["bun"],

"allowJs": true,
"declaration": true
}
Expand Down