Skip to content

Commit

Permalink
clean up sending code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Oct 23, 2023
1 parent 322c153 commit e2a9646
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions src/v2/service/addon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,36 +586,40 @@ export default class AddonService {
});
}

private async notifyAddonChange(a: Addon, before: AddonStatus): Promise<void> {
// webhook not set up
if (!process.env.WEBHOOK_URL) return;
const now = a.approval.status;
const statusSame = before === now; // "ignore pending to pending"

if (statusSame) return;

let title = a.name;
let name = "Add-on ";
let reason: APIEmbedField[] = [{
name: "Reason",
value: a.approval.reason ?? "*No reason provided*",
}];
if (now === "approved") reason = undefined;
if (now === "pending") {
title = `Add-on '${a.name}' pending approval`;
name += "Update";
private async notifyAddonChange(addon: Addon, before: AddonStatus): Promise<void> {
const status = addon.approval.status;
// webhook not set up or status hasn't changed
if (!process.env.WEBHOOK_URL || before === status) return;

let title: string;
let name: string;
if (status === "pending") {
title = `${addon.name} is pending approval!`;
name = "Add-on Update";
} else {
const usernameApproval = (a.approval.author
? await this.userService.getUserById(a.approval.author).catch(() => undefined)
const usernameApproval = (addon.approval.author
? await this.userService.getUserById(addon.approval.author).catch(() => undefined)
: undefined) || { username: "an unknown user" };
title = `Add-on '${a.name}' ${now} by ${usernameApproval.username}!`;
name += "Review";
title = `${addon.name} was ${status} by ${usernameApproval.username}!`;
name = "Add-on Review";
}

let reason: APIEmbedField[];
if (status !== "approved")
reason = [
{
name: "Reason",
value: addon.approval.reason ?? "*No reason provided*",
},
];

const payload: RESTPostAPIChannelMessageJSONBody = {
embeds: [
{
title,
url: `https://webapp.faithfulpack.net/#/review/addons?status=${now}&id=${String(a.id)}`,
url: `https://webapp.faithfulpack.net/#/review/addons?status=${status}&id=${String(
addon.id,
)}`,
author: {
name,
icon_url:
Expand Down

0 comments on commit e2a9646

Please sign in to comment.