Accept feedback and forward to Discord

This commit is contained in:
Jordan Eldredge 2021-10-13 21:59:04 -07:00
parent 26bfe37bf6
commit cd2bd05aa7
4 changed files with 41 additions and 2 deletions

View file

@ -82,6 +82,25 @@ export default class DiscordEventHandler {
);
break;
}
case "GOT_FEEDBACK": {
const dest = await this.getChannel(Config.FEEDBACK_SKIN_CHANNEL_ID);
const userMessage = action.message
.split("\n")
.map((line) => {
return `> ${line}`;
})
.join("\n");
let message = `Feedback:\n\n ${userMessage}`;
if (action.email != null) {
message += `\n\n--${action.email}`;
}
if (action.url != null) {
message += `\n(${action.url})`;
}
await dest.send(message);
break;
}
}
}

View file

@ -19,7 +19,8 @@ export type ApiAction =
| { type: "ERROR_PROCESSING_UPLOAD"; id: string; message: string }
| { type: "CLASSIC_SKIN_UPLOADED"; md5: string }
| { type: "MODERN_SKIN_UPLOADED"; md5: string }
| { type: "SKIN_UPLOAD_ERROR"; uploadId: string; message: string };
| { type: "SKIN_UPLOAD_ERROR"; uploadId: string; message: string }
| { type: "GOT_FEEDBACK"; message: string; email?: string, url?: string };
export type EventHandler = (event: ApiAction) => void;
export type Logger = {

View file

@ -113,6 +113,24 @@ router.post(
})
);
router.post(
"/feedback",
asyncHandler(async (req, res) => {
const payload = req.body as {
email?: string;
message: string;
url?: string;
};
req.notify({
type: "GOT_FEEDBACK",
url: payload.url,
message: payload.message,
email: payload.email,
});
res.json({ message: "sent" });
})
);
router.post(
"/skins/status",
asyncHandler(async (req, res) => {

View file

@ -48,7 +48,8 @@
"fetch-metadata": "ts-node --transpile-only ./cli.ts fetch-metadata",
"bot": "ts-node --transpile-only ./discord-bot/index.js",
"cli": "ts-node --transpile-only ./cli.ts",
"sync": "ts-node --transpile-only ./tasks/syncWithArchive.ts"
"sync": "ts-node --transpile-only ./tasks/syncWithArchive.ts",
"migrate": "knex migrate:latest"
},
"prettier": {},
"devDependencies": {