Moved everything to /src

This commit is contained in:
Luquinhas 2024-12-08 19:55:35 -03:00
parent dec0390280
commit 1072b641c8
29 changed files with 10 additions and 2 deletions

29
src/plugins/checklang.js Normal file
View file

@ -0,0 +1,29 @@
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',
'es': '../locales/spanish.json',
'es-es': '../locales/spanish.json',
'es-mx': '../locales/spanish.json',
'es-ar': '../locales/spanish.json',
'es-co': '../locales/spanish.json',
'es-cl': '../locales/spanish.json',
'es-pe': '../locales/spanish.json',
};
function getStrings(languageCode) {
const filePath = languageFiles[languageCode] || languageFiles['en'];
try {
return require(filePath);
} catch (error) {
console.error(`Error loading language file for code ${languageCode}:`, error);
return require(languageFiles['en']);
}
}
module.exports = {
getStrings
};

31
src/plugins/termlogger.js Normal file
View file

@ -0,0 +1,31 @@
const winston = require('winston');
const path = require('path');
const logFile = path.resolve(__dirname, '../props/bot.log');
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
winston.format.printf(({ message }) => {
return `${message}`;
})
),
transports: [
new winston.transports.Console(),
new winston.transports.File({
filename: logFile,
format: winston.format.printf(({ timestamp, message }) => {
return `[${timestamp}]\n${message}\n`;
})
})
]
});
console.log = (message) => logger.info(message);
console.error = (message) => logger.error(message);
console.warn = (message) => logger.warn(message);
console.info = (message) => logger.info(message);
module.exports = logger;

Binary file not shown.

View file

@ -0,0 +1,55 @@
const axios = require('axios');
const fs = require('fs');
const path = require('path');
const os = require('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();