diff --git a/.env.example b/.env.example index 9ca504d..51aa06d 100644 --- a/.env.example +++ b/.env.example @@ -28,6 +28,9 @@ GOOGLE= # Put DBL/top.gg token here DBL= +# Put headless Chrome IP here +CHROME=172.17.0.1:9222 + # Put HTML help page output location here, leave blank to disable OUTPUT= # Put temporary image dir here (make sure it's accessible via a web server), leave blank to disable diff --git a/api/index.js b/api/index.js index e27153a..d92f0ac 100644 --- a/api/index.js +++ b/api/index.js @@ -23,19 +23,41 @@ app.get("/", (req, res) => { }); app.post("/:method", upload.single("image"), async (req, res, next) => { - const type = req.file.mimetype === "video/mp4" ? "image/gif" : req.file.mimetype; + const type = req.file ? (req.file.mimetype === "video/mp4" ? "image/gif" : req.file.mimetype) : "image/png"; if (!formats.includes(type)) { return res.sendStatus(400); } const object = { cmd: req.params.method, - path: req.file.path, + path: req.file ? req.file.path : null, type: type.split("/")[1], - delay: parseInt(req.params.delay) + delay: req.query.delay ? parseInt(req.query.delay) : 0 }; for (const param of Object.keys(req.query)) { if (param === "delay") continue; - object[param] = req.query[param]; + switch (param) { + case "sharp": + case "flop": + case "loop": + case "vertical": + case "first": + case "stretch": + case "wide": + case "soos": + case "slow": + case "resize": + case "append": + case "mc": + if (req.query[param] === "true") { + object[param] = true; + } else { + object[param] = false; + } + break; + default: + object[param] = req.query[param]; + break; + } } try { diff --git a/commands/help.js b/commands/help.js index 35c594f..fca190d 100644 --- a/commands/help.js +++ b/commands/help.js @@ -21,7 +21,7 @@ exports.run = async (message, args) => { }, "title": `${prefix}${command}`, "url": "https://projectlounge.pw/esmBot/help.html", - "description": info.description, + "description": command === "tags" ? "The main tags command. Check the help page for more info: https://projectlounge.pw/esmBot/help.html" : info.description, "color": 16711680, "fields": [{ "name": "Aliases", @@ -32,7 +32,7 @@ exports.run = async (message, args) => { "inline": true }, { "name": "Parameters", - "value": info.params ? info.params : "None", + "value": command === "tags" ? "[name]" : info.params ? info.params : "None", "inline": true }] } diff --git a/commands/screenshot.js b/commands/screenshot.js index a33a0b3..f7259db 100644 --- a/commands/screenshot.js +++ b/commands/screenshot.js @@ -5,7 +5,7 @@ const fetch = require("node-fetch"); exports.run = async (message, args) => { message.channel.sendTyping(); if (args.length === 0) return `${message.author.mention}, you need to provide a URL to screenshot!`; - const getEndpoint = await fetch("http://172.17.0.1:9222/json/version"); + const getEndpoint = await fetch(`http://${process.env.CHROME}/json/version`); const endpoint = await getEndpoint.json(); const url = urlRegex.test(args[0]) ? args[0] : `http://${args[0]}`; const browser = await puppeteer.connect({ diff --git a/natives/sonic.cc b/natives/sonic.cc index 0965c11..85787ba 100644 --- a/natives/sonic.cc +++ b/natives/sonic.cc @@ -43,7 +43,7 @@ Napi::Value Sonic(const Napi::CallbackInfo &info) Napi::Object obj = info[0].As(); Napi::Function cb = info[1].As(); - string text = obj.Get("path").As().Utf8Value(); + string text = obj.Get("text").As().Utf8Value(); SonicWorker* explodeWorker = new SonicWorker(cb, text); explodeWorker->Queue(); diff --git a/utils/image.js b/utils/image.js index fa9d551..ef9726f 100644 --- a/utils/image.js +++ b/utils/image.js @@ -11,7 +11,7 @@ module.exports = async (object, fromAPI = false) => { params.push(`${element}=${encodeURIComponent(object[element])}`); } const form = new FormData(); - form.append("image", fs.createReadStream(object.path)); + if (object.path) form.append("image", fs.createReadStream(object.path)); const req = await fetch(`${process.env.API_URL}/${object.cmd}?${params.join("&")}`, { method: "POST", body: form, diff --git a/utils/soundplayer.js b/utils/soundplayer.js index 3c700be..caa1489 100644 --- a/utils/soundplayer.js +++ b/utils/soundplayer.js @@ -145,13 +145,18 @@ exports.skip = async (message) => { if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return client.createMessage(message.channel.id, `${message.author.mention}, I'm not in a voice channel!`); const player = this.players.get(message.channel.guild.id); if (player.host !== message.author.id) { - const voteCount = skipVotes.has(message.channel.guild.id) ? skipVotes.get(message.channel.guild.id) : 0; - if (voteCount + 1 === 3) { + const votes = skipVotes.has(message.channel.guild.id) ? skipVotes.get(message.channel.guild.id) : { count: 0, ids: [] }; + if (votes.ids.includes(message.author.id)) return client.createMessage(message.channel.id, `${message.author.mention}, you've already voted to skip!`); + const newObject = { + count: votes.count + 1, + ids: [...votes.ids, message.author.id].filter(item => !!item) + }; + if (votes.count + 1 === 3) { player.player.stop(message.channel.guild.id); - skipVotes.set(message.channel.guild.id, 0); + skipVotes.set(message.channel.guild.id, { count: 0, ids: [] }); } else { - await client.createMessage(message.channel.id, `🔊 Voted to skip song (${voteCount + 1}/3 people have voted).`); - skipVotes.set(message.channel.guild.id, voteCount + 1); + await client.createMessage(message.channel.id, `🔊 Voted to skip song (${votes.count + 1}/3 people have voted).`); + skipVotes.set(message.channel.guild.id, newObject); } } else { player.player.stop(message.channel.guild.id);