|
@@ -8,8 +8,8 @@ import { FaceCaptionMessage, FaceCaptionType } from "@shared/db/entity/FaceCapti
|
|
import { KnownChannel } from "@shared/db/entity/KnownChannel";
|
|
import { KnownChannel } from "@shared/db/entity/KnownChannel";
|
|
import { CommandSet, Action, ActionType, Command } from "src/model/command";
|
|
import { CommandSet, Action, ActionType, Command } from "src/model/command";
|
|
import { logger } from "src/logging";
|
|
import { logger } from "src/logging";
|
|
-import { Response } from "request";
|
|
|
|
-import needle from "needle";
|
|
|
|
|
|
+import got from "got";
|
|
|
|
+import FormData from "form-data";
|
|
|
|
|
|
const EMOTE_GUILD = "505333548694241281";
|
|
const EMOTE_GUILD = "505333548694241281";
|
|
|
|
|
|
@@ -144,7 +144,7 @@ export class Facemorph {
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
const prefixMessage = (await this.getRandomCaption(FaceCaptionType.PREFIX))?.message ?? "Feed them";
|
|
const prefixMessage = (await this.getRandomCaption(FaceCaptionType.PREFIX))?.message ?? "Feed them";
|
|
- const postfixMessage = (await this.getRandomCaption(FaceCaptionType.POSTFIX)) ?? "carrots";
|
|
|
|
|
|
+ const postfixMessage = (await this.getRandomCaption(FaceCaptionType.POSTFIX))?.message ?? "carrots";
|
|
text = `${prefixMessage} ${postfixMessage}`;
|
|
text = `${prefixMessage} ${postfixMessage}`;
|
|
}
|
|
}
|
|
const h = Jimp.measureTextHeight(font, text, targetSize - CAPTION_OFFSET * 2);
|
|
const h = Jimp.measureTextHeight(font, text, targetSize - CAPTION_OFFSET * 2);
|
|
@@ -172,20 +172,21 @@ export class Facemorph {
|
|
async processFaceSwap(message: Message, attachmentUrl: string, processor?: ImageProcessor, failMessage?: string, successMessage?: string): Promise<void> {
|
|
async processFaceSwap(message: Message, attachmentUrl: string, processor?: ImageProcessor, failMessage?: string, successMessage?: string): Promise<void> {
|
|
const data = await request(attachmentUrl, { encoding: null }) as Buffer;
|
|
const data = await request(attachmentUrl, { encoding: null }) as Buffer;
|
|
|
|
|
|
- const result = await needle("post", `http://${process.env.FACEDETECT_URL}/process`, {
|
|
|
|
- img_data: {
|
|
|
|
- buffer: data,
|
|
|
|
- filename: "image.png",
|
|
|
|
- content_type: "application/octet-stream"
|
|
|
|
- }
|
|
|
|
- }, { multipart: true });
|
|
|
|
-
|
|
|
|
|
|
+ const form = new FormData();
|
|
|
|
+ form.append("img_data", data, {
|
|
|
|
+ filename: "image.png",
|
|
|
|
+ contentType: "application/octet-stream"
|
|
|
|
+ });
|
|
|
|
+ const result = await got.post<FaceDetectionResponse>(`http://${process.env.FACEDETECT_URL}/process`, {
|
|
|
|
+ responseType: "json",
|
|
|
|
+ body: form
|
|
|
|
+ });
|
|
|
|
+
|
|
if(result.statusCode != 200) {
|
|
if(result.statusCode != 200) {
|
|
logger.error("Face detection failed! Got response %s", result.statusCode);
|
|
logger.error("Face detection failed! Got response %s", result.statusCode);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- const faceRects = result.body as FaceDetectionResponse;
|
|
|
|
|
|
+ const faceRects = result.body;
|
|
|
|
|
|
if (isError(faceRects)) {
|
|
if (isError(faceRects)) {
|
|
logger.error("Face detection failed! Got response %s", result.statusCode);
|
|
logger.error("Face detection failed! Got response %s", result.statusCode);
|
|
@@ -252,7 +253,7 @@ export class Facemorph {
|
|
processLastImage(msg: Message, processor: ImageProcessor): void {
|
|
processLastImage(msg: Message, processor: ImageProcessor): void {
|
|
type AttachedMessage = {msg: Message, att: MessageAttachment};
|
|
type AttachedMessage = {msg: Message, att: MessageAttachment};
|
|
const lastImagedMessage = msg.channel.messages.cache.mapValues(m => ({msg: m, att: m.attachments.find(v => isValidImage(v.name))}))
|
|
const lastImagedMessage = msg.channel.messages.cache.mapValues(m => ({msg: m, att: m.attachments.find(v => isValidImage(v.name))}))
|
|
- .filter(v => v.att != undefined).last() as AttachedMessage;
|
|
|
|
|
|
+ .filter(v => !v.msg.author.bot && v.att != undefined).last() as AttachedMessage;
|
|
|
|
|
|
if (!lastImagedMessage) {
|
|
if (!lastImagedMessage) {
|
|
msg.channel.send(`${msg.author.toString()} Sorry, I couldn't find any recent messages with images.`);
|
|
msg.channel.send(`${msg.author.toString()} Sorry, I couldn't find any recent messages with images.`);
|