void / commands /Menu.js
github-actions[bot]
Automated sync from GitHub
ca52557
Raw History Blame Contribute Delete
16 kB
import os from 'os';
import moment from 'moment-timezone';
import axios from 'axios';
import CONFIG from '../config.js';
import { t, translate, translateAIResponse, getUserLang } from '../france/translator.js';
const startTime = Date.now();
const styles = {
10: {
"0": "0", "1": "1", "2": "2", "3": "3", "4": "4", "5": "5", "6": "6", "7": "7", "8": "8", "9": "9",
"a": "แด€", "b": "ส™", "c": "แด„", "d": "แด…", "e": "แด‡", "f": "า“", "g": "ษข", "h": "สœ", "i": "ษช", "j": "แดŠ",
"k": "แด‹", "l": "สŸ", "m": "แด", "n": "ษด", "o": "แด", "p": "แด˜", "q": "ฯ™", "r": "ส€", "s": "s", "t": "แด›",
"u": "แดœ", "v": "v", "w": "แดก", "x": "x", "y": "ส", "z": "แดข", "A": "แด€", "B": "ส™", "C": "แด„", "D": "แด…",
"E": "แด‡", "F": "า“", "G": "ษข", "H": "สœ", "I": "ษช", "J": "แดŠ", "K": "แด‹", "L": "สŸ", "M": "แด", "N": "ษด",
"O": "แด", "P": "แด˜", "Q": "ฯ™", "R": "ส€", "S": "s", "T": "แด›", "U": "แดœ", "V": "v", "W": "แดก", "X": "x",
"Y": "ส", "Z": "แดข"
}
};
const applyStyle = (text, styleNum) => {
const map = styles[styleNum];
return text.split('').map(c => map[c] || c).join('');
};
const formatUptime = ms => {
const sec = Math.floor(ms / 1000) % 60;
const min = Math.floor(ms / (1000 * 60)) % 60;
const hr = Math.floor(ms / (1000 * 60 * 60)) % 24;
const day = Math.floor(ms / (1000 * 60 * 60 * 24));
const parts = [];
if (day === 1) parts.push(`1 day`);
else if (day > 1) parts.push(`${day} days`);
if (hr === 1) parts.push(`1 hour`);
else if (hr > 1) parts.push(`${hr} h`);
if (min === 1) parts.push(`1 minute`);
else if (min > 1) parts.push(`${min} m`);
if (sec === 1) parts.push(`1 second`);
else if (sec > 1 || parts.length === 0) parts.push(`${sec} s`);
return parts.join(', ');
};
const detectPlatform = () => {
const hostEnv = process.env.HOST_PROVIDER?.toLowerCase();
const providers = {
'optiklink': 'Optiklink.com',
'bot-hosting': 'Bot-Hosting.net',
'heroku': 'Heroku',
'railway': 'Railway',
'koyeb': 'Koyeb',
'render': 'Render',
'github': 'GitHub Actions',
'katabump': 'Katabump.com'
};
if (hostEnv && providers[hostEnv]) return providers[hostEnv];
if (process.env.RAILWAY_STATIC_URL || process.env.RAILWAY_ENVIRONMENT) return 'Railway';
if (process.env.KOYEB_ENV) return 'Koyeb';
if (process.env.RENDER) return 'Render';
if (process.env.GITHUB_WORKFLOW || process.env.GITHUB_ACTIONS) return 'GitHub Actions';
if (process.env.DYNO) return 'Heroku';
return 'PANEL';
};
const fetchRepoStats = async () => {
try {
const response = await axios.get('https://api.github.com/repos/franceking1/Flash-Md-V3');
const { forks_count, stargazers_count } = response.data;
return {
forks: forks_count || 0,
stars: stargazers_count || 0
};
} catch {
return {
forks: 0,
stars: 0
};
}
};
const more = String.fromCharCode(8206);
const readmore = more.repeat(4001);
export const commands = [
{
name: 'menu',
aliases: ['list'],
description: 'Show all available bot commands.',
category: 'General',
execute: async ({ sock, from, msg, commands, auteurMessage, nomAuteurMessage }) => {
try {
const botName = 'FLASH-MD-V3';
const botVersion = CONFIG.BOT_VERSION || '3.0.0';
const ownerName = CONFIG.OWNER_NAME || 'FRANCE KING';
const tz = CONFIG.TZ || 'Africa/Nairobi';
const prefix = CONFIG.PREFIXES?.[0] || ' ';
const mode = CONFIG.MODE === 'public' ? 'Public' : 'Private';
const menuImages = CONFIG.MENU_IMAGES || [];
const list = Array.from(commands.values());
if (!list.length) {
return sock.sendMessage(from, {
text: 'โŒ Command list not available.'
}, { quoted: msg });
}
const time = moment().tz(tz);
const hour = time.hour();
let greeting = "Good Night";
if (hour >= 0 && hour <= 11) {
greeting = "Good Morning";
} else if (hour >= 12 && hour <= 16) {
greeting = "Good Afternoon";
} else if (hour >= 16 && hour <= 21) {
greeting = "Good Evening";
}
const userName = nomAuteurMessage || auteurMessage || ownerName;
const uptime = formatUptime(Date.now() - startTime);
const platform = detectPlatform();
const usedMem = (
(os.totalmem() - os.freemem()) /
1024 /
1024 /
1024
).toFixed(2);
const totalMem = (
os.totalmem() /
1024 /
1024 /
1024
).toFixed(2);
const { forks, stars } = await fetchRepoStats();
const users = (stars * 3) + (forks * 2);
const usersFormatted = users.toLocaleString();
const grouped = {};
for (const cmd of list) {
const category = cmd.category || 'General';
if (!grouped[category]) {
grouped[category] = [];
}
grouped[category].push(cmd);
}
let menuText = `*${greeting} ${userName}*\n\n`;
menuText += `โ•ญโ”โ”โ”โ’ ${applyStyle(`${botName} ${botVersion}`, 10)} โ’โ”โ”โ”โ•ฎ\n`;
menuText += `โ”ƒโƒโ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n`;
menuText += `โ”ƒโƒโ”‚ *Owner:* ${ownerName}\n`;
menuText += `โ”ƒโƒโ”‚ *Prefix:* ${prefix}\n`;
menuText += `โ”ƒโƒโ”‚ *Commands:* ${list.length}\n`;
menuText += `โ”ƒโƒโ”‚ *Time:* ${time.format('HH:mm:ss')}\n`;
menuText += `โ”ƒโƒโ”‚ *Date:* ${time.format('DD/MM/YYYY')}\n`;
menuText += `โ”ƒโƒโ”‚ *Mode:* ${mode}\n`;
menuText += `โ”ƒโƒโ”‚ *Timezone:* ${tz}\n`;
menuText += `โ”ƒโƒโ”‚ *Total Users:* ${usersFormatted}\n`;
menuText += `โ”ƒโƒโ”‚ *RAM:* ${usedMem}/${totalMem} GB\n`;
menuText += `โ”ƒโƒโ”‚ *Uptime:* ${uptime}\n`;
menuText += `โ”ƒโƒโ”‚ *Platform:* ${platform}\n`;
menuText += `โ”ƒโƒโ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n`;
menuText += `โ•ฐโ”โ”โ”โ”โ”โ’ ${applyStyle(`VERSION ${botVersion}`, 10)} โ’โ”โ”โ”โ”โ•ฏ\n\n`;
menuText += `*โ—‡ ${botName} COMMANDS โ—‡*\n\n`;
let counter = 1;
const sortedCategories = Object.keys(grouped).sort();
for (const category of sortedCategories) {
const commandsInCategory = grouped[category]
.filter(c => c.name)
.sort((a, b) => a.name.localeCompare(b.name));
if (commandsInCategory.length === 0) continue;
menuText += `*โ•ญโ”€โ”€โ’ ${applyStyle(category.toUpperCase(), 10)} โ’โ”€โ”€โ”€โŠท*\n`;
menuText += `โ”‚โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n`;
for (const cmd of commandsInCategory) {
menuText += `โ”‚โ”‚ ${counter++}. ${applyStyle(cmd.name, 10)}\n`;
}
menuText += `โ”‚โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n`;
menuText += `โ•ฐโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โŠท\n\n`;
}
menuText += `${readmore}\n`;
menuText += `โ—‡ *THE FLASH MULTI DEVICE* โ—‡\n\n`;
menuText += ` *Released: 22.2.2024*\n\n`;
menuText += ` _Thanks For choosing ${botName}_\n\n`;
menuText += ` Created by *${ownerName} ยฉ2024*\n\n`;
menuText += ` *KEEP USING ${botName}*\n`;
const defaultMedia = [
'https://picsum.photos/700/900',
'https://h.uguu.se/qhKuTfqE.mp4'
];
const allMedia = [...defaultMedia, ...menuImages];
const randomImage = allMedia[
Math.floor(Math.random() * allMedia.length)
];
const isVideo = randomImage.endsWith('.mp4');
try {
await sock.sendMessage(from, {
...(isVideo
? { video: { url: randomImage } }
: { image: { url: randomImage } }),
caption: menuText,
contextInfo: {
mentionedJid: [userName],
forwardingScore: 1,
isForwarded: true,
forwardedNewsletterMessageInfo: {
newsletterJid: '120363238139244263@newsletter',
newsletterName: botName,
serverMessageId: -1
}
}
}, { quoted: msg });
} catch {
await sock.sendMessage(from, {
text: menuText,
contextInfo: {
mentionedJid: [userName],
forwardingScore: 1,
isForwarded: true,
forwardedNewsletterMessageInfo: {
newsletterJid: '120363238139244263@newsletter',
newsletterName: botName,
serverMessageId: -1
}
}
}, { quoted: msg });
}
} catch (error) {
console.error('Menu error:', error);
await sock.sendMessage(from, {
text: 'โŒ Error loading menu.'
}, { quoted: msg });
}
}
},
{
name: 'help',
aliases: ['guide'],
description: 'Show command details with descriptions and aliases.',
category: 'General',
execute: async ({ sock, from, text, msg, commands, auteurMessage, nomAuteurMessage }) => {
try {
const botName = 'FLASH-MD-V3';
const botVersion = CONFIG.BOT_VERSION || '3.0.0';
const ownerName = CONFIG.OWNER_NAME || 'FRANCE KING';
const tz = CONFIG.TZ || 'Africa/Nairobi';
const prefix = CONFIG.PREFIXES?.[0] || ' ';
const list = Array.from(commands.values());
if (!list.length) {
const noCommandsMsg = await t(from, 'help', 'noCommands');
return sock.sendMessage(from, {
text: noCommandsMsg
}, { quoted: msg });
}
const time = moment().tz(tz);
const hour = time.hour();
let greeting = "Good Night";
if (hour >= 0 && hour <= 11) {
greeting = "Good Morning";
} else if (hour >= 12 && hour <= 16) {
greeting = "Good Afternoon";
} else if (hour >= 16 && hour <= 21) {
greeting = "Good Evening";
}
const userName = nomAuteurMessage || auteurMessage || ownerName;
const greetingMsg = await t(from, 'help', 'greeting');
const ownerLabel = await t(from, 'help', 'owner');
const prefixLabel = await t(from, 'help', 'prefix');
const timeLabel = await t(from, 'help', 'time');
const dateLabel = await t(from, 'help', 'date');
const tzLabel = await t(from, 'help', 'timezone');
const noDescMsg = await t(from, 'help', 'noDescription');
const aliasesLabel = await t(from, 'help', 'aliases');
const usageMsg = await t(from, 'help', 'usage');
const poweredMsg = await t(from, 'help', 'powered');
let helpText = `${greetingMsg} ${userName}\n\n`;
helpText += `โ•ญโ”โ”โ”โ’ ${applyStyle(`${botName}`, 10)} โ’โ”โ”โ”โ•ฎ\n`;
helpText += `โ”ƒโƒโ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n`;
helpText += `โ”ƒโƒโ”‚ *${ownerLabel}:* ${ownerName}\n`;
helpText += `โ”ƒโƒโ”‚ *${prefixLabel}:* ${prefix}\n`;
helpText += `โ”ƒโƒโ”‚ *${timeLabel}:* ${time.format('HH:mm:ss')}\n`;
helpText += `โ”ƒโƒโ”‚ *${dateLabel}:* ${time.format('DD/MM/YYYY')}\n`;
helpText += `โ”ƒโƒโ”‚ *${tzLabel}:* ${tz}\n`;
helpText += `โ”ƒโƒโ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\n`;
helpText += `โ•ฐโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•ฏ\n\n`;
helpText += `*FLASH-MD V3 COMMANDS*\n\n`;
const grouped = {};
for (const cmd of list) {
const category = cmd.category || 'General';
if (!grouped[category]) {
grouped[category] = [];
}
grouped[category].push(cmd);
}
const sortedCategories = Object.keys(grouped).sort();
for (const category of sortedCategories) {
const commandsInCategory = grouped[category]
.filter(c => c.name)
.sort((a, b) => a.name.localeCompare(b.name));
if (commandsInCategory.length === 0) continue;
helpText += `โ•ญโ”€โ”€โ’ ${applyStyle(category.toUpperCase(), 10)} โ’โ”€โ”€โ”€โŠท\n`;
helpText += `โ”‚\n`;
for (const cmd of commandsInCategory) {
helpText += `โ”‚ โ€ข *${applyStyle(cmd.name, 10)}*\n`;
helpText += `โ”‚ โ†ณ ${cmd.description || noDescMsg}\n`;
if (cmd.aliases && cmd.aliases.length > 0) {
helpText += `โ”‚ โ†ณ ${aliasesLabel}: ${cmd.aliases.map(a => applyStyle(a, 10)).join(', ')}\n`;
}
helpText += `โ”‚\n`;
}
helpText += `โ•ฐโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โŠท\n\n`;
}
helpText += `${usageMsg} ${prefix}<command>\n`;
helpText += `${poweredMsg} ${botName} ${botVersion}`;
await sock.sendMessage(from, {
text: helpText,
contextInfo: {
mentionedJid: [userName],
forwardingScore: 1,
isForwarded: true,
forwardedNewsletterMessageInfo: {
newsletterJid: '120363238139244263@newsletter',
newsletterName: botName,
serverMessageId: -1
}
}
}, { quoted: msg });
} catch (error) {
console.error('Help error:', error);
const errorMsg = await t(from, 'help', 'error');
await sock.sendMessage(from, {
text: errorMsg
}, { quoted: msg });
}
}
}
];