Handle API errors more gracefully, fixed sharpen, restrict screenshot to the bot owner
This commit is contained in:
		
							parent
							
								
									9c496a4984
								
							
						
					
					
						commit
						78ae47dbbb
					
				
					 4 changed files with 20 additions and 6 deletions
				
			
		
							
								
								
									
										20
									
								
								api/index.js
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								api/index.js
									
										
									
									
									
								
							| 
						 | 
					@ -37,10 +37,24 @@ if (isMainThread) {
 | 
				
			||||||
        delete jobs[uuid];
 | 
					        delete jobs[uuid];
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    worker.on("error", err => console.error("worker error:", err));
 | 
					    worker.on("error", err => {
 | 
				
			||||||
 | 
					      console.error("worker error:", err);
 | 
				
			||||||
 | 
					      socket.send(Buffer.concat([Buffer.from([0x2]), Buffer.from(err.toString())]), jobs[uuid].port, jobs[uuid].addr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      workingWorkers--;
 | 
				
			||||||
 | 
					      if (queue.length > 0) {
 | 
				
			||||||
 | 
					        acceptJob(queue[0]);
 | 
				
			||||||
 | 
					        delete jobs[uuid];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
    worker.on("exit", (code) => {
 | 
					    worker.on("exit", (code) => {
 | 
				
			||||||
      if (code !== 0)
 | 
					      workingWorkers--;
 | 
				
			||||||
        console.error(`Worker stopped with exit code ${code}`);
 | 
					      if (queue.length > 0) {
 | 
				
			||||||
 | 
					        acceptJob(queue[0]);
 | 
				
			||||||
 | 
					        delete jobs[uuid];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (code !== 0) console.error(`Worker stopped with exit code ${code}`);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,7 @@
 | 
				
			||||||
      "libraries": [
 | 
					      "libraries": [
 | 
				
			||||||
        "<!(pkg-config --libs Magick++)",
 | 
					        "<!(pkg-config --libs Magick++)",
 | 
				
			||||||
      ],
 | 
					      ],
 | 
				
			||||||
      "defines": ["NAPI_DISABLE_CPP_EXCEPTIONS", "MAGICKCORE_HDRI_ENABLE=false", "MAGICKCORE_QUANTUM_DEPTH=16"]
 | 
					      "defines": ["NAPI_CPP_EXCEPTIONS", "MAGICKCORE_HDRI_ENABLE=false", "MAGICKCORE_QUANTUM_DEPTH=16"]
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  ]
 | 
					  ]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ exports.run = async (message) => {
 | 
				
			||||||
  const image = await require("../utils/imagedetect.js")(message);
 | 
					  const image = await require("../utils/imagedetect.js")(message);
 | 
				
			||||||
  if (image === undefined) return `${message.author.mention}, you need to provide an image to sharpen!`;
 | 
					  if (image === undefined) return `${message.author.mention}, you need to provide an image to sharpen!`;
 | 
				
			||||||
  const { buffer, type } = await magick.run({
 | 
					  const { buffer, type } = await magick.run({
 | 
				
			||||||
    cmd: "sharpen",
 | 
					    cmd: "blur",
 | 
				
			||||||
    path: image.path,
 | 
					    path: image.path,
 | 
				
			||||||
    sharp: true
 | 
					    sharp: true
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue