add initial complete webui, more ai commands for moderation, add api

This commit is contained in:
Aidan 2025-07-05 14:36:17 -04:00
parent 19e794e34c
commit 173d4e7a52
112 changed files with 8176 additions and 780 deletions

23
telegram/plugins/checklang.ts Executable file
View file

@ -0,0 +1,23 @@
const languageFiles = {
'pt': '../locales/portuguese.json',
'pt-br': '../locales/portuguese.json',
'pt-pt': '../locales/portuguese.json',
'en': '../locales/english.json',
'en-us': '../locales/english.json',
'en-gb': '../locales/english.json'
};
function getStrings(languageCode?: string) {
if (!languageCode) {
return require(languageFiles['en']);
}
const filePath: string = languageFiles[languageCode] || languageFiles['en'];
try {
return require(filePath);
} catch (error) {
console.error(`Error loading language file for code ${languageCode}:`, error);
return require(languageFiles['en']);
}
}
export { getStrings };

14
telegram/plugins/verifyInput.ts Executable file
View file

@ -0,0 +1,14 @@
import { Context } from "telegraf";
import { replyToMessageId } from "../utils/reply-to-message-id";
export default function verifyInput(ctx: Context, userInput: string, message: string, verifyNaN = false) {
const reply_to_message_id = replyToMessageId(ctx);
if (!userInput || (verifyNaN && isNaN(Number(userInput)))) {
ctx.reply(message, {
parse_mode: "Markdown",
...({ reply_to_message_id })
});
return true;
}
return false;
}

View file

@ -0,0 +1,55 @@
import axios from 'axios';
import fs from 'fs';
import path from 'path';
import os from 'os';
const downloadDir = path.resolve(__dirname, 'yt-dlp');
const urls = {
linux: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp',
win32: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe',
darwin: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos',
};
function getDownloadUrl() {
const platform = os.platform();
return urls[platform] || urls.linux;
};
async function downloadYtDlp() {
const url = getDownloadUrl();
const fileName = url.split('/').pop();
const filePath = path.join(downloadDir, fileName);
if (!fs.existsSync(downloadDir)) {
fs.mkdirSync(downloadDir, { recursive: true });
};
if (!fs.existsSync(filePath)) {
try {
const response = await axios({
url,
method: 'GET',
responseType: 'stream',
});
const writer = fs.createWriteStream(filePath);
response.data.pipe(writer);
writer.on('finish', () => {
if (os.platform() !== 'win32') {
fs.chmodSync(filePath, '-x');
}
});
writer.on('error', (err) => {
console.error('WARN: yt-dlp download failed:', err);
});
} catch (err) {
console.error('WARN: yt-dlp download failed:', err.message);
};
};
};
downloadYtDlp();