Migrate to TypeScript, minor changes and fixes (#46)

* docs: linting, require bun for ts

* rf: js -> ts

* chore: bump

* docs: add ts badge

* chore: bump types

* fix: add types for context to animal commands

* [m] hf: add bot type

* fix/types: add bot, ctx types, fix emoji on /dice cmd, add todo

* fix/types: bot admin checking fixes, other misc fixes, add types

---------

Co-authored-by: Lucas Gabriel <lucmsilva651@gmail.com>
This commit is contained in:
Aidan 2025-04-29 15:39:10 -04:00 committed by GitHub
parent 6fd5652afa
commit 07045d8e09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 550 additions and 325 deletions

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();