Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
hacxk authored May 26, 2024
1 parent 5eb96ae commit 3723632
Show file tree
Hide file tree
Showing 12 changed files with 3,760 additions and 0 deletions.
Binary file added Assets/_MenuAssets/menuImage1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Config.js

// Define bot settings object
global.botSettings = {};

// Add owner settings
global.botSettings.ownerNumbers = ['94771014973', '94754802771', '94773255188']; // Example: ['1234567', '453657767'] **PUT YOUR NAMER FIRST**
global.botSettings.botNumber = [''] // Don't Need to input bot will update automatically
global.botSettings.ownerName = ['Mr - Zaid']
global.botSettings.botName = ['Hacxk - MD']
global.botSettings.botPrefix = ['.'] // You can use prefix as /, ., # don't use [!] this
global.botSettings.botWorkMode = ['Private'] // If Private don't Work bot command in group if you want to work use Public
global.botSettings.greetings = true // This mean if a contact join or leave a group sending welcome and goodbye message if 'true' it works if 'false' not work

// ------------------------------------------------------------------------------------------------------------------------------------------\\


// Define api object
global.api = {};

global.api.openAI = ['']
global.api.gemini = ['']
7 changes: 7 additions & 0 deletions DOCKERFILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:18.16.0-bullseye-slim

WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]
65 changes: 65 additions & 0 deletions Lib/CommandHandle/CommandHandle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const fs = require('fs');
const path = require('path');
require('esm')(module);
require('../../Config');

const commands = [];
let commandPrefix = global.botSettings.botPrefix[0]; // Set your desired command prefix here

function Command({ cmd, desc, react, type, handler }) {
commands.push({ cmd, desc, react, type, handler });
}

async function handleCommand(m, sock, delay) {
try {
const textMessage = m.message?.conversation.toLowerCase() || m.message?.extendedTextMessage?.text.toLowerCase() || "";
const OriginalText = m.message?.conversation || m.message?.extendedTextMessage?.text || "";
const matchedCommand = commands.find(command => {
if (Array.isArray(command.cmd)) {
return command.cmd.some(cmd => textMessage.startsWith(commandPrefix + cmd));
} else {
return textMessage.startsWith(commandPrefix + command.cmd);
}
});
if (matchedCommand) {
await sock.presenceSubscribe(m.key.remoteJid);
await delay(250);
await sock.readMessages([m.key]);
if (matchedCommand.react) {
await sock.sendMessage(m.key.remoteJid, { react: { text: matchedCommand.react, key: m.key } });
}
await sock.sendPresenceUpdate('composing', m.key.remoteJid);
await delay(750);
await sock.sendPresenceUpdate('paused', m.key.remoteJid);
await matchedCommand.handler(m, sock, commands);
}
} catch (error) {
console.error("An error occurred:", error);
}
}

// Function to load all commands from the Plugin folder
async function loadCommandsFromFolder(folderPath) {
const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'));
let loadedCount = 0;
const totalFiles = commandFiles.length;
for (const file of commandFiles) {
const filePath = path.join(folderPath, file);
const commandModule = require(filePath); // Use require synchronously
if (typeof commandModule === 'function') {
commandModule(Command);
loadedCount++;
const percentage = ((loadedCount / totalFiles) * 100).toFixed(0);
// ANSI escape codes for green color and bold style
const greenBold = '\x1b[32;1m';
// Reset ANSI escape code
const reset = '\x1b[0m';
// Emoji
const emoji = '📂'; // You can choose any emoji you like
console.log(`${greenBold}${emoji} Loaded percentage: ${percentage}% (${loadedCount}/${totalFiles}) ${reset}`);
}
}
}


module.exports = { Command, handleCommand, loadCommandsFromFolder, commands };
24 changes: 24 additions & 0 deletions Plugin/Ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { performance } = require('perf_hooks');

module.exports = (Command) => {
Command({
cmd: ['ping', 'test'], // Define multiple commands as an array
desc: 'Check ping in ms',
react: "💨", // Reaction emoji
type: 'BOT COMMANDS',
handler: async (m, sock) => {
const startTime = performance.now();

// Perform some math calculation (for demonstration purposes)
const result = 2 + 2; // You can replace this with any calculation

const endTime = performance.now();
const pingTime = endTime - startTime; // Calculate ping time in milliseconds

// Send the result along with ping time
await sock.sendMessage(m.key.remoteJid, {
text: `Ping: ${pingTime.toFixed(2)} ms`
}, { quoted: m });
}
});
};
160 changes: 160 additions & 0 deletions Plugin/Tiktok_dl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
const tik = require('rahad-media-downloader');
const axios = require('axios');
const fs = require('fs');
const path = require('path');

module.exports = (Command) => {
Command({
cmd: ['tt', 'tiktok', 'tik'],
desc: 'Download TikTok video/audio',
react: "🎶",
type: 'TIKTOK DOWNLOADER COMMANDS',
handler: async (m, sock) => {
const OriginalText = m.message?.conversation || m.message?.extendedTextMessage?.text || "";
const [command, ...args] = OriginalText.split(' ');

if (args.length < 1) {
await sock.sendMessage(m.key.remoteJid, { text: 'Hey there! To download a video, send ".tt [TikTok link or keyword]" ' }, { quoted: m });
await sock.sendMessage(m.key.remoteJid, { react: { text: "❓", key: m.key } });
return;
}

await sock.sendMessage(m.key.remoteJid, { react: { text: "🔍", key: m.key } });

const input = args.join(' ');

try {
if (input.match(/(https:\/\/www\.tiktok\.com\/|https:\/\/vm\.tiktok\.com\/)/)) {
const result = await tik.rahadtikdl(input);

const { metadata, videoDetails } = result;

console.log(videoDetails)

const {
title,
react_count,
comment_count,
share_count,
musicInfo,
noWatermarkMp4,
watermarkMp4,
download_count,
create_time,
avatar,
} = videoDetails;

const { Author, Facebook } = metadata;

const message = `🎶 *TikTok Search Results* 📹\n\n` +
`*To Download:*\n` +
`> ▶️ To Download Video as HD: Reply with 1\n` +
`> ▶️ To Download Video as SD: Reply with 2\n` +
`> ▶️ To Download Video as MP3: Reply with 3\n\n` +
`🎬 *Title*: ${title}\n` +
`❤️ *Likes*: ${react_count}\n` +
`💬 *Comments*: ${comment_count}\n` +
`🔄 *Shares*: ${share_count}\n` +
`🔽 *Downloads*: ${download_count}\n` +
`⏰ *Created*: ${new Date(create_time * 1000).toLocaleString()}\n\n` +
`🎵 *Music Info* 🎵\n` +
`🎶 *Title*: ${musicInfo.title}\n` +
`👤 *Author*: ${musicInfo.author}\n` +
`⏱️ *Duration*: ${musicInfo.duration}s\n\n` +
`🔗 *Video URL*: ${noWatermarkMp4}\n\n` +
`👤 *Author Metadata* 👤\n` +
`👤 *Name*: ${Author}\n` +
`🌐 *Facebook*: ${Facebook}\n` +
`🖼️ *Avatar*: ${avatar}`;

const sentMessage = await sock.sendMessage(m.key.remoteJid, { text: message, matchedText: input, canonicalUrl: input, previewType: true, thumbnailWidth: 630 }, { quoted: m });

const replyHandler = async (msg) => {
if (msg.message?.extendedTextMessage?.contextInfo?.stanzaId === sentMessage.key.id) {
const replyText = msg.message?.conversation || msg.message?.extendedTextMessage?.text;
if (replyText === '1') {
await sock.sendMessage(m.key.remoteJid, { text: 'Downloading video as HD...' }, { quoted: msg });
const url = noWatermarkMp4;
await downloadTiktok(sock, m, 'HD', url, title);
} else if (replyText === '2') {
await sock.sendMessage(m.key.remoteJid, { text: 'Downloading Video as SD...' }, { quoted: msg });
const url = watermarkMp4;
await downloadTiktok(sock, m, 'SD', url, title);
} else if (replyText === '3') {
await sock.sendMessage(m.key.remoteJid, { text: 'Downloading audio...' }, { quoted: msg });
const url = musicInfo.music;
await downloadTiktok(sock, m, 'MP3', url, title);
} else {
await sock.sendMessage(m.key.remoteJid, { text: 'Invalid option. Send "1" for video or "3" for audio.' }, { quoted: msg });
}
}
};


sock.ev.on('messages.upsert', async ({ messages }) => {
for (let msg of messages) {
await replyHandler(msg);
}
});
} else {
await sock.sendMessage(m.key.remoteJid, { text: "Please send a valid TikTok link to download." }, { quoted: m });
}
} catch (error) {
console.error('Error occurred:', error);
await sock.sendMessage(m.key.remoteJid, { text: 'An error occurred while processing your request. Please try again later.' }, { quoted: m });
}
}
});
};

const sanitizeFilename = (filename) => {
return filename.replace(/[<>:"/\\|?*]+/g, '');
};

async function downloadTiktok(sock, m, option, url, stitle) {
try {
const response = await axios.get(url, { responseType: 'arraybuffer' });

// Generate filename based on video title
const title = sanitizeFilename(stitle.toLowerCase().replace(/ /g, '_'));
const extension = option === 'MP3' ? 'mp3' : 'mp4';
const filename = `${title}.${extension}`;

// Determine the directory to save the file
const saveDirectory = path.join(__dirname, 'downloads');

// Create the "downloads" folder if it doesn't exist
if (!fs.existsSync(saveDirectory)) {
fs.mkdirSync(saveDirectory);
}

const filePath = path.join(saveDirectory, filename);

fs.writeFileSync(filePath, response.data);

// Prepare media message details
const mediaMessage = {
[option === 'MP3' ? 'audio' : 'video']: fs.readFileSync(filePath),
mimetype: option === 'MP3' ? 'audio/mp3' : 'video/mp4',
width: 1920,
caption: `*Video Title*: ${stitle}\n*Size*: ${Math.round(response.data.length / (1024 * 1024))} MB\n\n𝘏𝘈𝘊𝘟𝘒 𝘔𝘋`
};

// Send the media message
await sock.sendMessage(m.key.remoteJid, mediaMessage, { quoted: m });

// Delete the downloaded video file
fs.unlink(filePath, (err) => {
if (err) {
console.error('Error deleting video:', err);
} else {
console.log('Video deleted successfully.');
}
});

// await sock.sendMessage(m.key.remoteJid, { text: `Downloaded ${option === 'MP3' ? 'audio' : 'video'} successfully.` }, { quoted: m });
} catch (error) {
console.error('Error occurred during download:', error);
await sock.sendMessage(m.key.remoteJid, { text: 'An error occurred during download. Please try again later.' }, { quoted: m });
}
}
Loading

0 comments on commit 3723632

Please sign in to comment.