2020-02-17 22:21:24 +00:00
|
|
|
const urlRegex = /(?:\w+:)?\/\/(\S+)/;
|
2020-11-26 15:31:24 +00:00
|
|
|
const puppeteer = require("puppeteer-extra");
|
|
|
|
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
|
|
|
|
puppeteer.use(StealthPlugin());
|
2020-02-17 22:21:24 +00:00
|
|
|
const fetch = require("node-fetch");
|
|
|
|
|
|
|
|
exports.run = async (message, args) => {
|
2020-12-14 18:39:18 +00:00
|
|
|
if (message.author.id !== process.env.OWNER) return `${message.author.mention}, only the bot owner can run this command!`;
|
2020-02-17 22:21:24 +00:00
|
|
|
message.channel.sendTyping();
|
|
|
|
if (args.length === 0) return `${message.author.mention}, you need to provide a URL to screenshot!`;
|
2020-09-19 00:54:52 +00:00
|
|
|
const getEndpoint = await fetch(`http://${process.env.CHROME}/json/version`);
|
2020-02-17 22:21:24 +00:00
|
|
|
const endpoint = await getEndpoint.json();
|
|
|
|
const url = urlRegex.test(args[0]) ? args[0] : `http://${args[0]}`;
|
|
|
|
const browser = await puppeteer.connect({
|
|
|
|
browserWSEndpoint: endpoint.webSocketDebuggerUrl,
|
|
|
|
defaultViewport: {
|
|
|
|
width: 1280,
|
|
|
|
height: 720
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.goto(url);
|
|
|
|
const screenshot = await page.screenshot();
|
|
|
|
await page.close();
|
2020-04-12 19:51:48 +00:00
|
|
|
return {
|
2020-02-17 22:21:24 +00:00
|
|
|
file: screenshot,
|
|
|
|
name: "screenshot.png"
|
2020-04-12 19:51:48 +00:00
|
|
|
};
|
2020-02-17 22:21:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.aliases = ["webshot", "ss", "shot", "page"];
|
2020-12-14 18:39:18 +00:00
|
|
|
exports.category = 8;
|
2020-02-17 22:21:24 +00:00
|
|
|
exports.help = "Screenshots a webpage";
|