goat
command
raw
View or delete command files, upload to Pastebin
0
views
0
likes
0
installs
raw source
module.exports.config = {
name: "raw",
version: "1.0.1",
role: 2,
author: "π©π
ππ·πΎππͺ πππΎ",
description: "View or delete command files, upload to Pastebin",
category: "admin",
usages: "Reply with: file_number + type (raw/del)",
countDown: 0,
};
module.exports.onStart = async function ({ event, api }) {
const fs = require("fs");
const path = require("path");
const folderPath = __dirname;
fs.readdir(folderPath, (err, files) => {
if (err) {
console.error("Error reading files:", err);
return;
}
const jsFiles = files.filter(
(file) => path.extname(file).toLowerCase() === ".js"
);
let message = "βββββββββββββββββββββββββ\n";
message += "β π πππππππ π
ππππ β\n";
message += "βββββββββββββββββββββββββ\n\n";
jsFiles.forEach((file, index) => {
message += `${index + 1}. ${file}\n`;
});
message += "\nββββββββββββββββββββ\n";
message += "π‘ Reply:\n";
message += "βΈ number + raw (upload)\n";
message += "βΈ number + del (delete)\n\n";
message += "Example: 1 raw\n\n";
message += "Β© Robin-Ali";
api.sendMessage(
message,
event.threadID,
(err, info) => {
if (err) return console.error(err);
if (global.GoatBot?.onReply) { global.GoatBot.onReply.set(info.messageID, {
name: module.exports.config.name,
messageID: info.messageID,
author: event.senderID,
files: jsFiles,
}); }
},
event.messageID
);
});
};
module.exports.onReply = async function ({ event, api, handleReply: _origReply }) {
const handleReply = Reply || _origReply || {};
const fs = require("fs");
const path = require("path");
const axios = require("axios");
const input = event.body.trim().split(" ");
const fileNumber = parseInt(input[0], 10);
const action = input[1]?.toLowerCase();
// Validate input
if (isNaN(fileNumber) || !action) {
return api.sendMessage(
"β Invalid format!\nUse: number + raw/del\nExample: 1 raw",
event.threadID,
event.messageID
);
}
// Check authorization
if (event.senderID !== handleReply.author) {
return api.sendMessage(
"β Only the command user can reply!",
event.threadID,
event.messageID
);
}
const jsFiles = handleReply.files;
// Validate file number
if (fileNumber < 1 || fileNumber > jsFiles.length) {
return api.sendMessage(
`β Invalid file number! (1-${jsFiles.length})`,
event.threadID,
event.messageID
);
}
const fileName = jsFiles[fileNumber - 1];
const filePath = path.join(__dirname, fileName);
try {
if (action === "del") {
// Delete file
fs.unlinkSync(filePath);
return api.sendMessage(
`β
Deleted: ${fileName}`,
event.threadID,
event.messageID
);
}
if (action === "raw") {
// Upload to Pastebin
const fileContent = fs.readFileSync(filePath, "utf8");
const apiKey = global.config.PASTEBIN_API_KEY;
if (!apiKey) {
return api.sendMessage(
'β API key missing!\n\nSetup:\n1. Get key: pastebin.com/doc_api\n2. Add to config.json:\n "PASTEBIN_API_KEY": "key"\n3. Restart bot',
event.threadID,
event.messageID
);
}
api.sendMessage(`β³ Uploading ${fileName}...`, event.threadID);
try {
const formData = `api_dev_key=${encodeURIComponent(
apiKey
)}&api_option=paste&api_paste_code=${encodeURIComponent(
fileContent
)}&api_paste_name=${encodeURIComponent(
fileName
)}&api_paste_format=javascript&api_paste_private=1&api_paste_expire_date=1M`;
const response = await axios.post(
"https://pastebin.com/api/api_post.php",
formData,
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
}
);
if (response.data && response.data.startsWith("http")) {
const pasteUrl = response.data.trim();
const rawUrl = pasteUrl.replace("pastebin.com/", "pastebin.com/raw/");
return api.sendMessage(
`β
Uploaded!\n\nπ ${fileName}\nπ ${fileContent.length} chars\n\nπ View: ${pasteUrl}\nπ Raw: ${rawUrl}\n\nβ° Expires: 1 month\n\nΒ© Robin-Bot`,
event.threadID,
event.messageID
);
} else {
throw new Error(response.data);
}
} catch (err) {
console.error("Pastebin error:", err.response?.data || err.message);
return api.sendMessage(
`β Upload failed!\n\nError: ${
err.response?.data || err.message
}\n\nCheck API key validity.`,
event.threadID,
event.messageID
);
}
}
return api.sendMessage(
"β Invalid action!\nUse: raw or del",
event.threadID,
event.messageID
);
} catch (error) {
console.error("Error:", error);
return api.sendMessage(
"β An error occurred!",
event.threadID,
event.messageID
);
}
};